Skip to content

Commit d11d2a5

Browse files
refactor: copr-ci reusable workflow
1 parent 9864531 commit d11d2a5

1 file changed

Lines changed: 94 additions & 51 deletions

File tree

.github/workflows/copr-ci.yml

Lines changed: 94 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,17 @@ env:
4747
SECRETS_COPR_BETA_WEBHOOK_TOKEN: ${{ secrets.COPR_BETA_WEBHOOK_TOKEN }}
4848
SECRETS_COPR_STABLE_WEBHOOK_TOKEN: ${{ secrets.COPR_STABLE_WEBHOOK_TOKEN }}
4949
SECRETS_COPR_CLI_CONFIG: ${{ secrets.COPR_CLI_CONFIG }}
50+
PACKAGE_NAME: ${{ github.event.repository.name }}
51+
GH_EVENT_ACTION: ${{ github.event.action }}
52+
GH_EVENT_NAME: ${{ github.event_name }}
53+
GH_EVENT_NUMBER: ${{ github.event.number }}
5054

5155
jobs:
5256
package-init:
5357
name: Create/update copr package
5458
container: fedora:latest
5559
env:
5660
BASE_URL: https://copr.fedorainfracloud.org/api_3
57-
PACKAGE_NAME: ${{ github.event.repository.name }}
5861
SOURCE_TYPE_TEXT: "custom"
5962
permissions:
6063
contents: read
@@ -80,7 +83,7 @@ jobs:
8083
echo "Copr CLI configuration file is empty. Exiting..."
8184
8285
# if a pull request exit with 0
83-
if [[ "${{ github.event_name }}" = "pull_request" ]]; then
86+
if [[ "${GITHUB_EVENT_NAME}" = "pull_request" ]]; then
8487
echo "SKIP_REMAINING_JOBS=true" >> "${GITHUB_OUTPUT}"
8588
else
8689
exit 1
@@ -107,9 +110,9 @@ jobs:
107110
)
108111
109112
# download the latest copr-ci.sh script
110-
if [[ "${{ github.repository }}" = "LizardByte/copr-ci" ]]; then
113+
if [[ "${GITHUB_REPOSITORY}" = "LizardByte/copr-ci" ]]; then
111114
# use the version from the same ref
112-
ref="${{ github.ref }}"
115+
ref="${GITHUB_REF}"
113116
else
114117
ref="master" # default to master branch
115118
fi
@@ -159,10 +162,10 @@ jobs:
159162
needs: package-init
160163
outputs:
161164
BUILD_ID: ${{ steps.build.outputs.BUILD_ID }}
165+
BUILD_CHANNEL: ${{ steps.get-properties.outputs.BUILD_CHANNEL }}
162166
BUILD_CANCEL: ${{ steps.build.outcome == 'cancelled' }}
163167
BUILD_SUCCESS: ${{ steps.build.outcome == 'success' }}
164168
runs-on: ubuntu-latest
165-
timeout-minutes: ${{ inputs.job_timeout }}
166169
permissions:
167170
contents: read
168171
steps:
@@ -171,56 +174,32 @@ jobs:
171174
dnf install -y \
172175
copr-cli \
173176
git \
174-
jq \
175-
nodejs \
176-
zip
177+
jq
177178
178179
- name: Checkout
179180
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
180181

181182
- name: Set git safe directory
182183
run: git config --global --add safe.directory '*'
183184

