Skip to content

Commit 0259ebf

Browse files
committed
ci: upload build snippets to ci-builds
Add logic to upload the generated snippets to ci-builds, so that they can be used to populate the boards manager index and tool index in the Arduino IDE.
1 parent ea5680d commit 0259ebf

3 files changed

Lines changed: 139 additions & 9 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Copyright (c) Arduino s.r.l. and/or its affiliated companies
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Reusable workflow to upload the generated snippets to the ci-builds repo.
5+
# Must be called with 'id-token: write' permissions.
6+
7+
name: Upload snippets to ci-builds
8+
9+
on:
10+
workflow_call:
11+
secrets:
12+
# PAT with 'actions: write' permissions on the ci-builds repo.
13+
ci-builds-token:
14+
required: true
15+
inputs:
16+
# Name of the artifact containing the snippets to upload
17+
artifact:
18+
required: true
19+
type: string
20+
# Version to be associated with this snippet upload
21+
version:
22+
required: true
23+
type: string
24+
# Repository branch to be associated with this snippet upload
25+
base-branch:
26+
required: true
27+
type: string
28+
# Repo hosting the ci-builds workflow to call for storing the snippets.
29+
# Not required; useful for testing the workflow with a fork.
30+
ci-builds-repo-owner:
31+
required: false
32+
type: string
33+
default: 'arduino'
34+
ci-builds-repo-name:
35+
required: false
36+
type: string
37+
default: 'core-ci-builds'
38+
39+
jobs:
40+
ci-builds-upload:
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/download-artifact@v8
44+
with:
45+
name: ${{ inputs.artifact }}
46+
path: snippets/
47+
48+
- run: |
49+
echo "SNIPPETS<<EOF" >> $GITHUB_ENV
50+
(cd snippets && jq -cn 'reduce inputs as $i ({}; .[input_filename] = $i)' $(find * -name '*.json')) >> $GITHUB_ENV
51+
echo "EOF" >> $GITHUB_ENV
52+
53+
- name: Get OIDC identity token
54+
id: oidc
55+
uses: actions/github-script@v9
56+
with:
57+
script: |
58+
const token = await core.getIDToken('${{ inputs.ci-builds-repo-owner }}/${{ inputs.ci-builds-repo-name }}');
59+
core.setOutput('token', token)
60+
61+
- name: Store snippets in ci-builds
62+
uses: actions/github-script@v9
63+
with:
64+
github-token: ${{ secrets.ci-builds-token }}
65+
script: |
66+
await github.rest.actions.createWorkflowDispatch({
67+
owner: '${{ inputs.ci-builds-repo-owner }}',
68+
repo: '${{ inputs.ci-builds-repo-name }}',
69+
workflow_id: 'store-snippets.yml',
70+
ref: 'main',
71+
inputs: {
72+
oidc_token: '${{ steps.oidc.outputs.token }}',
73+
base_branch: '${{ inputs.base-branch }}',
74+
version: '${{ inputs.version }}',
75+
snippets: '${{ env.SNIPPETS }}',
76+
},
77+
});

.github/workflows/package_core.yml

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,14 @@ jobs:
469469
# errors due to race conditions with parallel branch runs should not fail the job
470470
extra/ci_calc_size_reports.py ${GITHUB_BASE_SHA} sketches-reports/ || true
471471
472+
# upload build metadata artifact, for upload to ci-builds
473+
- name: Archive build metadata information
474+
uses: actions/upload-artifact@v7
475+
with:
476+
name: build-metadata
477+
path: ${{ env.CORE_VER }}.json
478+
retention-days: 1
479+
472480
# upload comment request artifact (will be retrieved by leave_pr_comment.yml)
473481
- name: Archive comment information
474482
uses: actions/upload-artifact@v7
@@ -600,22 +608,45 @@ jobs:
600608

601609
- uses: actions/download-artifact@v8
602610
with:
611+
pattern: ArduinoCore-*.tar.bz2
603612
path: .
604-
pattern: ArduinoCore-*
605613
merge-multiple: true
606614

