Skip to content

Commit dde39f6

Browse files
ci: add reusable workflows (#14)
1 parent bdaeb4e commit dde39f6

4 files changed

Lines changed: 271 additions & 0 deletions

File tree

.github/workflows/book.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Book
2+
3+
on:
4+
workflow_call:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
test:
11+
name: Test
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
17+
18+
- name: Set up Rust toolchain
19+
uses: actions-rust-lang/setup-rust-toolchain@2b1f5e9b395427c92ee4e3331786ca3c37afe2d7 # v1.16.0
20+
with:
21+
target: wasm32-unknown-unknown
22+
23+
- name: Install Cargo Binary Install
24+
uses: cargo-bins/cargo-binstall@dc19f1e48450eefe5a29b8da6c6b00a87d730b37 # v1.18.1
25+
26+
- name: Install mdBook
27+
run: cargo binstall --force -y mdbook mdbook-tabs mdbook-trunk
28+
29+
- name: Run tests
30+
run: mdbook test
31+
working-directory: book
32+
33+
build:
34+
name: Build
35+
needs: test
36+
runs-on: ubuntu-latest
37+
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
41+
with:
42+
fetch-depth: 0
43+
44+
- name: Set up Rust toolchain
45+
uses: actions-rust-lang/setup-rust-toolchain@2b1f5e9b395427c92ee4e3331786ca3c37afe2d7 # v1.16.0
46+
with:
47+
target: wasm32-unknown-unknown
48+
49+
- name: Install Cargo Binary Install
50+
uses: cargo-bins/cargo-binstall@dc19f1e48450eefe5a29b8da6c6b00a87d730b37 # v1.18.1
51+
52+
- name: Install mdBook and Trunk
53+
run: cargo binstall --force -y mdbook mdbook-tabs mdbook-trunk trunk
54+
55+
- name: Install Node.js dependencies
56+
run: npm ci
57+
58+
- name: Build Book
59+
run: mdbook build
60+
working-directory: book
61+
62+
- name: Combine Book Outputs
63+
run: mdbook-trunk combine
64+
working-directory: book
65+
66+
- name: Upload artifact
67+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
68+
with:
69+
name: book
70+
path: book/dist
71+
retention-days: 1
72+
if-no-files-found: error
73+
74+
deploy:
75+
name: Deploy
76+
needs: build
77+
if: github.ref == 'refs/heads/main'
78+
runs-on: ubuntu-latest
79+
80+
permissions:
81+
contents: read
82+
pages: write
83+
id-token: write
84+
85+
steps:
86+
- name: Checkout
87+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
88+
with:
89+
fetch-depth: 0
90+
91+
- name: Download artifacts
92+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
93+
with:
94+
path: dist
95+
merge-multiple: true
96+
97+
- name: Setup Pages
98+
uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0
99+
100+
- name: Upload artifact
101+
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
102+
with:
103+
path: dist
104+
105+
- name: Deploy to GitHub Pages
106+
id: deployment
107+
uses: actions/deploy-pages@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128 # v5.0.0

.github/workflows/labels.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Labels
2+
3+
on:
4+
workflow_call:
5+
6+
permissions:
7+
contents: read
8+
issues: write
9+
10+
jobs:
11+
sync-labels:
12+
name: Sync Labels
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
17+
with:
18+
sparse-checkout: .github/labels.yml
19+
20+
- name: Sync labels
21+
uses: EndBug/label-sync@52074158190acb45f3077f9099fea818aa43f97a # v2.3.3
22+
with:
23+
config-file: .github/labels.yml

.github/workflows/publish.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Publish
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
# Inputs for `actions-rust-lang/setup-rust-toolchain`.
7+
# https://github.com/actions-rust-lang/setup-rust-toolchain/blob/main/action.yml
8+
toolchain:
9+
description: 'Comma-separated list of Rust toolchain specifications. Last version becomes the default. -- see https://rust-lang.github.io/rustup/concepts/toolchains.html#toolchain-specification'
10+
type: string
11+
required: false
12+
target:
13+
description: 'Target triple to install for this toolchain'
14+
type: string
15+
required: false
16+
17+
permissions:
18+
contents: read
19+
id-token: write
20+
21+
jobs:
22+
publish:
23+
name: Publish
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
29+
30+
- name: Set up Rust toolchain
31+
uses: actions-rust-lang/setup-rust-toolchain@2b1f5e9b395427c92ee4e3331786ca3c37afe2d7 # v1.16.0
32+
with:
33+
toolchain: ${{ inputs.toolchain }}
34+
target: ${{ inputs.target }}
35+
36+
- name: Install Cargo Binary Install
37+
uses: cargo-bins/cargo-binstall@dc19f1e48450eefe5a29b8da6c6b00a87d730b37 # v1.18.1
38+
39+
- name: Install crates
40+
run: cargo binstall --force -y cargo-workspaces
41+
42+
- uses: rust-lang/crates-io-auth-action@bbd81622f20ce9e2dd9622e3218b975523e45bbe # v1.0.4
43+
id: auth
44+
45+
- name: Publish
46+
run: cargo workspaces publish --publish-as-is
47+
env:
48+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}

