Skip to content

Commit 30cc3de

Browse files
committed
Release SpiderMonkey build artifacts when landing PRs updating SpiderMonkey
This is a lot of yaml code to automate releasing of pre-built SpiderMonkey libraries for all build configs whenever the version of SpiderMonkey used is changed. These releases are done on merge to `main`, and will be picked up automatically by StarlingMonkey's build system.
1 parent fddc853 commit 30cc3de

File tree

2 files changed

+74
-15
lines changed

2 files changed

+74
-15
lines changed

.github/workflows/main.yml

Lines changed: 72 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,44 @@ jobs:
2626
matrix:
2727
build: [release, debug]
2828
os: [ubuntu-latest]
29+
outputs:
30+
SM_TAG_EXISTS: ${{ steps.check-sm-release.outputs.SM_TAG_EXISTS }}
31+
SM_TAG: ${{ steps.check-sm-release.outputs.SM_TAG }}
32+
SM_CACHE_KEY_debug: ${{ steps.check-sm-release.outputs.SM_CACHE_KEY_debug }}
33+
SM_CACHE_KEY_release: ${{ steps.check-sm-release.outputs.SM_CACHE_KEY_release }}
2934
runs-on: ${{ matrix.os }}
3035
steps:
3136
- uses: actions/checkout@v2
3237

33-
- name: Install Rust 1.88.0
38+
- name: Check if SpiderMonkey Release Exists
39+
id: check-sm-release
3440
run: |
35-
rustup toolchain install 1.88.0
36-
rustup target add wasm32-wasip1 --toolchain 1.88.0
41+
SM_TAG="libspidermonkey_$(awk '/^set\(SM_TAG/ {gsub(/set\(SM_TAG |\)/, ""); print}' cmake/spidermonkey.cmake)"
42+
echo "SM_TAG=${SM_TAG}" >> "$GITHUB_OUTPUT"
43+
if gh release view "${SM_TAG}" >/dev/null 2>&1; then
44+
echo "Found existing SpiderMonkey release tag: ${SM_TAG}"
45+
echo "SM_TAG_EXISTS=true" >> "$GITHUB_OUTPUT"
46+
else
47+
echo "SM_TAG_EXISTS=false" >> "$GITHUB_OUTPUT"
48+
echo "SM_CACHE_KEY_${{ matrix.build }}=spidermonkey-cache-${{ matrix.build }}-${{ hashFiles('cmake/spidermonkey.cmake') }}" >> "$GITHUB_OUTPUT"
49+
fi
50+
env:
51+
GH_TOKEN: ${{ github.token }}
3752

3853
- name: Cache SpiderMonkey tarball
54+
if: steps.check-sm-release.outputs.SM_TAG_EXISTS == 'false'
3955
uses: actions/cache@v4
4056
id: sm-cache
4157
with:
4258
path: |
43-
spidermonkey-dist
59+
spidermonkey-dist-${{ matrix.build }}
4460
key: spidermonkey-cache-${{ matrix.build }}-${{ hashFiles('cmake/spidermonkey.cmake') }}
4561

