Skip to content

Commit 3a8d6bf

Browse files
Merge pull request #46 from BitGo/BTC-0.consolidate-workflows
feat(ci): refactor workflows using reusable workflow pattern
2 parents 126d4b9 + 454f855 commit 3a8d6bf

File tree

4 files changed

+144
-119
lines changed

4 files changed

+144
-119
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: "Build and Test (Reusable)"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
upload-artifacts:
7+
description: "Upload build artifacts"
8+
type: boolean
9+
default: false
10+
11+
jobs:
12+
run:
13+
name: "Test"
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
20+
21+
- name: Install Rust
22+
uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # v1
23+
with:
24+
toolchain: nightly-2025-10-23
25+
26+
- name: Cache Rust dependencies
27+
uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # v2.8.1
28+
with:
29+
workspaces: "packages/wasm-utxo"
30+
cache-on-failure: true
31+
32+
- name: Setup node 20
33+
uses: actions/setup-node@v4
34+
with:
35+
node-version: 20
36+
37+
- name: Ensure npm 11.5.1
38+
run: |
39+
npm install -g [email protected]
40+
41+
- name: Install wasm tools
42+
run: |
43+
rustup component add rustfmt
44+
cargo install wasm-pack --version 0.13.1
45+
cargo install wasm-opt --version 0.116.1
46+
cargo install cargo-deny --locked
47+
48+
- name: Build Info
49+
run: |
50+
echo "node $(node --version)"
51+
echo "npm $(npm --version)"
52+
echo "rustc $(rustc --version)"
53+
echo "wasm-pack $(wasm-pack --version)"
54+
echo "wasm-opt $(wasm-opt --version)"
55+
echo "cargo-deny $(cargo deny --version)"
56+
git --version
57+
echo "base ref $GITHUB_BASE_REF"
58+
echo "head ref $GITHUB_HEAD_REF"
59+
60+
- name: Fetch Base Ref
61+
if: github.event_name == 'pull_request'
62+
run: |
63+
git fetch origin $GITHUB_BASE_REF
64+
65+
- name: Install Packages
66+
run: npm ci --workspaces --include-workspace-root
67+
68+
- name: Check dependencies with cargo-deny
69+
run: cargo deny check
70+
working-directory: packages/wasm-utxo
71+
72+
- name: build packages
73+
run: npm --workspaces run build
74+
75+
- name: Check Source Code Formatting
76+
run: npm run check-fmt
77+
78+
- name: wasm-utxo / cargo test
79+
run: cargo test --workspace
80+
working-directory: packages/wasm-utxo
81+
82+
- name: wasm-utxo / Wasm-Pack Test (Node)
83+
run: npm run test:wasm-pack-node
84+
working-directory: packages/wasm-utxo
85+
86+
- name: wasm-utxo / Wasm-Pack Test (Chrome)
87+
run: npm run test:wasm-pack-chrome
88+
working-directory: packages/wasm-utxo
89+
90+
- name: Unit Test
91+
run: npm --workspaces test
92+
93+
- name: Upload build artifacts
94+
if: inputs.upload-artifacts
95+
uses: actions/upload-artifact@v4
96+
with:
97+
name: wasm-utxo-build
98+
path: |
99+
packages/wasm-utxo/pkg/
100+
packages/wasm-utxo/dist/
101+
retention-days: 1
102+

.github/workflows/ci.yaml

Lines changed: 3 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "test / Test"
1+
name: "Build and Test"
22

33
on:
44
push:
@@ -12,83 +12,5 @@ on:
1212
workflow_dispatch:
1313