615+
- uses: actions/download-artifact@v8
616+
with:
617+
name: build-metadata
618+
path: snippets/metadata/
619+
607620
- name: Prepare package index snippets
608621
run: |
622+
mkdir -p snippets/platforms/
609623
jq -cr '.[]' <<< ${ARTIFACTS} | while read -r artifact; do
610624
# note: the archive names are always hash-based so they use a
611625
# predictable pattern. JSON files can use the tag for user-friendliness.
612626
ARTIFACT_FILE=ArduinoCore-${artifact}-${CORE_HASH}.tar.bz2
613-
PACKAGE_JSON=ArduinoCore-${artifact}-${CORE_TAG}.json
627+
PACKAGE_JSON=snippets/platforms/ArduinoCore-${artifact}-${CORE_TAG}.json
614628
./extra/gen_package_index_json.sh ${artifact} ${ARTIFACT_FILE} ${PACKAGE_JSON}
615629
done
616630
617631
- name: Archive package index snippets
618632
uses: actions/upload-artifact@v7
619633
with:
620-
name: ArduinoCore-zephyr-${{ env.CORE_TAG }}-jsons
621-
path: ArduinoCore-*-${{ env.CORE_TAG }}.json
634+
name: snippets-${{ env.CORE_TAG }}
635+
path: snippets/
636+
637+
ci-builds-upload:
638+
name: Upload to ci-builds
639+
if: ${{ github.event_name == 'push' && github.repository == 'arduino/ArduinoCore-zephyr' }}
640+
needs:
641+
- build-env
642+
- verify-core
643+
- prepare-json
644+
permissions:
645+
id-token: write # required to obtain the OIDC token
646+
uses: ./.github/workflows/ci_builds_upload.yml
647+
with:
648+
artifact: snippets-${{ needs.build-env.outputs.CORE_TAG }}
649+
version: ${{ needs.build-env.outputs.CORE_VER }}
650+
base-branch: ${{ needs.build-env.outputs.CORE_BRANCH }}
651+
secrets:
652+
ci-builds-token: ${{ secrets.CI_BUILDS_TOKEN }}

.github/workflows/package_tool.yml

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ jobs:
102102
cache: false
103103

104104
- name: Build and package tool
105-
run: extra/package_tool.sh tools/${{ matrix.tool }} ${{ matrix.version }}
105+
run: |
106+
mkdir -p snippets/tools snippets/metadata
107+
extra/package_tool.sh tools/${{ matrix.tool }} ${{ matrix.version }}
108+
mv distrib/*.json snippets/tools/
109+
# metadata dir is empty, but is still required to preserve the
110+
# directory structure in the generated artifacts
106111
107112
- name: Upload tool artifact
108113
uses: actions/upload-artifact@v7
@@ -113,12 +118,11 @@ jobs:
113118
distrib/*.zip
114119
retention-days: 7
115120

116-
- name: Upload JSON artifact
121+
- name: Upload JSON snippet
117122
uses: actions/upload-artifact@v7
118123
with:
119-
name: ${{ matrix.tool }}-${{ matrix.version }}.json
120-
path: distrib/*.json
121-
archive: false
124+
name: snippet-${{ matrix.tool }}-${{ matrix.version }}
125+
path: snippets/
122126

123127
# Upload the built tool packages to the S3 bucket for public distribution.
124128

@@ -167,3 +171,21 @@ jobs:
167171
# A failure here means either the build or publish step failed when it was expected to run.
168172
[ ${{ needs.build-tool.result }} == "success" ] && \
169173
( [ ${{ needs.publish-tool.result }} == "success" ] || [ ${{ needs.publish-tool.result }} == "skipped" ] )
174+
175+
ci-builds-upload:
176+
name: Upload to ci-builds
177+
if: fromJSON(needs.setup.outputs.is_release)
178+
needs:
179+
- setup
180+
- build-tool
181+
- publish-tool
182+
- verify-tool
183+
permissions:
184+
id-token: write # required to obtain the OIDC token
185+
uses: ./.github/workflows/ci_builds_upload.yml
186+
with:
187+
artifact: snippet-${{ needs.setup.outputs.tool_artifact }}
188+
version: ${{ needs.setup.outputs.CORE_VER }}
189+
base-branch: ${{ needs.setup.outputs.CORE_BRANCH }}
190+
secrets:
191+
ci-builds-token: ${{ secrets.CI_BUILDS_TOKEN }}

0 commit comments

Comments
 (0)