Skip to content

Commit 03416c4

Browse files
feat: download logs
1 parent 50208a2 commit 03416c4

2 files changed

Lines changed: 61 additions & 59 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: 61 additions & 41 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,63 @@ 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
208-
fi
209+
copr-cli \
210+
cancel \
211+
${{ steps.build.outputs.BUILD_ID }}
209212
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
213+
- name: Logs
218214
run: |
219-
dnf install -y \
220-
copr-cli \
221-
nodejs \
222-
zip
215+
package=${{ github.event.repository.name }}
216+
base_url="https://download.copr.fedorainfracloud.org/results/${{ inputs.copr_ownername }}/${BUILD_CHANNEL}"
217+
218+
build_url="https://copr.fedorainfracloud.org/api_3/build/${{ steps.build.outputs.BUILD_ID }}"
219+
chroots=$(curl -s "${build_url}" | jq -r '.chroots[]')
220+
221+
error=0
222+
for chroot in $chroots; do
223+
set +e
224+
echo "::group::Logs - ${chroot}"
225+
url="${base_url}/${chroot}/${{ steps.build.outputs.BUILD_ID }}-${package}/builder-live.log.gz"
226+
227+
# download and print the logs
228+
curl -sS "${url}"
229+
if [ $? -ne 0 ]; then
230+
echo "Failed to download logs from ${url}"
231+
error=1
232+
fi
233+
echo "::endgroup::"
234+
set -e
235+
done
236+
237+
exit ${error}
223238
224239
- name: Download build
240+
id: download-build
241+
if: steps.build.outcome == 'success'
225242
run: |
226243
mkdir -p artifacts
227244
copr-cli \
228245
download-build \
229246
--dest . \
230247
--rpms \
231-
${{ needs.build.outputs.BUILD_ID }}
248+
${{ steps.build.outputs.BUILD_ID }}
232249
233250
- name: Setup gh actions artifact client
251+
id: download-build-client
252+
if: steps.download-build.outcome == 'success'
234253
uses: lhotari/gh-actions-artifact-client@v2
235254

236255
- name: Upload artifacts
256+
if: steps.download-build-client.outcome == 'success'
237257
run: |
238258
find . -type f -name "*.rpm" ! -name "*.src.rpm" | while read -r file; do
239259
name=build-$(basename "$file")

0 commit comments

Comments
 (0)