1414
jobs:
15-
unit-test:
16-
name: "test / Test"
17-
18-
runs-on: ubuntu-latest
19-
20-
strategy:
21-
fail-fast: false
22-
23-
steps:
24-
- uses: actions/checkout@v4
25-
with:
26-
ref: ${{ github.event.pull_request.head.sha }}
27-
28-
- name: Install Rust
29-
uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # v1
30-
with:
31-
toolchain: nightly-2025-10-23
32-
33-
- name: Cache Rust dependencies
34-
uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # v2.8.1
35-
with:
36-
workspaces: "packages/wasm-utxo"
37-
cache-on-failure: true
38-
39-
- name: Setup node ${{ matrix.node-version }}
40-
uses: actions/setup-node@v3
41-
with:
42-
node-version: ${{ matrix.node-version }}
43-
44-
- name: Install wasm tools
45-
run: |
46-
rustup component add rustfmt
47-
cargo install wasm-pack --version 0.13.1
48-
cargo install wasm-opt --version 0.116.1
49-
cargo install cargo-deny --locked
50-
51-
- name: Build Info
52-
run: |
53-
echo "node $(node --version)"
54-
echo "npm $(npm --version)"
55-
echo "npx $(npx --version)"
56-
echo "rustc $(rustc --version)"
57-
echo "wasm-pack $(wasm-pack --version)"
58-
echo "wasm-opt $(wasm-opt --version)"
59-
echo "cargo-deny $(cargo deny --version)"
60-
git --version
61-
echo "base ref $GITHUB_BASE_REF"
62-
echo "head ref $GITHUB_HEAD_REF"
63-
64-
- name: Fetch Base Ref
65-
run: |
66-
git fetch origin $GITHUB_BASE_REF
67-
68-
- name: Install Packages
69-
run: npm ci --workspaces --include-workspace-root
70-
71-
- name: Check dependencies with cargo-deny
72-
run: cargo deny check
73-
working-directory: packages/wasm-utxo
74-
75-
- name: build packages
76-
run: npm --workspaces run build
77-
78-
- name: Check Source Code Formatting
79-
run: npm run check-fmt
80-
81-
- name: wasm-utxo / cargo test
82-
run: cargo test --workspace
83-
working-directory: packages/wasm-utxo
84-
85-
- name: wasm-utxo / Wasm-Pack Test (Node)
86-
run: npm run test:wasm-pack-node
87-
working-directory: packages/wasm-utxo
88-
89-
- name: wasm-utxo / Wasm-Pack Test (Chrome)
90-
run: npm run test:wasm-pack-chrome
91-
working-directory: packages/wasm-utxo
92-
93-
- name: Unit Test
94-
run: npm --workspaces test
15+
test:
16+
uses: ./.github/workflows/build-and-test.yaml

.github/workflows/publish.yaml

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ concurrency:
99
group: ${{ github.workflow }}-${{ github.ref }}
1010

1111
jobs:
12+
test:
13+
name: Test
14+
uses: ./.github/workflows/build-and-test.yaml
15+
with:
16+
upload-artifacts: true
17+
1218
publish:
1319
name: Publish Release
20+
needs: test
1421
runs-on: ubuntu-latest
1522
environment: publish
1623
permissions:
@@ -23,58 +30,27 @@ jobs:
2330
with:
2431
fetch-depth: 0
2532

33+
- name: Download build artifacts
34+
uses: actions/download-artifact@v4
35+
with:
36+
name: wasm-utxo-build
37+
path: packages/wasm-utxo/
38+
2639
- name: Setup Node
2740
uses: actions/setup-node@v4
2841
with:
2942
node-version: 20
3043
registry-url: https://registry.npmjs.org
3144

32-
- name: Ensure npm 11.5.1 or later for trusted publishing
45+
- name: Ensure npm 11.5.1
3346
run: |
3447
npm install -g [email protected]
3548
36-
- name: Install Rust
37-
uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # v1
38-
with:
39-
toolchain: nightly-2025-10-23
40-
41-
- name: Cache Rust dependencies
42-
uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # v2.8.1
43-
with:
44-
workspaces: "packages/wasm-utxo"
45-
cache-on-failure: true
46-
47-
- name: Install wasm tools
48-
run: |
49-
rustup component add rustfmt
50-
cargo install wasm-pack --version 0.13.1
51-
cargo install wasm-opt --version 0.116.1
52-
53-
- name: Build Info
54-
run: |
55-
echo "node $(node --version)"
56-
echo "npm $(npm --version)"
57-
echo "rustc $(rustc --version)"
58-
echo "wasm-pack $(wasm-pack --version)"
59-
echo "wasm-opt $(wasm-opt --version)"
60-
git --version
61-
echo "base ref $GITHUB_BASE_REF"
62-
echo "head ref $GITHUB_HEAD_REF"
63-
6449
- name: Configure Git
6550
run: |
6651
git config user.name "github-actions[bot]"
6752
git config user.email "github-actions[bot]@users.noreply.github.com"
6853
69-
- name: Install Packages
70-
run: npm ci --workspaces --include-workspace-root
71-
72-
- name: build packages
73-
run: npm --workspaces run build
74-
75-
- name: Unit Test
76-
run: npm --workspaces test
77-
7854
- name: Release (npm publish via OIDC)
7955
working-directory: packages/wasm-utxo
8056
run: npm publish
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This is a thin wrapper workflow that reflects the status of the "Build and Test" workflow.
2+
# It exists solely to provide a clean "test / Test" status check name in GitHub PR status checks,
3+
# avoiding the multi-level name composition that occurs with reusable workflows.
4+
# Configure branch protection rules to require "test / Test" as the status check.
5+
6+
name: "test / Test"
7+
8+
on:
9+
workflow_run:
10+
workflows: ["Build and Test"]
11+
types:
12+
- completed
13+
14+
jobs:
15+
status:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Check Build and Test Status
19+
run: |
20+
if [ "${{ github.event.workflow_run.conclusion }}" != "success" ]; then
21+
echo "Build and Test workflow failed"
22+
exit 1
23+
fi
24+
echo "Build and Test workflow succeeded"
25+

0 commit comments

Comments
 (0)