Skip to content

Commit 542eac6

Browse files
github: Use IAM Roles to push files on AWS S3 (#148)
* github: Use IAM Roles to push files on AWS S3 * align workflow with our workflow-templates * fix workflow
1 parent 18124f4 commit 542eac6

File tree

1 file changed

+49
-37
lines changed

1 file changed

+49
-37
lines changed

.github/workflows/release-go-task.yml

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ env:
88
DIST_DIR: tools/bhy-controller/src/dist
99
# The project's folder on Arduino's download server for uploading builds
1010
AWS_PLUGIN_TARGET: /unisense/tools/bhy-controller/
11-
ARTIFACT_NAME: dist
11+
AWS_REGION: "us-east-1"
12+
ARTIFACT_PREFIX: dist-
1213

1314
on:
1415
push:
@@ -24,11 +25,16 @@ jobs:
2425
strategy:
2526
matrix:
2627
os:
27-
- Windows_32bit
28-
- Windows_64bit
29-
- Linux_32bit
30-
- Linux_64bit
31-
- macOS_64bit
28+
- task: Windows_32bit
29+
artifact-suffix: Windows_32bit
30+
- task: Windows_64bit
31+
artifact-suffix: Windows_64bit
32+
- task: Linux_32bit
33+
artifact-suffix: Linux_32bit
34+
- task: Linux_64bit
35+
artifact-suffix: Linux_64bit
36+
- task: macOS_64bit
37+
artifact-suffix: macOS_64bit
3238

3339
steps:
3440
- name: Checkout repository
@@ -38,7 +44,7 @@ jobs:
3844

3945
- name: Create changelog
4046
# Avoid creating the same changelog for each os
41-
if: matrix.os == 'Windows_32bit'
47+
if: matrix.os.task == 'Windows_32bit'
4248
uses: arduino/create-changelog@v1
4349
with:
4450
tag-regex: '^[0-9]+\.[0-9]+\.[0-9]+.*$'
@@ -53,21 +59,19 @@ jobs:
5359
version: 3.x
5460

5561
- name: Build
56-
run: task dist:${{ matrix.os }}
62+
run: task dist:${{ matrix.os.task }}
5763

5864
- name: Upload artifacts
5965
uses: actions/upload-artifact@v4
6066
with:
6167
if-no-files-found: error
62-
name: ${{ env.ARTIFACT_NAME }}
68+
name: ${{ env.ARTIFACT_PREFIX }}${{ matrix.os.artifact-suffix }}
6369
path: ${{ env.DIST_DIR }}
6470

6571
notarize-macos:
66-
name: Notarize ${{ matrix.artifact.name }}
72+
name: Notarize ${{ matrix.build.folder-suffix }}
6773
runs-on: macos-latest
6874
needs: create-release-artifacts
69-
outputs:
70-
checksum-darwin_amd64: ${{ steps.re-package.outputs.checksum-darwin_amd64 }}
7175
permissions:
7276
contents: read
7377

@@ -76,18 +80,26 @@ jobs:
7680

7781
strategy:
7882
matrix:
79-
artifact:
80-
- name: darwin_amd64
81-
path: "macOS_64bit.tar.gz"
83+
build:
84+
- artifact-suffix: macOS_64bit
85+
folder-suffix: darwin_amd64
86+
package-suffix: "macOS_64bit.tar.gz"
8287

8388
steps:
89+
- name: Set environment variables
90+
run: |
91+
# See: https://docs.github.com/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-an-environment-variable
92+
echo "BUILD_FOLDER=${{ env.PROJECT_NAME }}_osx_${{ matrix.build.folder-suffix }}" >> "$GITHUB_ENV"
93+
TAG="${GITHUB_REF/refs\/tags\//}"
94+
echo "PACKAGE_FILENAME=${{ env.PROJECT_NAME }}_${TAG}_${{ matrix.build.package-suffix }}" >> $GITHUB_ENV
95+
8496
- name: Checkout repository
8597
uses: actions/checkout@v4
8698

8799
- name: Download artifacts
88100
uses: actions/download-artifact@v4
89101
with:
90-
name: ${{ env.ARTIFACT_NAME }}
102+
name: ${{ env.ARTIFACT_PREFIX }}${{ matrix.build.artifact-suffix }}
91103
path: ${{ env.DIST_DIR }}
92104

93105
- name: Import Code-Signing Certificates
@@ -124,7 +136,7 @@ jobs:
124136
run: |
125137
cat > "${{ env.GON_CONFIG_PATH }}" <<EOF
126138
# See: https://github.com/Bearer/gon#configuration-file
127-
source = ["${{ env.DIST_DIR }}/${{ env.PROJECT_NAME }}_osx_${{ matrix.artifact.name }}/${{ env.PROJECT_NAME }}"]
139+
source = ["${{ env.DIST_DIR }}/${{ env.BUILD_FOLDER }}/${{ env.PROJECT_NAME }}"]
128140
bundle_id = "cc.arduino.${{ env.PROJECT_NAME }}"
129141
130142
sign {
@@ -147,42 +159,42 @@ jobs:
147159
gon "${{ env.GON_CONFIG_PATH }}"
148160
149161
- name: Re-package binary
150-
id: re-package
151162
working-directory: ${{ env.DIST_DIR }}
152163
# Repackage the signed binary replaced in place by Gon (ignoring the output zip file)
153164
run: |
154165
# GitHub's upload/download-artifact actions don't preserve file permissions,
155166
# so we need to add execution permission back until the action is made to do this.
156-
chmod +x "${{ env.PROJECT_NAME }}_osx_${{ matrix.artifact.name }}/${{ env.PROJECT_NAME }}"
157-
TAG="${GITHUB_REF/refs\/tags\//}"
158-
PACKAGE_FILENAME="${{ env.PROJECT_NAME }}_${TAG}_${{ matrix.artifact.path }}"
159-
tar -czvf "$PACKAGE_FILENAME" \
160-
-C "${{ env.PROJECT_NAME }}_osx_${{ matrix.artifact.name }}/" "${{ env.PROJECT_NAME }}" \
167+
chmod +x "${{ env.BUILD_FOLDER }}/${{ env.PROJECT_NAME }}"
168+
tar -czvf "${{ env.PACKAGE_FILENAME }}" \
169+
-C "${{ env.BUILD_FOLDER }}/" "${{ env.PROJECT_NAME }}" \
161170
-C ../../ LICENSE.txt
162-
echo "PACKAGE_FILENAME=$PACKAGE_FILENAME" >> $GITHUB_ENV
163171
164-
- name: Upload artifact
172+
- name: Replace artifact with notarized build
165173
uses: actions/upload-artifact@v4
166174
with:
167175
if-no-files-found: error
168-
name: ${{ env.ARTIFACT_NAME }}
169-
path: ${{ env.DIST_DIR }}
176+
name: ${{ env.ARTIFACT_PREFIX }}${{ matrix.build.artifact-suffix }}
177+
overwrite: true
178+
path: ${{ env.DIST_DIR }}/${{ env.PACKAGE_FILENAME }}
170179

171180
create-release:
172181
runs-on: ubuntu-latest
182+
environment: production
173183
needs: notarize-macos
174184
permissions:
175185
contents: write
186+
id-token: write # This is required for requesting the JWT
176187

177188
steps:
178189
- name: Download artifact
179190
uses: actions/download-artifact@v4
180191
with:
181-
name: ${{ env.ARTIFACT_NAME }}
192+
pattern: ${{ env.ARTIFACT_PREFIX }}*
193+
merge-multiple: true
182194
path: ${{ env.DIST_DIR }}
183195

184196
- name: Create checksum file
185-
working-directory: ${{ env.DIST_DIR}}
197+
working-directory: ${{ env.DIST_DIR }}
186198
run: |
187199
TAG="${GITHUB_REF/refs\/tags\//}"
188200
sha256sum ${{ env.PROJECT_NAME }}_${TAG}* > ${TAG}-checksums.txt
@@ -215,12 +227,12 @@ jobs:
215227
# (all the files we need are in the DIST_DIR root)
216228
artifacts: ${{ env.DIST_DIR }}/*
217229

230+
- name: configure aws credentials
231+
uses: aws-actions/configure-aws-credentials@v4
232+
with:
233+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
234+
role-session-name: "github_${{ env.PROJECT_NAME }}"
235+
aws-region: ${{ env.AWS_REGION }}
236+
218237
- name: Upload release files on Arduino downloads servers
219-
uses: docker://plugins/s3
220-
env:
221-
PLUGIN_SOURCE: "${{ env.DIST_DIR }}/*"
222-
PLUGIN_TARGET: ${{ env.AWS_PLUGIN_TARGET }}
223-
PLUGIN_STRIP_PREFIX: "${{ env.DIST_DIR }}/"
224-
PLUGIN_BUCKET: ${{ secrets.DOWNLOADS_BUCKET }}
225-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
226-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
238+
run: aws s3 sync ${{ env.DIST_DIR }} s3://${{ secrets.DOWNLOADS_BUCKET }}${{ env.AWS_PLUGIN_TARGET }}

0 commit comments

Comments
 (0)