184-
- name: Add problem matchers
185-
run: |
186-
# add default matchers
187-
mkdir -p .github/matchers
188-
189-
# download the latest rpmlint.json matcher
190-
if [[ ! "${{ github.repository }}" = "LizardByte/copr-ci" ]]; then
191-
# not in copr-ci repo, so download the rpmlint.json
192-
ref="master" # default to master branch
193-
curl \
194-
-fsS \
195-
--retry 3 \
196-
"https://raw.githubusercontent.com/lizardbyte/copr-ci/${ref}/.github/matchers/rpmlint.json" \
197-
-o ".github/matchers/rpmlint.json"
198-
fi
199-
echo "::add-matcher::.github/matchers/rpmlint.json"
200-
201-
# repo specific matchers
202-
if [[ -f ".github/matchers/copr-ci.json" ]]; then
203-
echo "Found copr-ci.json matcher, adding it..."
204-
echo "::add-matcher::.github/matchers/copr-ci.json"
205-
fi
206-
207185
- name: Get properties
186+
id: get-properties
208187
run: |
209188
# package name = repository name
210-
package=${{ github.event.repository.name }}
189+
package=${PACKAGE_NAME}
211190
copr_base="https://copr.fedorainfracloud.org/webhooks/custom-dir/${INPUTS_COPR_OWNERNAME}"
212191
213192
# release and released type
214-
if [[ "${{ github.event_name }}" = "release" ]]; then
215-
if [[ "${{ github.event.action }}" = "prereleased" ]]; then
193+
if [[ "${GH_EVENT_NAME}" = "release" ]]; then
194+
if [[ "${GH_EVENT_ACTION}" = "prereleased" ]]; then
216195
BUILD_CHANNEL="beta"
217196
COPR_PUSH_WEBHOOK="${copr_base}/${BUILD_CHANNEL}/${SECRETS_COPR_BETA_WEBHOOK_TOKEN}/${package}/"
218-
elif [[ "${{ github.event.action }}" = "released" ]]; then
197+
elif [[ "${GH_EVENT_ACTION}" = "released" ]]; then
219198
BUILD_CHANNEL="stable"
220199
COPR_PUSH_WEBHOOK="${copr_base}/${BUILD_CHANNEL}/${SECRETS_COPR_STABLE_WEBHOOK_TOKEN}/${package}/"
221200
fi
222-
elif [[ "${{ github.event_name }}" = "pull_request" ]]; then
223-
BUILD_CHANNEL="pulls:pr:${{ github.event.number }}"
201+
elif [[ "${GH_EVENT_NAME}" = "pull_request" ]]; then
202+
BUILD_CHANNEL="pulls:pr:${GH_EVENT_NUMBER}"
224203
COPR_PR_WEBHOOK="${copr_base}/${BUILD_CHANNEL}/${INPUTS_COPR_PR_WEBHOOK_TOKEN}/${package}/"
225204
fi
226205
@@ -234,8 +213,13 @@ jobs:
234213
echo "COPR_PUSH_WEBHOOK=${COPR_PUSH_WEBHOOK}"
235214
echo "COPR_PR_WEBHOOK=${COPR_PR_WEBHOOK}"
236215
216+
# Output BUILD_CHANNEL for other jobs
217+
echo "BUILD_CHANNEL=${BUILD_CHANNEL}" >> "${GITHUB_OUTPUT}"
218+
237219
- name: Build
238220
id: build
221+
env:
222+
PR_NUMBER: ${{ github.event.pull_request.number }}
239223
run: |
240224
curl \
241225
-fsS \
@@ -245,36 +229,78 @@ jobs:
245229
# "https://raw.githubusercontent.com/praiskup/copr-ci-tooling/main/copr-gh-actions-submit"
246230
247231
# if a PR number is added the script will use the PR webhook, otherwise it will use the push webhook
248-
bash submit ${{ github.event.pull_request.number }}
232+
bash submit ${PR_NUMBER}
249233
250234
- name: Cancel Copr build
251235
if: >-
252236
always() &&
253237
steps.build.outcome == 'cancelled' &&
254238
github.secret_source
239+
env:
240+
BUILD_ID: ${{ steps.build.outputs.BUILD_ID }}
255241
run: |
256242
mkdir -p ~/.config
257243
echo "${SECRETS_COPR_CLI_CONFIG}" > ~/.config/copr
258244
259245
copr-cli \
260246
cancel \
261-
${{ steps.build.outputs.BUILD_ID }}
247+
${BUILD_ID}
248+
249+
logs:
250+
name: Copr logs
251+
if: always() && needs.build.outputs.BUILD_ID != ''
252+
container: fedora:latest
253+
env:
254+
BUILD_CHANNEL: ${{ needs.build.outputs.BUILD_CHANNEL }}
255+
BUILD_ID: ${{ needs.build.outputs.BUILD_ID }}
256+
needs: build
257+
runs-on: ubuntu-latest
258+
permissions:
259+
contents: read
260+
steps:
261+
- name: Install dependencies
262+
run: |
263+
dnf install -y \
264+
jq
265+
266+
- name: Checkout
267+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
268+
269+
- name: Add problem matchers
270+
run: |
271+
# add default matchers
272+
mkdir -p .github/matchers
273+
274+
# download the latest rpmlint.json matcher
275+
if [[ ! "${{ github.repository }}" = "LizardByte/copr-ci" ]]; then
276+
# not in copr-ci repo, so download the rpmlint.json
277+
ref="master" # default to master branch
278+
curl \
279+
-fsS \
280+
--retry 3 \
281+
"https://raw.githubusercontent.com/lizardbyte/copr-ci/${ref}/.github/matchers/rpmlint.json" \
282+
-o ".github/matchers/rpmlint.json"
283+
fi
284+
echo "::add-matcher::.github/matchers/rpmlint.json"
285+
286+
# repo specific matchers
287+
if [[ -f ".github/matchers/copr-ci.json" ]]; then
288+
echo "Found copr-ci.json matcher, adding it..."
289+
echo "::add-matcher::.github/matchers/copr-ci.json"
290+
fi
262291
263292
- name: Logs
264-
if: >-
265-
always() &&
266-
steps.build.outcome != 'skipped'
267293
run: |
268-
package=${{ github.event.repository.name }}
294+
package=${PACKAGE_NAME}
269295
base_url="https://download.copr.fedorainfracloud.org/results/${INPUTS_COPR_OWNERNAME}/${BUILD_CHANNEL}"
270296
271297
# get chroots and prefixed build_id
272-
build_url="https://copr.fedorainfracloud.org/api_3/build/${{ steps.build.outputs.BUILD_ID }}"
298+
build_url="https://copr.fedorainfracloud.org/api_3/build/${BUILD_ID}"
273299
data=$(curl -fsS --retry 3 "${build_url}")
274300
275301
# Extract build_id from source_package.url (matches the last path segment after 'srpm-builds/')
276-
build_id=$(echo "${data}" | jq -r '.source_package.url' | sed -E 's#.*/srpm-builds/([0-9]+)/.*#\1#')
277-
echo "build_id: ${build_id}"
302+
build_id_alt=$(echo "${data}" | jq -r '.source_package.url' | sed -E 's#.*/srpm-builds/([0-9]+)/.*#\1#')
303+
echo "build_id_alt: ${build_id_alt}"
278304
279305
# Extract chroots
280306
chroots=$(echo "${data}" | jq -r '.chroots[]')
@@ -283,9 +309,9 @@ jobs:
283309
284310
# Array of "name|url" pairs
285311
logs=(
286-
"source_builder|${base_url}/srpm-builds/${build_id}/builder-live.log.gz"
287-
"source_backend|${base_url}/srpm-builds/${build_id}/backend.log.gz"
288-
"import|https://copr-dist-git.fedorainfracloud.org/per-task-logs/${{ steps.build.outputs.BUILD_ID }}.log"
312+
"source_builder|${base_url}/srpm-builds/${build_id_alt}/builder-live.log.gz"
313+
"source_backend|${base_url}/srpm-builds/${build_id_alt}/backend.log.gz"
314+
"import|https://copr-dist-git.fedorainfracloud.org/per-task-logs/${BUILD_ID}.log"
289315
)
290316
291317
for chroot in $chroots; do
@@ -311,16 +337,33 @@ jobs:
311337
312338
exit ${error}
313339
340+
download-artifacts:
341+
name: Download and upload artifacts
342+
if: always() && needs.build.outputs.BUILD_SUCCESS == 'true'
343+
container: fedora:latest
344+
env:
345+
BUILD_ID: ${{ needs.build.outputs.BUILD_ID }}
346+
needs: build
347+
runs-on: ubuntu-latest
348+
permissions:
349+
contents: read
350+
steps:
351+
- name: Install dependencies
352+
run: |
353+
dnf install -y \
354+
copr-cli \
355+
nodejs \
356+
zip
357+
314358
- name: Download build
315359
id: download-build
316-
if: steps.build.outcome == 'success'
317360
run: |
318361
mkdir -p artifacts
319362
copr-cli \
320363
download-build \
321364
--dest . \
322365
--rpms \
323-
${{ steps.build.outputs.BUILD_ID }}
366+
${BUILD_ID}
324367
325368
- name: Setup gh actions artifact client
326369
id: download-build-client

0 commit comments

Comments
 (0)