-
Notifications
You must be signed in to change notification settings - Fork 197
177 lines (165 loc) · 6.12 KB
/
ci.yml
File metadata and controls
177 lines (165 loc) · 6.12 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
name: CI
on:
merge_group:
pull_request:
push: # WARNING: Renovate sometimes automerges without PR, so we MUST build and test renovate/** branches
workflow_call:
workflow_dispatch:
concurrency:
group: "${{ github.workflow }} @ ${{ github.event.compare || github.head_ref || github.ref }}"
cancel-in-progress: true
jobs:
build:
name: Build
runs-on: ubuntu-latest
outputs:
any-workspace: ${{ steps.filter.outputs.any-workspace }}
packages: ${{ steps.filter.outputs.changes }}
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6
with:
cache: 'npm'
node-version-file: '.nvmrc'
- name: Debug info
# https://docs.github.com/en/actions/reference/security/secure-use#use-an-intermediate-environment-variable
env:
# `env:` values are printed to the log even without using them in `run:`
GH_CONTEXT: ${{ toJson(github) }}
run: |
cat <<EOF
Working directory: $(pwd)
Node version: $(node --version)
NPM version: $(npm --version)
Scratch environment: ${{ vars.SCRATCH_ENV || '<none>' }}
EOF
- uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4
id: filter
with:
filters: ./.github/path-filters.yml
- if: ${{ steps.filter.outputs.any-workspace == 'true' }}
uses: ./.github/actions/install-dependencies
- name: Build packages
if: ${{ steps.filter.outputs.any-workspace == 'true' }}
run: npm run build
- name: Store build artifacts
if: ${{ steps.filter.outputs.any-workspace == 'true' }}
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5
with:
name: build
path: |
packages/**/build
packages/**/dist
packages/**/playground
test:
runs-on: ubuntu-latest
needs: build
if: ${{ needs.build.outputs.any-workspace == 'true' }}
permissions:
checks: write
pull-requests: write
contents: read
issues: read
strategy:
fail-fast: false
matrix:
package: ${{ fromJSON(needs.build.outputs.packages) }}
exclude:
- package: global
- package: any-workspace
name: Test ${{ matrix.package }}
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6
with:
cache: 'npm'
node-version-file: '.nvmrc'
- uses: ./.github/actions/install-dependencies
- uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6
with:
name: build
path: packages
- uses: ./.github/actions/test-package
with:
package_name: ${{ matrix.package }}
preview:
runs-on: ubuntu-latest
needs: build
# We don't want to give forks free reign to publish to our GitHub Pages, so run this job only if both:
# - any workspace changed (otherwise there's no work to do)
# - and either
# - this is not a PR (so it's some other event that happened in our fork, like a push or merge group)
# - or it's a PR from our fork (not some other fork)
# - and
# - it's not a Renovate branch (just to reduce noise)
if: ${{
(needs.build.outputs.any-workspace == 'true') &&
(
(!github.event.pull_request) ||
(github.event.pull_request.head.repo.full_name == github.repository)
) &&
(!startsWith((github.head_ref || github.ref_name), 'renovate/'))
}}
name: Publish preview playgrounds to GitHub Pages
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
with:
sparse-checkout: .github/actions/deploy-pages-with-retry/
fetch-depth: 1
sparse-checkout-cone-mode: true
persist-credentials: false
lfs: false
submodules: false
- name: Determine GitHub Pages directory name
id: branch_dir_name
# even `develop` should be published to a subdirectory
# that way each branch can be updated or cleaned up independently
run: |
echo "result=${GITHUB_REF_NAME//[^A-Za-z0-9._-]/_}" | tee --append "$GITHUB_OUTPUT"
- uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6
with:
name: build
path: packages
- name: Prepare playgrounds for GitHub Pages
working-directory: ./packages
run: |
mkdir -p ../pages/
for pkg in *; do
if [ -d "${pkg}/playground" ]; then
# using symlinks is quick and artifact generation will dereference them
# if the GitHub Pages action stops dereferencing these links, we'll need to copy the files instead
ln -s "../packages/${pkg}/playground" "../pages/${pkg}"
fi
done
# scratch-gui doesn't follow the pattern above
ln -s "../packages/scratch-gui/build" "../pages/scratch-gui"
ls -l ../pages/
- name: Deploy playgrounds to GitHub Pages
uses: ./.github/actions/deploy-pages-with-retry
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./pages
destination_dir: "${{steps.branch_dir_name.outputs.result}}"
full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}"
results:
name: Test Results
runs-on: ubuntu-latest
needs: test
if: ${{ !cancelled() }}
steps:
- run: |
case "${{ needs.test.result }}" in
success)
echo "Tests passed successfully."
exit 0
;;
skipped)
echo "Tests were unnecessary for these changes, so they were skipped."
echo "If this is unexpected, check the path filters."
exit 0
;;
*)
echo "Tests failed."
exit 1
;;
esac