Skip to content

Commit af4e0d9

Browse files
feat: add problem matcher and log downloader
1 parent 50208a2 commit af4e0d9

2 files changed

Lines changed: 88 additions & 58 deletions

File tree

.github/workflows/copr-ci-post.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

.github/workflows/copr-ci.yml

Lines changed: 88 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ on:
2727
description: 'Job timeout in minutes.'
2828
required: false
2929
type: number
30-
default: 60
30+
default: 90
3131
secrets:
3232
COPR_BETA_WEBHOOK_TOKEN:
3333
description: 'Copr beta webhook token. This should be a secret.'
@@ -136,15 +136,28 @@ jobs:
136136
needs: package-init
137137
if: github.repository_owner == inputs.github_org_owner
138138
runs-on: ubuntu-latest
139+
container: fedora:latest
139140
timeout-minutes: ${{ inputs.job_timeout }}
140141
outputs:
141142
BUILD_ID: ${{ steps.build.outputs.BUILD_ID }}
142143
BUILD_CANCEL: ${{ steps.build.outcome == 'cancelled' }}
143144
BUILD_SUCCESS: ${{ steps.build.outcome == 'success' }}
144145
steps:
146+
- name: Install dependencies
147+
run: |
148+
dnf install -y \
149+
copr-cli \
150+
git \
151+
jq \
152+
nodejs \
153+
zip
154+
145155
- name: Checkout
146156
uses: actions/checkout@v4
147157

