Skip to content

Commit 02cf0c2

Browse files
authored
Merge pull request #496 from scratchfoundation/version-before-build
fix(ci): build with new version before testing and publishing
2 parents 80bbfc4 + f330580 commit 02cf0c2

8 files changed

Lines changed: 220 additions & 200 deletions

File tree

.github/workflows/ci.yml

Lines changed: 16 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
with:
3535
cache: 'npm'
3636
node-version-file: '.nvmrc'
37-
- name: Debug info
37+
- name: Debug Info
3838
# https://docs.github.com/en/actions/reference/security/secure-use#use-an-intermediate-environment-variable
3939
env:
4040
# `env:` values are printed to the log even without using them in `run:`
@@ -54,7 +54,7 @@ jobs:
5454
with:
5555
filters: ./.github/path-filters.yml
5656

57-
- name: Resolve changed packages
57+
- name: Resolve Changed Packages
5858
id: filter
5959
run: |
6060
if [ "${{ inputs.force-full-build }}" = "true" ]; then
@@ -70,14 +70,12 @@ jobs:
7070
- if: ${{ steps.filter.outputs.any-workspace == 'true' }}
7171
uses: ./.github/actions/install-dependencies
7272

73-
# IMPORTANT: always build all packages or none - never a subset.
74-
# The publish workflow reuses these artifacts, so partial artifacts would cause publish
75-
# failures for omitted packages.
76-
- name: Build packages
73+
# TODO: Packages currently depend on each other's compiled dist at build time. Fix that and matrix the builds.
74+
- name: Build Packages
7775
if: ${{ steps.filter.outputs.any-workspace == 'true' }}
7876
run: npm run build
7977

80-
- name: Store build artifacts
78+
- name: Store Build Artifacts
8179
if: ${{ steps.filter.outputs.any-workspace == 'true' }}
8280
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5
8381
with:
@@ -89,36 +87,15 @@ jobs:
8987
packages/**/playground
9088
9189
test:
92-
runs-on: ubuntu-latest
90+
name: Test
9391
needs: build
9492
if: ${{ needs.build.outputs.any-workspace == 'true' && needs.build.outputs.packages != '[]' }}
95-
permissions:
96-
checks: write
97-
pull-requests: write
98-
contents: read
99-
issues: read
100-
strategy:
101-
fail-fast: false
102-
matrix:
103-
package: ${{ fromJSON(needs.build.outputs.packages) }}
104-
name: Test ${{ matrix.package }}
105-
steps:
106-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
107-
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6
108-
with:
109-
cache: 'npm'
110-
node-version-file: '.nvmrc'
111-
- uses: ./.github/actions/install-dependencies
112-
- uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6
113-
with:
114-
name: build
115-
path: packages
116-
- uses: ./.github/actions/test-package
117-
with:
118-
package_name: ${{ matrix.package }}
93+
uses: ./.github/workflows/test-packages.yml
94+
with:
95+
packages: ${{ needs.build.outputs.packages }}
11996

12097
preview:
121-
runs-on: ubuntu-latest
98+
name: Preview
12299
needs: build
123100
# We don't want to give forks free reign to publish to our GitHub Pages, so run this job only if both:
124101
# - any workspace changed (otherwise there's no work to do)
@@ -135,68 +112,9 @@ jobs:
135112
) &&
136113
(!startsWith((github.head_ref || github.ref_name), 'renovate/'))
137114
}}
138-
name: Publish preview playgrounds to GitHub Pages
139-
steps:
140-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
141-
with:
142-
sparse-checkout: .github/actions/deploy-pages-with-retry/
143-
fetch-depth: 1
144-
sparse-checkout-cone-mode: true
145-
persist-credentials: false
146-
lfs: false
147-
submodules: false
148-
- name: Determine GitHub Pages directory name
149-
id: branch_dir_name
150-
# even `develop` should be published to a subdirectory
151-
# that way each branch can be updated or cleaned up independently
152-
run: |
153-
echo "result=${GITHUB_REF_NAME//[^A-Za-z0-9._-]/_}" | tee --append "$GITHUB_OUTPUT"
154-
- uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6
155-
with:
156-
name: build
157-
path: packages
158-
- name: Prepare playgrounds for GitHub Pages
159-
working-directory: ./packages
160-
run: |
161-
mkdir -p ../pages/
162-
for pkg in *; do
163-
if [ -d "${pkg}/playground" ]; then
164-
# using symlinks is quick and artifact generation will dereference them
165-
# if the GitHub Pages action stops dereferencing these links, we'll need to copy the files instead
166-
ln -s "../packages/${pkg}/playground" "../pages/${pkg}"
167-
fi
168-
done
169-
170-
# scratch-gui doesn't follow the pattern above
171-
ln -s "../packages/scratch-gui/build" "../pages/scratch-gui"
172-
173-
ls -l ../pages/
174-
- name: Deploy playgrounds to GitHub Pages
175-
uses: ./.github/actions/deploy-pages-with-retry
176-
with:
177-
github_token: ${{ secrets.GITHUB_TOKEN }}
178-
publish_dir: ./pages
179-
destination_dir: "${{steps.branch_dir_name.outputs.result}}"
180-
full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}"
181-
182-
results:
183-
name: Test Results
184-
runs-on: ubuntu-latest
185-
needs: test
186-
if: ${{ !cancelled() && needs.test.result != 'skipped' }}
187-
steps:
188-
- run: |
189-
case "${{ needs.test.result }}" in
190-
success)
191-
echo "Tests passed successfully."
192-
exit 0
193-
;;
194-
cancelled)
195-
echo "Tests were cancelled."
196-
exit 1
197-
;;
198-
*)
199-
echo "Tests failed. Result: ${{ needs.test.result }}"
200-
exit 1
201-
;;
202-
esac
115+
uses: ./.github/workflows/deploy-playground-preview.yml
116+
with:
117+
# even `develop` should be published to a subdirectory
118+
# that way each branch can be updated or cleaned up independently
119+
destination_dir: ${{ github.head_ref || github.ref_name }}
120+
full_commit_message: "Build for ${{ github.sha }} ${{ github.event.head_commit.message }}"