.github/workflows/release.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Release
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
bump:
7+
description: 'Bump version by semver keyword.'
8+
required: true
9+
type: string
10+
11+
# Inputs for `actions-rust-lang/setup-rust-toolchain`.
12+
# https://github.com/actions-rust-lang/setup-rust-toolchain/blob/main/action.yml
13+
toolchain:
14+
description: 'Comma-separated list of Rust toolchain specifications. Last version becomes the default. -- see https://rust-lang.github.io/rustup/concepts/toolchains.html#toolchain-specification'
15+
type: string
16+
required: false
17+
target:
18+
description: 'Target triple to install for this toolchain'
19+
type: string
20+
required: false
21+
22+
permissions:
23+
contents: write
24+
25+
jobs:
26+
release:
27+
name: Release
28+
runs-on: ubuntu-latest
29+
30+
steps:
31+
- name: Generate GitHub App token
32+
id: app-token
33+
uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
34+
with:
35+
client-id: ${{ secrets.APP_ID }}
36+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
37+
38+
- name: Checkout
39+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
40+
41+
- name: Set up Rust toolchain
42+
uses: actions-rust-lang/setup-rust-toolchain@2b1f5e9b395427c92ee4e3331786ca3c37afe2d7 # v1.16.0
43+
with:
44+
toolchain: ${{ inputs.toolchain }}
45+
target: ${{ inputs.target }}
46+
47+
- name: Install Cargo Binary Install
48+
uses: cargo-bins/cargo-binstall@dc19f1e48450eefe5a29b8da6c6b00a87d730b37 # v1.18.1
49+
50+
- name: Install crates
51+
run: cargo binstall --force -y cargo-workspaces toml-cli
52+
53+
- name: Bump version
54+
run: cargo workspaces version --all --no-git-commit --yes ${{ inputs.bump }}
55+
56+
- name: Extract version
57+
id: extract-version
58+
run: echo "VERSION=v$(toml get Cargo.toml workspace.package.version --raw)" >> "$GITHUB_OUTPUT"
59+
60+
- name: Add changes
61+
run: git add .
62+
63+
- name: Commit
64+
id: commit
65+
uses: dsanders11/github-app-commit-action@2bbcd331016d8c950b05a24b56e7eb9cb50d545e # v2.1.0
66+
with:
67+
message: ${{ steps.extract-version.outputs.VERSION }}
68+
token: ${{ steps.app-token.outputs.token }}
69+
70+
- name: Reset and pull
71+
run: git reset --hard && git pull
72+
73+
- name: Tag
74+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
75+
env:
76+
GIT_TAG: ${{ steps.extract-version.outputs.VERSION }}
77+
GIT_SHA: ${{ steps.commit.outputs.sha }}
78+
with:
79+
script: |
80+
github.rest.git.createRef({
81+
owner: context.repo.owner,
82+
repo: context.repo.repo,
83+
ref: `refs/tags/${process.env.GIT_TAG}`,
84+
sha: process.env.GIT_SHA
85+
})
86+
87+
- name: Release
88+
uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3.0.0
89+
with:
90+
generate_release_notes: true
91+
make_latest: true
92+
tag_name: ${{ steps.extract-version.outputs.VERSION }}
93+
token: ${{ steps.app-token.outputs.token }}

0 commit comments

Comments
 (0)