-
Notifications
You must be signed in to change notification settings - Fork 6.5k
181 lines (157 loc) · 8.23 KB
/
pull-request.yml
File metadata and controls
181 lines (157 loc) · 8.23 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# Security Notes
# Only selected Actions are allowed within this repository. Please refer to (https://github.com/nodejs/nodejs.org/settings/actions)
# for the full list of available actions. If you want to add a new one, please reach out a maintainer with Admin permissions.
# REVIEWERS, please always double-check security practices before merging a PR that contains Workflow changes!!
# AUTHORS, please only use actions with explicit SHA references, and avoid using `@master` or `@main` references or `@version` tags.
name: Pull Request Checks
on:
pull_request:
merge_group:
defaults:
run:
# This ensures that the working directory is the root of the repository
working-directory: ./
permissions:
contents: read
actions: read
jobs:
base:
name: Base Tasks
runs-on: ubuntu-latest
outputs:
fetch_depth: ${{ steps.calculate_current_commits.outputs.fetch_depth }}
turbo_args: ${{ steps.turborepo_arguments.outputs.turbo_args }}
steps:
- name: Calculate Commits to Checkout
id: calculate_current_commits
# This calculates the amount of commits we should fetch during our shallow clone
# This calculates the amount of commits this PR produced diverged from the base branch + 1
# Which should include the "merge" commit reference
# In other words, the GitHub Action will always have the full history of the current PR
# We need all the commits of the PR so that `turbo --filter` works correctly
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "fetch_depth=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "$GITHUB_OUTPUT"
else
echo "fetch_depth=1" >> "$GITHUB_OUTPUT"
fi
- name: Provide Turborepo Arguments
id: turborepo_arguments
# `--filter` flag allows us to tell TurboRepo to only run a said command if there were any changes found in a given --filter range
# It verifies if any change was done to any of the including `glob` patterns described for a said command on `turbo.json`
# By default in this Workflow we use the `...[$TURBO_REF_FILTER]` as a value to the filter flag which tells Turborepo to look changes
# between the latest base branch commit and all the commits of this PR; That's why we use the `pull_request.base.sha` as a ref to the last
# commit on the base branch that this pull_request refers to.
# We also set the Turborepo Cache to the `.turbo` folder
# See https://turbo.build/repo/docs/reference/command-line-reference/run#--filter
# See https://turbo.build/repo/docs/reference/command-line-reference/run#--cache-dir
# See https://turbo.build/repo/docs/reference/command-line-reference/run#--force
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "turbo_args=--filter=\"[HEAD~${{ github.event.pull_request.commits }}...HEAD]\" --cache-dir=.turbo/cache" >> "$GITHUB_OUTPUT"
else
echo "turbo_args=--cache-dir=.turbo/cache" >> "$GITHUB_OUTPUT"
fi
lint:
name: Lint
runs-on: ubuntu-latest
needs: [base]
steps:
- name: Git Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
with:
# Here we apply the Environment Variable created above on the "Calculate Commits to Checkout"
fetch-depth: ${{ needs.base.outputs.fetch_depth }}
- name: Restore Lint Cache
uses: actions/cache/restore@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8
with:
path: |
.turbo/cache
node_modules/.cache
# We want to restore Turborepo Cache and ESlint and Prettier Cache
key: cache-lint-${{ hashFiles('package-lock.json') }}-
restore-keys: |
cache-lint-${{ hashFiles('package-lock.json') }}-
cache-lint-
- name: Set up Node.js
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8
with:
# We want to ensure that the Node.js version running here respects our supported versions
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install NPM packages
# We want to avoid NPM from running the Audit Step and Funding messages on a CI environment
# We also use `npm i` instead of `npm ci` so that the node_modules/.cache folder doesn't get deleted
run: npm i --no-audit --no-fund --ignore-scripts --userconfig=/dev/null
- name: Run `turbo lint`
# We want to enforce that the actual `turbo@latest` package is used instead of a possible hijack from the user
# the `${{ needs.base.outputs.turbo_args }}` is a string substitution happening from the base job
run: npx --package=turbo@latest -- turbo lint ${{ needs.base.outputs.turbo_args }}
- name: Run `turbo prettier`
# We want to enforce that the actual `turbo@latest` package is used instead of a possible hijack from the user
# the `${{ needs.base.outputs.turbo_args }}` is a string substitution happening from the base job
run: npx --package=turbo@latest -- turbo prettier ${{ needs.base.outputs.turbo_args }}
- name: Save Lint Cache
if: github.event_name == 'pull_request'
uses: actions/cache/save@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8
with:
path: |
.turbo/cache
node_modules/.cache
key: cache-lint-${{ hashFiles('package-lock.json') }}-${{ hashFiles('.turbo/cache/**') }}
tests:
name: Tests
runs-on: ubuntu-latest
needs: [base]
steps:
- name: Git Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
with:
# Here we apply the Environment Variable created above on the "Calculate Commits to Checkout"
fetch-depth: ${{ needs.base.outputs.fetch_depth }}
- name: Restore Tests Cache
uses: actions/cache/restore@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8
with:
path: |
.turbo/cache
node_modules/.cache
# We want to restore Turborepo Cache and Storybook Cache
key: cache-tests-${{ hashFiles('package-lock.json') }}-
restore-keys: |
cache-tests-${{ hashFiles('package-lock.json') }}-
cache-tests-
- name: Set up Node.js
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8
with:
# We want to ensure that the Node.js version running here respects our supported versions
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install NPM packages
# We want to avoid NPM from running the Audit Step and Funding messages on a CI environment
# We also use `npm i` instead of `npm ci` so that the node_modules/.cache folder doesn't get deleted
run: npm i --no-audit --no-fund --userconfig=/dev/null
- name: Run Unit Tests
# We want to enforce that the actual `turbo@latest` package is used instead of a possible hijack from the user
# the `${{ needs.base.outputs.turbo_args }}` is a string substitution happening from the base job
run: npx --package=turbo@latest -- turbo test:unit ${{ needs.base.outputs.turbo_args }} -- --ci --coverage
- name: Upload Coverage Report
if: github.event_name == 'pull_request'
# We upload the Coverage Report so it can be used on another Workflow
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce
with:
name: coverage-report
path: |
coverage/
junit.xml
- name: Run Storybook Tests
# We want to enforce that the actual `turbo@latest` package is used instead of a possible hijack from the user
# the `${{ needs.base.outputs.turbo_args }}` is a string substitution happening from the base job
run: npx --package=turbo@latest -- turbo test:storybook:local ${{ needs.base.outputs.turbo_args }} -- --ci
- name: Save Tests Cache
if: github.event_name == 'pull_request'
uses: actions/cache/save@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8
with:
path: |
.turbo/cache
node_modules/.cache
key: cache-tests-${{ hashFiles('package-lock.json') }}-${{ hashFiles('.turbo/cache/**') }}