Skip to content

Commit 837c45a

Browse files
committed
package_core/tool: export CORE_BRANCH for ci-builds tracking
Map the target branch for this workflow (HEAD_REF for branch pushes, or closest branch that contains the tag) to CORE_BRANCH, so it can be used for ci-builds tracking in the JSON export. Do the same in the package_tool workflow, where CORE_BRANCH is needed to link the tool packages to the core version they were built with. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
1 parent b849f48 commit 837c45a

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

.github/workflows/package_core.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ jobs:
4040
# Tag (if found) or hash identifying this core build, should be used for
4141
# user-friendly strings and file names
4242
CORE_TAG: ${{ env.CORE_TAG }}
43+
# Target branch referred to by this workflow (HEAD_REF for branch pushes,
44+
# or closest branch that contains the tag), used for ci-builds tracking
45+
CORE_BRANCH: ${{ env.CORE_BRANCH }}
4346
# Hash identifying this core build, should be used for exact version match
4447
CORE_HASH: ${{ env.CORE_HASH }}
4548
# JSON describing all boards to build, collected by get_board_details.sh
@@ -80,6 +83,13 @@ jobs:
8083
run: |
8184
echo "## Building \`$CORE_VER\`" >> "$GITHUB_STEP_SUMMARY"
8285
echo "CORE_TAG=$(git describe --tags --exact-match --exclude '*/*' 2>/dev/null || echo $CORE_HASH)" >> "$GITHUB_ENV"
86+
if [[ "${{ github.ref_type }}" == "tag" ]]; then
87+
BRANCH=$(git branch -r --contains HEAD --sort=-committerdate --format='%(refname:short)' | sed 's|origin/||' | grep -v HEAD | head -1)
88+
[[ -n "$BRANCH" ]] || { echo "::error::No branch found containing tag ${{ github.ref_name }}"; exit 1; }
89+
echo "CORE_BRANCH=${BRANCH}" >> "$GITHUB_ENV"
90+
else
91+
echo "CORE_BRANCH=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_ENV"
92+
fi
8393
echo "ALL_BOARD_FQBNS=$(jq -c 'map((. + {link_mode: "static"}), (. + {link_mode: "dynamic"}))' <<< ${ALL_BOARD_DATA})" >> "$GITHUB_ENV"
8494
echo "ARTIFACTS=$(jq -c '["zephyr"] + (map(.artifact) | unique)' <<< ${ALL_BOARD_DATA})" >> "$GITHUB_ENV"
8595
echo "SUB_ARCHES=$(jq -c 'map(.subarch) | unique' <<< ${ALL_BOARD_DATA})" >> "$GITHUB_ENV"

.github/workflows/package_tool.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ jobs:
4040
matrix: ${{ steps.set-matrix.outputs.matrix }}
4141
is_release: ${{ steps.set-matrix.outputs.is_release }}
4242
tool_artifact: ${{ steps.set-matrix.outputs.tool_artifact }}
43+
CORE_BRANCH: ${{ steps.set-matrix.outputs.CORE_BRANCH }}
44+
CORE_VER: ${{ steps.set-matrix.outputs.CORE_VER }}
4345
steps:
4446
- uses: actions/checkout@v6
4547
with:
4648
fetch-depth: 0
49+
fetch-tags: true # for get_core_version
4750
persist-credentials: false
4851
submodules: 'ignore'
4952

@@ -59,16 +62,24 @@ jobs:
5962
'{include: [{tool: $tool, version: $version}]}')
6063
echo "tool_artifact=$TOOL-$VERSION" >> "$GITHUB_OUTPUT"
6164
echo "is_release=${{ github.repository == 'arduino/ArduinoCore-zephyr' }}" >> "$GITHUB_OUTPUT"
65+
66+
BRANCH=$(git branch -r --contains HEAD --sort=-committerdate --format='%(refname:short)' | sed 's|origin/||' | grep -v HEAD | head -1)
67+
[[ -n "$BRANCH" ]] || { echo "::error::No branch found containing tag ${{ github.ref_name }}"; exit 1; }
68+
echo "CORE_BRANCH=${BRANCH}" >> "$GITHUB_OUTPUT"
6269
else
6370
# build all tools using commit SHA as version
6471
VERSION=$(git rev-parse --short ${{ github.event.pull_request.head.sha || 'HEAD' }})
6572
MATRIX=$(for d in tools/*/; do [ -f "$d/go.mod" ] && basename "$d"; done \
6673
| jq -Rnc --arg version "$VERSION" '{include: [inputs | {tool: ., version: $version}]}')
6774
echo "tool_artifact=" >> "$GITHUB_OUTPUT"
6875
echo "is_release=false" >> "$GITHUB_OUTPUT"
76+
77+
echo "CORE_BRANCH=${{ github.head_ref || github.ref_name }}" >> "$GITHUB_OUTPUT"
6978
fi
7079
echo "matrix=$MATRIX" >> "$GITHUB_OUTPUT"
7180
81+
echo "CORE_VER=$(extra/get_core_version.sh)" >> "$GITHUB_OUTPUT"
82+
7283
# Build and package the tools in parallel according to the matrix, uploading
7384
# the resulting packages and metadata as artifacts for later use.
7485

.github/workflows/upload_json.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
runs-on: ubuntu-latest
3030
if: ${{ github.repository == 'arduino/ArduinoCore-zephyr'
3131
&& github.event.workflow_run.event == 'push'
32-
&& github.event.workflow_run.head_branch == 'main'
32+
&& !contains(github.event.workflow_run.head_branch, '/')
3333
&& github.event.workflow_run.conclusion == 'success' }}
3434
environment:
3535
name: github-pages

0 commit comments

Comments
 (0)