.github/workflows/commitlint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Lint commit messages
1+
name: Lint Commit Messages
22
on: [pull_request]
33

44
concurrency:
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Deploy Playground Preview
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
destination_dir:
7+
description: 'Destination subdirectory for GitHub Pages (will be sanitized)'
8+
type: string
9+
required: true
10+
full_commit_message:
11+
description: 'Commit message for the GitHub Pages deployment'
12+
type: string
13+
required: true
14+
15+
jobs:
16+
preview:
17+
runs-on: ubuntu-latest
18+
name: Publish Preview Playgrounds to GitHub Pages
19+
steps:
20+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
21+
with:
22+
sparse-checkout: .github/actions/deploy-pages-with-retry/
23+
fetch-depth: 1
24+
sparse-checkout-cone-mode: true
25+
persist-credentials: false
26+
lfs: false
27+
submodules: false
28+
- name: Sanitize Destination Directory Name
29+
id: dir
30+
env:
31+
DESTINATION_DIR: ${{ inputs.destination_dir }}
32+
run: |
33+
echo "result=${DESTINATION_DIR//[^A-Za-z0-9._-]/_}" | tee --append "$GITHUB_OUTPUT"
34+
- uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6
35+
with:
36+
name: build
37+
path: packages
38+
- name: Prepare Playgrounds for GitHub Pages
39+
working-directory: ./packages
40+
run: |
41+
mkdir -p ../pages/
42+
for pkg in *; do
43+
if [ -d "${pkg}/playground" ]; then
44+
# using symlinks is quick and artifact generation will dereference them
45+
# if the GitHub Pages action stops dereferencing these links, we'll need to copy the files instead
46+
ln -s "../packages/${pkg}/playground" "../pages/${pkg}"
47+
fi
48+
done
49+
50+
# scratch-gui doesn't follow the pattern above
51+
ln -s "../packages/scratch-gui/build" "../pages/scratch-gui"
52+
53+
ls -l ../pages/
54+
- name: Deploy Playgrounds to GitHub Pages
55+
uses: ./.github/actions/deploy-pages-with-retry
56+
with:
57+
github_token: ${{ secrets.GITHUB_TOKEN }}
58+
publish_dir: ./pages
59+
destination_dir: "${{ steps.dir.outputs.result }}"
60+
full_commit_message: "${{ inputs.full_commit_message }}"

.github/workflows/gha-debug.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: GitHub Actions debug info
1+
name: GitHub Actions Debug Info
22

33
on:
44
branch_protection_rule:
@@ -41,7 +41,7 @@ jobs:
4141
info:
4242
runs-on: ubuntu-latest
4343
steps:
44-
- name: Output debug info
44+
- name: Output Debug Info
4545
env:
4646
github: ${{ toJson(github) }}
4747
run: |

.github/workflows/ghpages-cleanup.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ jobs:
1515
contents: write
1616
runs-on: ubuntu-latest
1717
steps:
18-
- name: Check out GitHub Pages branch
18+
- name: Check Out GitHub Pages Branch
1919
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
2020
with:
2121
# replace `fetch-depth` with `shallow-since` if and when actions/checkout#619 (or an equivalent) gets merged
2222
# then remove the "Fetch a bit more history" step below
2323
fetch-depth: 1
2424
ref: gh-pages
25-
- name: Fetch a bit more history
25+
- name: Fetch a Bit More History
2626
run: git fetch --update-shallow --shallow-since="32 days ago" origin gh-pages
27-
- name: Mark stale directories for removal
27+
- name: Mark Stale Directories for Removal
2828
run: |
2929
for dir in */; do
3030
[ -L "${dir%/}" ] && continue # skip symlinks (trim trailing slash for test)
@@ -33,7 +33,7 @@ jobs:
3333
git rm --quiet -r "$dir"
3434
fi
3535
done
36-
- name: Configure git user
36+
- name: Configure Git User
3737
run: |
3838
git config user.name 'github-actions[bot]'
3939
git config user.email 'github-actions[bot]@users.noreply.github.com'

0 commit comments

Comments
 (0)