forked from oamg/leapp-repository
-
Notifications
You must be signed in to change notification settings - Fork 1
163 lines (144 loc) · 6.25 KB
/
reuse-copr-build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
name: reuse-copr-build@TF
on:
workflow_call:
secrets:
FEDORA_COPR_LOGIN:
required: true
FEDORA_COPR_TOKEN:
required: true
outputs:
artifacts:
description: "A string with test artifacts to install in tft test env"
value: ${{ jobs.reusable_workflow_copr_build_job.outputs.artifacts }}
jobs:
reusable_workflow_copr_build_job:
# This job only runs for '/rerun' pull request comments by owner, member, or collaborator of the repo/organization.
name: Build copr builds for tft tests
runs-on: ubuntu-20.04
outputs:
artifacts: ${{ steps.gen_artifacts.outputs.artifacts }}
if: |
github.event.issue.pull_request
&& startsWith(github.event.comment.body, '/rerun')
&& contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association)
steps:
- name: Update repository
id: repo_update
run: sudo apt-get update
- name: Install necessary deps
id: deps_install
run: sudo apt-get install -y libkrb5-dev
- name: Get pull request number
id: pr_nr
run: |
PR_URL="${{ github.event.comment.issue_url }}"
echo "::set-output name=pr_nr::${PR_URL##*/}"
- name: Checkout
# TODO: The correct way to checkout would be to use similar approach as in get_commit_by_timestamp function of
# the github gluetool module (i.e. do not use HEAD but the last commit before comment).
id: checkout
uses: actions/checkout@v2
with:
ref: "refs/pull/${{ steps.pr_nr.outputs.pr_nr }}/head"
- name: Get ref and sha
id: ref_sha
run: |
echo "::set-output name=sha::$(git rev-parse --short HEAD)"
echo "::set-output name=ref::refs/pull/${{ steps.pr_nr.outputs.pr_nr }}/head"
- name: Trigger copr build
id: copr_build
env:
COPR_CONFIG: "copr_fedora.conf"
COPR_CHROOT: "epel-7-x86_64,epel-8-x86_64"
COPR_REPO: "@oamg/leapp"
run: |
cat << EOF > $COPR_CONFIG
[copr-cli]
login = ${{ secrets.FEDORA_COPR_LOGIN }}
username = oamgbot
token = ${{ secrets.FEDORA_COPR_TOKEN }}
copr_url = https://copr.fedorainfracloud.org
# expiration date: 2030-07-04
EOF
pip install copr-cli
PR=${{ steps.pr_nr.outputs.pr_nr }} COPR_CONFIG=$COPR_CONFIG COPR_REPO="$COPR_REPO" COPR_CHROOT=$COPR_CHROOT make copr_build | tee copr.log
COPR_URL=$(grep -Po 'https://copr.fedorainfracloud.org/coprs/build/\d+' copr.log)
echo "::set-output name=copr_url::${COPR_URL}"
echo "::set-output name=copr_id::${COPR_URL##*/}"
- name: Add comment with copr build url
# TODO: Create comment when copr build fails.
id: link_copr
uses: actions/github-script@v4
with:
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Copr build succeeded: ${{ steps.copr_build.outputs.copr_url }}'
})
- name: Get dependent leapp pr number from rerun comment
uses: actions-ecosystem/action-regex-match@v2
id: leapp_pr_regex_match
with:
text: ${{ github.event.comment.body }}
regex: '^/(rerun|rerun-sst)\s+([0-9]+)\s*$'
- name: If leapp_pr was specified in the comment - trigger copr build
# TODO: XXX FIXME This should schedule copr build for leapp but for now it will be just setting an env var
id: leapp_pr
if: ${{ steps.leapp_pr_regex_match.outputs.match != '' }}
run: |
echo "::set-output name=leapp_pr::${{ steps.leapp_pr_regex_match.outputs.group2 }}"
- name: Checkout leapp
id: checkout_leapp
if: ${{ steps.leapp_pr_regex_match.outputs.match != '' }}
uses: actions/checkout@v2
with:
repository: "oamg/leapp"
ref: "refs/pull/${{ steps.leapp_pr.outputs.leapp_pr }}/head"
- name: Get ref and sha for leapp
id: ref_sha_leapp
if: ${{ steps.leapp_pr_regex_match.outputs.match != '' }}
run: |
echo "::set-output name=sha::$(git rev-parse --short HEAD)"
echo "::set-output name=ref::refs/pull/${{ steps.leapp_pr.outputs.leapp_pr }}/head"
- name: Trigger copr build for leapp
id: copr_build_leapp
if: ${{ steps.leapp_pr_regex_match.outputs.match != '' }}
env:
COPR_CONFIG: "copr_fedora.conf"
COPR_CHROOT: "epel-7-x86_64,epel-8-x86_64"
COPR_REPO: "@oamg/leapp"
run: |
cat << EOF > $COPR_CONFIG
[copr-cli]
login = ${{ secrets.FEDORA_COPR_LOGIN }}
username = oamgbot
token = ${{ secrets.FEDORA_COPR_TOKEN }}
copr_url = https://copr.fedorainfracloud.org
# expiration date: 2030-07-04
EOF
pip install copr-cli
PR=${{ steps.leapp_pr.outputs.leapp_pr }} COPR_CONFIG=$COPR_CONFIG COPR_REPO="$COPR_REPO" COPR_CHROOT=$COPR_CHROOT make copr_build | tee copr.log
COPR_URL=$(grep -Po 'https://copr.fedorainfracloud.org/coprs/build/\d+' copr.log)
echo "::set-output name=copr_url::${COPR_URL}"
echo "::set-output name=copr_id::${COPR_URL##*/}"
- name: Add comment with copr build url for leapp
# TODO: Create comment when copr build fails.
id: link_copr_leapp
if: ${{ steps.leapp_pr_regex_match.outputs.match != '' }}
uses: actions/github-script@v4
with:
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Copr build succeeded: ${{ steps.copr_build_leapp.outputs.copr_url }}'
})
- name: Generate artifacts output
id: gen_artifacts
env:
ARTIFACTS: ${{ steps.leapp_pr_regex_match.outputs.match != '' && format('{0};{1}', steps.copr_build_leapp.outputs.copr_id, steps.copr_build.outputs.copr_id) || steps.copr_build.outputs.copr_id }}
run: |
echo "::set-output name=artifacts::${{ env.ARTIFACTS }}"