Skip to content

Commit 7a211be

Browse files
authored
Add workflow cron job to check for wasm-bindgen macro chagnes (#75)
Tests expand macro output. This changes a lot based on the version of wasm-bindgen that is installed. This cron job is meant to create a PR whenever there are changes to the expanded macro output. Since all PRs that affect tsify's macro output should update their own tests, this should only detect changes in other rust crates.
1 parent 63a1123 commit 7a211be

File tree

3 files changed

+92
-5
lines changed

3 files changed

+92
-5
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Check wasm-bindgen changes
2+
3+
# Tests expand macro output. This changes a lot based on the version of wasm-bindgen that is installed
4+
# This cron job is meant to create a PR whenever there are changes to the expanded macro output.
5+
# Since all PRs that affect tsify's macro output should update their own tests, this should only detect
6+
# changes in other rust crates.
7+
8+
on:
9+
schedule:
10+
- cron: "0 0 * * *" # every day at midnight GMT
11+
workflow_dispatch:
12+
13+
env:
14+
TARGET_BRANCH: ${{ github.event.pull_request.base.ref || github.ref_name }}
15+
16+
jobs:
17+
test:
18+
name: Create Test Artifacts
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout sources
23+
uses: actions/checkout@v6
24+
25+
- name: Setup Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: "24"
29+
30+
- name: Install toolchain
31+
uses: actions-rs/toolchain@v1
32+
with:
33+
profile: minimal
34+
toolchain: stable
35+
override: true
36+
components: rustfmt
37+
38+
- name: Install wasm-pack
39+
uses: jetli/wasm-pack-action@v0.4.0
40+
with:
41+
# specify exact version to work around
42+
# https://github.com/jetli/wasm-pack-action/issues/23
43+
version: v0.13.1
44+
45+
- name: Add cargo-expand
46+
run: cargo install cargo-expand
47+
48+
- name: Setup git config
49+
run: |
50+
git config user.name "${{ github.actor }} via GitHub Actions"
51+
git config user.email "${{ github.actor }}@github_actions.no_reply"
52+
git checkout -b update-expanded-test-artifacts
53+
# Ensure the branch exists on the remote
54+
git ls-remote --exit-code origin update-expanded-test-artifacts || {
55+
git push -u origin update-expanded-test-artifacts
56+
}
57+
# Fetch the branch from the remote
58+
git fetch origin update-expanded-test-artifacts
59+
git fetch origin ${{ env.TARGET_BRANCH }}
60+
git fetch origin main
61+
# Reset to the target branch to avoid conflicts with the existing branch
62+
git reset --hard origin/${{ env.TARGET_BRANCH }}
63+
git branch --set-upstream-to=origin/${{ env.TARGET_BRANCH }} update-expanded-test-artifacts
64+
env:
65+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
67+
# Run `MACROTEST=overwrite cargo test -p tsify --test expandtest` to rebuild the test artifacts with expanded macros.
68+
- name: Expand Macros
69+
run: cargo test -p tsify --test expandtest
70+
env:
71+
MACROTEST: overwrite
72+
73+
- name: Check for changes
74+
run: |
75+
git diff --quiet || {
76+
echo "Available branches:"
77+
git branch -a
78+
echo "Remote configuration:"
79+
git remote -v
80+
echo "Creating PR with changes..."
81+
git add tests
82+
git commit -m "Update expanded test artifacts"
83+
git push --force --set-upstream origin update-expanded-test-artifacts
84+
gh pr create --fill
85+
}
86+
env:
87+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/on-pull-request.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
steps:
1515
- name: Checkout sources
16-
uses: actions/checkout@v3
16+
uses: actions/checkout@v6
1717

1818
- name: Install toolchain
1919
uses: actions-rs/toolchain@v1
@@ -37,12 +37,12 @@ jobs:
3737

3838
steps:
3939
- name: Checkout sources
40-
uses: actions/checkout@v3
40+
uses: actions/checkout@v6
4141

4242
- name: Setup Node.js
4343
uses: actions/setup-node@v4
4444
with:
45-
node-version: '20'
45+
node-version: '24'
4646

4747
- name: Install toolchain
4848
uses: actions-rs/toolchain@v1
@@ -71,7 +71,7 @@ jobs:
7171

7272
steps:
7373
- name: Checkout sources
74-
uses: actions/checkout@v3
74+
uses: actions/checkout@v6
7575

7676
- name: Install toolchain
7777
uses: actions-rs/toolchain@v1

tests/expandtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Generates expanded code for tests in `tests/expand/` directory.
22
//! To update the expected output, run with `MACROTEST=overwrite cargo test`
3-
//! or delete the `.expanded.rs` files.
3+
//! or delete the `*.expanded.rs` files.
44
55
#[test]
66
fn expandtest() {

0 commit comments

Comments
 (0)