158+
- name: Set git safe directory
159+
run: git config --global --add safe.directory '*'
160+
148161
- name: Get properties
149162
env:
150163
COPR_PR_WH_TOKEN: ${{ inputs.copr_pr_webhook_token }}
@@ -156,17 +169,22 @@ jobs:
156169
# release and released type
157170
if [ "${{ github.event_name }}" = "release" ]; then
158171
if [ "${{ github.event.action }}" = "prereleased" ]; then
159-
COPR_PUSH_WEBHOOK="${copr_base}/beta/${{ secrets.COPR_BETA_WEBHOOK_TOKEN }}/${package}/"
172+
BUILD_CHANNEL="beta"
173+
COPR_PUSH_WEBHOOK="${copr_base}/${BUILD_CHANNEL}/${{ secrets.COPR_BETA_WEBHOOK_TOKEN }}/${package}/"
160174
elif [ "${{ github.event.action }}" = "released" ]; then
161-
COPR_PUSH_WEBHOOK="${copr_base}/stable/${{ secrets.COPR_STABLE_WEBHOOK_TOKEN }}/${package}/"
175+
BUILD_CHANNEL="stable"
176+
COPR_PUSH_WEBHOOK="${copr_base}/${BUILD_CHANNEL}/${{ secrets.COPR_STABLE_WEBHOOK_TOKEN }}/${package}/"
162177
fi
163178
elif [ "${{ github.event_name }}" = "pull_request" ]; then
164-
COPR_PR_WEBHOOK="${copr_base}/pulls:pr:${{ github.event.number }}/${{ env.COPR_PR_WH_TOKEN }}/${package}/"
179+
BUILD_CHANNEL="pulls:pr:${{ github.event.number }}"
180+
COPR_PR_WEBHOOK="${copr_base}/${BUILD_CHANNEL}/${{ env.COPR_PR_WH_TOKEN }}/${package}/"
165181
fi
166182
183+
echo "BUILD_CHANNEL=${BUILD_CHANNEL}" >> $GITHUB_ENV
167184
echo "COPR_PUSH_WEBHOOK=${COPR_PUSH_WEBHOOK}" >> $GITHUB_ENV
168185
echo "COPR_PR_WEBHOOK=${COPR_PR_WEBHOOK}" >> $GITHUB_ENV
169186
187+
echo "BUILD_CHANNEL=${BUILD_CHANNEL}"
170188
echo "COPR_PUSH_WEBHOOK=${COPR_PUSH_WEBHOOK}"
171189
echo "COPR_PR_WEBHOOK=${COPR_PR_WEBHOOK}"
172190
@@ -179,61 +197,91 @@ jobs:
179197
# if a PR number is added the script will use the PR webhook, otherwise it will use the push webhook
180198
bash submit ${{ github.event.pull_request.number }}
181199
182-
cancel-build:
183-
name: Cancel build
184-
needs: build
185-
if: |
186-
always() &&
187-
needs.build.outputs.BUILD_CANCEL == 'true'
188-
runs-on: ubuntu-latest
189-
container: fedora:latest
190-
steps:
191-
- name: Install dependencies
192-
run: |
193-
dnf install -y \
194-
copr-cli
195-
196200
- name: Cancel Copr build
201+
if: >-
202+
always() &&
203+
steps.build.outcome == 'cancelled' &&
204+
github.secret_source
197205
run: |
198-
if [ -n "${{ secrets.COPR_CLI_CONFIG }}" ]; then
199-
mkdir -p ~/.config
200-
echo "${{ secrets.COPR_CLI_CONFIG }}" > ~/.config/copr
206+
mkdir -p ~/.config
207+
echo "${{ secrets.COPR_CLI_CONFIG }}" > ~/.config/copr
201208
202-
copr-cli \
203-
cancel \
204-
${{ needs.build.outputs.BUILD_ID }}
205-
else
206-
echo "Cannot cancel Copr build. No Copr CLI configuration file found. This is likely a PR from a fork."
207-
exit 1
209+
copr-cli \
210+
cancel \
211+
${{ steps.build.outputs.BUILD_ID }}
212+
213+
- name: Add problem matcher
214+
if: >-
215+
always() &&
216+
steps.build.outcome != 'skipped'
217+
run: |
218+
if [ -f "${{ github.workspace }}/.github/matchers/copr-ci.json" ]; then
219+
echo "::add-matcher::${{ github.workspace }}/.github/matchers/copr-ci.json"
208220
fi
209221
210-
download-build:
211-
name: Download build
212-
if: needs.build.outputs.BUILD_SUCCESS == 'true'
213-
needs: build
214-
runs-on: ubuntu-latest
215-
container: fedora:latest
216-
steps:
217-
- name: Install dependencies
222+
- name: Logs
223+
if: >-
224+
always() &&
225+
steps.build.outcome != 'skipped'
218226
run: |
219-
dnf install -y \
220-
copr-cli \
221-
nodejs \
222-
zip
227+
package=${{ github.event.repository.name }}
228+
base_url="https://download.copr.fedorainfracloud.org/results/${{ inputs.copr_ownername }}/${BUILD_CHANNEL}"
229+
build_id="0${{ steps.build.outputs.BUILD_ID }}"
230+
231+
# Array of "name|url" pairs
232+
logs=(
233+
"source_builder|${base_url}/srpm-builds/${build_id}/builder-live.log.gz"
234+
"source_backend|${base_url}/srpm-builds/${build_id}/backend.log.gz"
235+
"import|https://copr-dist-git.fedorainfracloud.org/per-task-logs/${{ steps.build.outputs.BUILD_ID }}.log"
236+
)
237+
238+
build_url="https://copr.fedorainfracloud.org/api_3/build/${{ steps.build.outputs.BUILD_ID }}"
239+
chroots=$(curl -s "${build_url}" | jq -r '.chroots[]')
240+
241+
for chroot in $chroots; do
242+
logs+=("builder_${chroot}|${base_url}/${chroot}/${build_id}-${package}/builder-live.log.gz")
243+
logs+=("backend_${chroot}|${base_url}/${chroot}/${build_id}-${package}/backend.log.gz")
244+
done
245+
246+
error=0
247+
for entry in "${logs[@]}"; do
248+
name="${entry%%|*}"
249+
url="${entry#*|}"
250+
set +e
251+
echo "::group::Logs - ${name}"
252+
if [[ "${url}" == *.gz ]]; then
253+
curl -fsS --retry 3 "${url}" | gunzip -c
254+
else
255+
curl -fsS --retry 3 "${url}"
256+
fi
257+
if [ $? -ne 0 ]; then
258+
echo "Failed to download logs from ${url}"
259+
error=1
260+
fi
261+
echo "::endgroup::"
262+
set -e
263+
done
264+
265+
exit ${error}
223266
224267
- name: Download build
268+
id: download-build
269+
if: steps.build.outcome == 'success'
225270
run: |
226271
mkdir -p artifacts
227272
copr-cli \
228273
download-build \
229274
--dest . \
230275
--rpms \
231-
${{ needs.build.outputs.BUILD_ID }}
276+
${{ steps.build.outputs.BUILD_ID }}
232277
233278
- name: Setup gh actions artifact client
279+
id: download-build-client
280+
if: steps.download-build.outcome == 'success'
234281
uses: lhotari/gh-actions-artifact-client@v2
235282

236283
- name: Upload artifacts
284+
if: steps.download-build-client.outcome == 'success'
237285
run: |
238286
find . -type f -name "*.rpm" ! -name "*.src.rpm" | while read -r file; do
239287
name=build-$(basename "$file")

0 commit comments

Comments
 (0)