Skip to content

Commit 1724e56

Browse files
Merge pull request #203 from arduino/iam-roles
github: Use IAM Roles to push files on AWS S3
2 parents 1a68dfb + 9af805a commit 1724e56

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

Diff for: .github/workflows/build.yml

+21-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ on:
1212
- main
1313

1414
env:
15+
# As defined by the Taskfile's PROJECT_NAME variable
16+
PROJECT_NAME: arduino-language-server
1517
ARTIFACT_PREFIX: dist-
18+
AWS_REGION: "us-east-1"
19+
# The project's folder on Arduino's download server for uploading builds
20+
AWS_PLUGIN_TARGET: /arduino-language-server/nightly/
21+
# As defined by the Taskfile's DIST_DIR variable
22+
DIST_DIR: dist
1623

1724
jobs:
1825

@@ -65,20 +72,24 @@ jobs:
6572
needs: build
6673
if: github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main')
6774
runs-on: ubuntu-latest
75+
environment: production
76+
permissions:
77+
contents: write
78+
id-token: write # This is required for requesting the JWT
6879
steps:
6980
- name: Download Workflow Artifact [GitHub Actions]
7081
uses: actions/download-artifact@v4
7182
with:
7283
pattern: ${{ env.ARTIFACT_PREFIX }}*
7384
merge-multiple: true
74-
path: build-artifacts
85+
path: ${{ env.DIST_DIR }}
7586

76-
- name: Publish Nightly [S3]
77-
uses: docker://plugins/s3
78-
env:
79-
PLUGIN_SOURCE: "build-artifacts/*"
80-
PLUGIN_TARGET: "/arduino-language-server/nightly"
81-
PLUGIN_STRIP_PREFIX: "build-artifacts/"
82-
PLUGIN_BUCKET: ${{ secrets.DOWNLOADS_BUCKET }}
83-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
84-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
87+
- name: configure aws credentials
88+
uses: aws-actions/configure-aws-credentials@v4
89+
with:
90+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
91+
role-session-name: "github_${{ env.PROJECT_NAME }}"
92+
aws-region: ${{ env.AWS_REGION }}
93+
94+
- name: Upload release files on Arduino downloads servers
95+
run: aws s3 sync ${{ env.DIST_DIR }} s3://${{ secrets.DOWNLOADS_BUCKET }}${{ env.AWS_PLUGIN_TARGET }}

Diff for: .github/workflows/release-go-task.yml

+13-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ env:
88
DIST_DIR: dist
99
# The project's folder on Arduino's download server for uploading builds
1010
AWS_PLUGIN_TARGET: /arduino-language-server/
11+
AWS_REGION: "us-east-1"
1112
ARTIFACT_PREFIX: dist-
1213

1314
on:
@@ -189,7 +190,11 @@ jobs:
189190

190191
create-release:
191192
runs-on: ubuntu-latest
193+
environment: production
192194
needs: notarize-macos
195+
permissions:
196+
contents: write
197+
id-token: write # This is required for requesting the JWT
193198

194199
steps:
195200
- name: Download artifact
@@ -233,12 +238,12 @@ jobs:
233238
# (all the files we need are in the DIST_DIR root)
234239
artifacts: ${{ env.DIST_DIR }}/*
235240

241+
- name: configure aws credentials
242+
uses: aws-actions/configure-aws-credentials@v4
243+
with:
244+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
245+
role-session-name: "github_${{ env.PROJECT_NAME }}"
246+
aws-region: ${{ env.AWS_REGION }}
247+
236248
- name: Upload release files on Arduino downloads servers
237-
uses: docker://plugins/s3
238-
env:
239-
PLUGIN_SOURCE: "${{ env.DIST_DIR }}/*"
240-
PLUGIN_TARGET: ${{ env.AWS_PLUGIN_TARGET }}
241-
PLUGIN_STRIP_PREFIX: "${{ env.DIST_DIR }}/"
242-
PLUGIN_BUCKET: ${{ secrets.DOWNLOADS_BUCKET }}
243-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
244-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
249+
run: aws s3 sync ${{ env.DIST_DIR }} s3://${{ secrets.DOWNLOADS_BUCKET }}${{ env.AWS_PLUGIN_TARGET }}

0 commit comments

Comments
 (0)