-
Notifications
You must be signed in to change notification settings - Fork 4
83 lines (77 loc) · 2.67 KB
/
ci-build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: Format and Test
# Prevent formatting commit collisions when pushing code too fast.
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
on:
pull_request:
branches:
- main
jobs:
format:
name: Format code
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
head: ${{ steps.head.outputs.head }}
steps:
- uses: actions/checkout@v4
with:
# Check out the branch that the PR refers to, so the git HEAD isn't detached.
ref: ${{ github.event.pull_request.head.ref }}
- uses: actions/setup-node@v4
with:
node-version: 18
cache: yarn
- run: npx prettier --write .
- name: Push changes
run: |
if [ -n "$(git status --porcelain)" ]; then
# github-actions name and email derived from https://github.com/orgs/community/discussions/26560
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git commit -am "Automatic formatting"
git push
fi
- name: Get head SHA
id: head
run: echo "head=$(git rev-parse HEAD)" >>"$GITHUB_OUTPUT"
test:
name: Test deployment
runs-on: ubuntu-latest
permissions:
statuses: write
needs: [format]
steps:
- uses: actions/checkout@v4
with:
# Check out the HEAD from the previous workflow, to catch any mistakes that the formatter
# may have introduced.
ref: "${{ needs.format.outputs.head }}"
- uses: actions/setup-node@v4
with:
node-version: 18
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Test build website
run: yarn build
# The format job may have changed the PR's head. When the head is changed through a workflow
# another workflow is not kicked off to prevent infinite loops. Thus, the new head never
# receives its workflow status.
#
# Workaround this by setting a status check to the new head manually.
- name: Set status check
if: always()
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api \
repos/${{ github.repository }}/commits/${{ needs.format.outputs.head }}/statuses \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-f state="${{ job.status }}" \
-f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
-f context="Format and Test"