4662
- name: Set env var to use cached SpiderMonkey tarball
47-
if: steps.sm-cache.outputs.cache-hit == 'true'
63+
if: steps.check-sm-release.outputs.SM_TAG_EXISTS == 'false' && steps.sm-cache.outputs.cache-hit == 'true'
4864
run: |
49-
tree spidermonkey-dist
50-
echo "SPIDERMONKEY_BINARIES=$(pwd)/spidermonkey-dist" >> $GITHUB_ENV
65+
tree spidermonkey-dist-${{ matrix.build }}
66+
echo "SPIDERMONKEY_BINARIES=$(pwd)/spidermonkey-dist-${{ matrix.build }}" >> $GITHUB_ENV
5167
5268
- uses: actions/setup-node@v2
5369
with:
@@ -80,19 +96,61 @@ jobs:
8096
CTEST_OUTPUT_ON_FAILURE=1 ctest --test-dir cmake-build-${{ matrix.build }} -j$(nproc) --verbose
8197
8298
- name: Set up cacheable SpiderMonkey artifacts
83-
if: steps.sm-cache.outputs.cache-hit != 'true'
99+
if: steps.check-sm-release.outputs.SM_TAG_EXISTS == 'false' && steps.sm-cache.outputs.cache-hit != 'true'
84100
run: |
85-
mkdir -p spidermonkey-dist
86-
cp -a cmake-build-${{ matrix.build }}/spidermonkey-obj/dist/libspidermonkey.a spidermonkey-dist/
87-
cp -aL cmake-build-${{ matrix.build }}/spidermonkey-obj/dist/include spidermonkey-dist/
88-
tree spidermonkey-dist
101+
mkdir -p spidermonkey-dist-${{ matrix.build }}
102+
cp -a cmake-build-${{ matrix.build }}/spidermonkey-obj/dist/libspidermonkey.a spidermonkey-dist-${{ matrix.build }}/
103+
cp -aL cmake-build-${{ matrix.build }}/spidermonkey-obj/dist/include spidermonkey-dist-${{ matrix.build }}/
104+
tree spidermonkey-dist-${{ matrix.build }}
89105
90106
# Upload tarball as an artifact of the github action run, so the output
91107
# can be inspected for pull requests.
92108
- name: Upload SpiderMonkey tarball
93109
uses: actions/upload-artifact@v4
94110
if: (github.event_name != 'push' || (github.ref != 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/v')))
95-
&& steps.sm-cache.outputs.cache-hit != 'true'
111+
&& steps.check-sm-release.outputs.SM_TAG_EXISTS == 'false' && steps.sm-cache.outputs.cache-hit != 'true'
96112
with:
97113
name: spidermonkey-${{ matrix.build }}
98-
path: spidermonkey-dist/*
114+
path: spidermonkey-dist-${{ matrix.build }}/*
115+
116+
release-spidermonkey:
117+
needs: test
118+
if: needs.test.outputs.SM_TAG_EXISTS == 'false' && (github.event_name == 'push' &&
119+
(github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')))
120+
runs-on: ubuntu-latest
121+
permissions:
122+
contents: write
123+
steps:
124+
- name: Restore SpiderMonkey Debug Cache
125+
uses: actions/cache/restore@v4
126+
id: sm-cache-debug
127+
with:
128+
path: |
129+
spidermonkey-dist-debug
130+
key: ${{ needs.test.outputs.SM_CACHE_KEY_debug }}
131+
fail-on-cache-miss: true
132+
- name: Restore SpiderMonkey Release Cache
133+
uses: actions/cache/restore@v4
134+
id: sm-cache-release
135+
with:
136+
path: |
137+
spidermonkey-dist-release
138+
key: ${{ needs.test.outputs.SM_CACHE_KEY_release }}
139+
fail-on-cache-miss: true
140+
141+
- name: Create SpiderMonkey Tar Balls
142+
run: |
143+
mkdir -p release-artifacts
144+
tar -a -cf release-artifacts/spidermonkey-static-debug.tar.gz spidermonkey-dist-debug/*
145+
tar -a -cf release-artifacts/spidermonkey-static-release.tar.gz spidermonkey-dist-release/*
146+
tree release-artifacts
147+
148+
- name: Do the Release
149+
uses: softprops/action-gh-release@72f2c25fcb47643c292f7107632f7a47c1df5cd8 #2.3.2
150+
with:
151+
body: |
152+
This release contains pre-built SpiderMonkey artifacts to be used by the StarlingMonkey
153+
build system. It's not meant for general public consumption and doesn't come with any
154+
stability or availability guarantees.
155+
tag_name: ${{ needs.test.outputs.SM_TAG }}
156+
files: release-artifacts/*

cmake/spidermonkey.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ if (DEFINED ENV{SPIDERMONKEY_BINARIES})
2525
message(STATUS "Using pre-built SpiderMonkey artifacts from local directory ${SM_LIB_DIR}")
2626
else()
2727
set(SM_URL https://github.com/bytecodealliance/starlingmonkey/releases/download/libspidermonkey_${SM_TAG}/spidermonkey-static-${SM_BUILD_TYPE}.tar.gz)
28+
message(STATUS "Checking for pre-built SpiderMonkey artifacts at ${SM_URL}")
2829
execute_process(
29-
COMMAND curl -s -o /dev/null -w "%{http_code}" ${SM_URL}
30+
COMMAND curl -sIL -o /dev/null -w "%{http_code}" ${SM_URL}
3031
RESULT_VARIABLE CURL_RESULT
3132
OUTPUT_VARIABLE HTTP_STATUS
3233
)

0 commit comments

Comments
 (0)