Skip to content

Commit 89f855d

Browse files
committed
Separate test and deploy jobs
So that we can provide secret tokens only to the `deploy` job, and have better isolation between building/testing and deploying.
1 parent aa2a8f9 commit 89f855d

File tree

1 file changed

+40
-15
lines changed

1 file changed

+40
-15
lines changed

.github/workflows/main.yml

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ on:
55
merge_group:
66

77
jobs:
8-
ci:
9-
name: CI
8+
test:
9+
name: Test
1010
runs-on: ubuntu-latest
1111
if: github.repository == 'rust-lang/team'
12-
permissions:
13-
id-token: write
14-
pages: write
1512
steps:
1613
- uses: actions/checkout@v4
1714
with:
@@ -53,23 +50,32 @@ jobs:
5350
run: echo "${{ github.event.pull_request.number }}" > build/pr.txt
5451

5552
- name: Upload the built JSON as a GitHub artifact
56-
if: ${{ github.event_name == 'pull_request' }}
5753
uses: actions/upload-artifact@v4
5854
with:
5955
name: team-api-output
6056
path: build
61-
62-
- name: Disable Jekyll
63-
run: touch build/.nojekyll
64-
65-
- name: Upload GitHub pages artifact
66-
uses: actions/upload-pages-artifact@v3
57+
deploy:
58+
name: Deploy
59+
needs: [ test ]
60+
runs-on: ubuntu-latest
61+
environment: deploy
62+
concurrency: deploy
63+
permissions:
64+
id-token: write
65+
if: github.event_name == 'merge_group'
66+
steps:
67+
- name: Download built JSON API
68+
uses: actions/download-artifact@v4
6769
with:
70+
name: team-api-output
6871
path: build
69-
7072
- name: Deploy to GitHub Pages
71-
if: github.event_name == 'merge_group'
72-
uses: actions/deploy-pages@v4
73+
run: |
74+
touch build/.nojekyll
75+
curl -LsSf https://raw.githubusercontent.com/rust-lang/simpleinfra/master/setup-deploy-keys/src/deploy.rs | rustc - -o /tmp/deploy
76+
(cd build && /tmp/deploy)
77+
env:
78+
GITHUB_DEPLOY_KEY: ${{ secrets.GITHUB_DEPLOY_KEY }}
7379

7480
- name: Configure AWS credentials
7581
if: github.event_name == 'merge_group'
@@ -85,3 +91,22 @@ jobs:
8591
sleep 60
8692
aws --region us-west-1 lambda invoke --function-name start-sync-team output.json
8793
cat output.json | python3 -m json.tool
94+
95+
# Summary job for the merge queue.
96+
# ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB!
97+
conclusion:
98+
needs: [ test, deploy ]
99+
# We need to ensure this job does *not* get skipped if its dependencies fail,
100+
# because a skipped job is considered a success by GitHub. So we have to
101+
# overwrite `if:`. We use `!cancelled()` to ensure the job does still not get run
102+
# when the workflow is canceled manually.
103+
if: ${{ !cancelled() }}
104+
runs-on: ubuntu-latest
105+
steps:
106+
# Manually check the status of all dependencies. `if: failure()` does not work.
107+
- name: Conclusion
108+
run: |
109+
# Print the dependent jobs to see them in the CI log
110+
jq -C <<< '${{ toJson(needs) }}'
111+
# Check if all jobs that we depend on (in the needs array) were successful.
112+
jq --exit-status 'all(.result == "success" or .result == "skipped")' <<< '${{ toJson(needs) }}'

0 commit comments

Comments
 (0)