Skip to content

Commit

Permalink
ci: reuse build for release assets
Browse files Browse the repository at this point in the history
Reuse the build artifacts from the test workflow for the release assets.

Signed-off-by: Maximilian Deubel <[email protected]>
  • Loading branch information
maxd-nordic committed Nov 4, 2024
1 parent ed39a51 commit b591785
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
44 changes: 32 additions & 12 deletions .github/workflows/attach_release_assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,46 @@ on:
types: [created]

jobs:
build:
uses: ./.github/workflows/build.yml
secrets: inherit
with:
build_bl_update: true
build_debug: true
memfault_sw_type: "hello.nrfcloud.com"

attach-assets:
runs-on: ubuntu-24.04
needs: [build]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download artifact
- name: Set up the GitHub CLI
uses: actions/gh-cli@v1

- name: Find Workflow Run ID for Build
id: find_run_id
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
tag_name="${{ github.event.release.tag_name }}"
workflow_id="test.yml"
# Get workflow runs for the specified workflow ID and tag name
response=$(gh api repos/${{ github.repository }}/actions/workflows/$workflow_id/runs \
-F event=push \
-F branch="$tag_name")
# Extract the run ID of the latest workflow run on the specified tag
run_id=$(echo "$response" | jq -r '.workflow_runs[] | select(.head_branch == env.tag_name) | .id' | head -n 1)
if [ -z "$run_id" ]; then
echo "No run ID found for tag: $tag_name in workflow: $workflow_id"
exit 1
else
echo "Found run ID: $run_id"
echo "::set-output name=run_id::$run_id"
fi
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: firmware-*
merge-multiple: true
pattern: firmware-*
merge-multiple: true
run-id: ${{ steps.find_run_id.outputs.run_id }}
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Deploy release to github
uses: softprops/action-gh-release@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/on_target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ on:

jobs:
target_test:
name: Target Test
name: Test on target
runs-on: self-hosted
environment: production
container:
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Test on Target
name: Build and Test

on:
workflow_dispatch:
Expand Down Expand Up @@ -30,13 +30,15 @@ jobs:
secrets: inherit
with:
build_bl_update: true
build_debug: true
memfault_sw_type: "hello.nrfcloud.com"
dfu_check:
uses: ./.github/workflows/dfu_check.yml
needs: build
secrets: inherit
with:
artifact_run_id: ${{ needs.build.outputs.run_id }}
test:
target_test:
uses: ./.github/workflows/on_target.yml
needs: build
secrets: inherit
Expand Down

0 comments on commit b591785

Please sign in to comment.