Skip to content

Commit c3fb761

Browse files
committed
ci: adds workflows for pull requests, publishing package, and deprecating or re-indexing a published version
1 parent 95f10b3 commit c3fb761

File tree

4 files changed

+155
-0
lines changed

4 files changed

+155
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Publish to crate.io
2+
3+
on:
4+
workflow_dispatch:
5+
6+
env:
7+
CARGO_TERM_COLOR: always
8+
9+
jobs:
10+
run-test-workflow:
11+
uses: ./.github/workflows/on-pull-request.yml
12+
13+
publish:
14+
name: Publish to crate.io
15+
needs: run-test-workflow
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: dtolnay/rust-toolchain@stable
20+
21+
- uses: katyo/publish-crates@v2
22+
with:
23+
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
24+
25+
tag-and-release:
26+
name: Tag and Release
27+
needs: publish
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
34+
- name: Get version
35+
run: echo "VERSION=$(cat Cargo.toml | grep version | head -n1 | cut -d '"' -f2)" >> "$GITHUB_ENV"
36+
37+
- uses: rickstaa/action-create-tag@v1
38+
id: tag_create
39+
with:
40+
tag: v${{ env.VERSION }}
41+
42+
- name: Check if release is needed
43+
id: check
44+
run: |
45+
last_version=$(git describe --tags --abbrev=0)
46+
if [[ "$VERSION" == "$last_version" ]]; then
47+
# no release needed
48+
echo "create_release=false" >> "$GITHUB_OUTPUT"
49+
else
50+
echo "create_release=true" >> "$GITHUB_OUTPUT"
51+
fi
52+
53+
- name: Create Release
54+
if: steps.check.outputs.create_release == 'true'
55+
uses: actions/create-release@v1
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
with:
59+
tag_name: v${{ env.VERSION }}
60+
release_name: v${{ env.VERSION }}

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Run build and tests
2+
on:
3+
workflow_call:
4+
workflow_dispatch:
5+
pull_request:
6+
7+
env:
8+
CARGO_TERM_COLOR: always
9+
10+
jobs:
11+
lint-format:
12+
name: Lint and Format
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: dtolnay/rust-toolchain@stable
17+
18+
- name: Install clippy
19+
run: rustup component add clippy
20+
- name: Check linting
21+
run: cargo clippy --all-targets --all-features -- -D warnings
22+
23+
- name: Install rustfmt
24+
run: rustup component add rustfmt
25+
- name: Check formatting
26+
run: cargo fmt --all -- --check
27+
28+
build-and-test:
29+
name: Build and Test
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
- uses: dtolnay/rust-toolchain@stable
34+
35+
- name: Build
36+
run: cargo build --release --verbose
37+
- name: Test
38+
run: cargo test --release --no-fail-fast --verbose
39+
40+
publish-check:
41+
name: Publish Check
42+
needs:
43+
- lint-format
44+
- build-and-test
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@v4
48+
- uses: dtolnay/rust-toolchain@stable
49+
- uses: katyo/publish-crates@v2
50+
with:
51+
dry-run: true

.github/workflows/un-yank.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Undo a Yank of a published version from crate.io
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: The version number you wish to un-yank from crate.io
8+
required: true
9+
type: string
10+
11+
env:
12+
CARGO_TERM_COLOR: always
13+
14+
jobs:
15+
yank:
16+
name: Undo a Yank of a published version from crate.io
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: dtolnay/rust-toolchain@stable
20+
- name: Yank
21+
if: github.event.inputs.version != ''
22+
run: cargo yank --version ${{ github.event.inputs.version }} --token ${{ secrets.CARGO_REGISTRY_TOKEN }}

.github/workflows/yank.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Yank a published version from crate.io
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: The version number you wish to yank from crate.io
8+
required: true
9+
type: string
10+
11+
env:
12+
CARGO_TERM_COLOR: always
13+
14+
jobs:
15+
yank:
16+
name: Yank a published version from crate.io
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: dtolnay/rust-toolchain@stable
20+
- name: Yank
21+
if: github.event.inputs.version != ''
22+
run: cargo yank ${{ github.event.inputs.version }} --token ${{ secrets.CARGO_REGISTRY_TOKEN }}

0 commit comments

Comments
 (0)