Skip to content

Commit

Permalink
CD: Add build status reporing
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit ecfee6a
Author: cyqsimon <[email protected]>
Date:   Thu Oct 12 13:30:10 2023 +0800

    Only run reporting job when build ID output is not empty

    - See dorny/paths-filter#66

commit c286138
Author: cyqsimon <[email protected]>
Date:   Thu Oct 12 13:26:18 2023 +0800

    Better job & step naming

commit fa80712
Author: cyqsimon <[email protected]>
Date:   Thu Oct 12 13:25:17 2023 +0800

    rm mock build ID

commit 445f56f
Author: cyqsimon <[email protected]>
Date:   Thu Oct 12 13:24:18 2023 +0800

    `jq` is installed by default

commit 3e526a0
Author: cyqsimon <[email protected]>
Date:   Thu Oct 12 13:18:31 2023 +0800

    Use a running mock build ID

commit fd1c375
Author: cyqsimon <[email protected]>
Date:   Thu Oct 12 13:14:29 2023 +0800

    Query API until build completion

commit ddd091a
Author: cyqsimon <[email protected]>
Date:   Thu Oct 12 12:53:26 2023 +0800

    Create job matrix using JSON array output

commit 139dc51
Author: cyqsimon <[email protected]>
Date:   Thu Oct 12 12:47:43 2023 +0800

    Generate JSON array correctly

commit 1fd4c8e
Author: cyqsimon <[email protected]>
Date:   Thu Oct 12 12:42:21 2023 +0800

    Correctly output whole array

commit 627b1e5
Author: cyqsimon <[email protected]>
Date:   Thu Oct 12 12:39:56 2023 +0800

    Add mock build IDs

commit 4e0f5d6
Author: cyqsimon <[email protected]>
Date:   Thu Oct 12 12:36:20 2023 +0800

    add build ID output
  • Loading branch information
cyqsimon committed Oct 12, 2023
1 parent 03bf9ba commit 1586228
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/rebuild-changed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
name: Trigger rebuild for modified .spec files
runs-on: ubuntu-latest
timeout-minutes: 3
outputs:
builds: ${{ steps.send-request.outputs.builds }}
steps:
- name: Install ripgrep
run: sudo apt-get install -y ripgrep
Expand All @@ -28,12 +30,49 @@ jobs:
files: specs/*.spec

- name: Send rebuild request to COPR
id: send-request
env:
URL: ${{ secrets.COPR_WEBHOOK_URL }}
run: |
BUILD_IDS=()
for FILE in ${{ steps.spec-modified.outputs.modified_files }}; do
PKG=$(rg '^Name:\s*([\w\d_\-]+)\s*$' --replace '$1' $FILE)
echo "Package $PKG changed (Spec file: $FILE); sending rebuild request"
BUILD_ID=$(curl -Ssf -X POST "$URL/$PKG")
echo "Build submitted: https://copr.fedorainfracloud.org/coprs/build/$BUILD_ID"
BUILD_IDS+=( "$BUILD_ID" )
done
echo "builds=$(printf '%s\n' "${BUILD_IDS[@]}" | jq -ncR '[inputs] | map(select(. != ""))')" >> "$GITHUB_OUTPUT"
report-status:
name: Report build status
needs: trigger-rebuild-for-modified
runs-on: ubuntu-latest
if: needs.trigger-rebuild-for-modified.outputs.builds != '[]'
strategy:
matrix:
build_id: ${{ fromJson(needs.trigger-rebuild-for-modified.outputs.builds) }}
steps:
- name: Report status
run: |
while true; do
STATUS=$(curl -Ssf "https://copr.fedorainfracloud.org/api_3/build/${{ matrix.build_id }}" | jq -r '.state')
case $STATUS in
pending | starting | importing | imported | waiting | running)
echo "Build is $STATUS. Querying again in 15s."
sleep 15
;;
succeeded | forked)
echo "Build $STATUS."
exit 0
;;
failed | canceled | skipped)
echo "Build $STATUS."
exit 1
;;
*)
echo "COPR API reported unknown status: $STATUS."
exit 2
;;
esac
done

0 comments on commit 1586228

Please sign in to comment.