From 3c167379d085059c2539a65121a6045226c289c7 Mon Sep 17 00:00:00 2001 From: Maximilian Deubel Date: Mon, 4 Nov 2024 16:41:06 +0100 Subject: [PATCH] ci: reuse build for release assets Reuse the build artifacts from the test workflow for the release assets. Signed-off-by: Maximilian Deubel --- .github/workflows/attach_release_assets.yml | 44 +++++++++++++++------ .github/workflows/test.yml | 2 + 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/.github/workflows/attach_release_assets.yml b/.github/workflows/attach_release_assets.yml index 1977239d..7c114813 100644 --- a/.github/workflows/attach_release_assets.yml +++ b/.github/workflows/attach_release_assets.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fd02126b..e70e7f66 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,6 +30,8 @@ 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