Skip to content

Commit e1cb948

Browse files
committed
ci: add cargo publish workflow
- Add publish.yml workflow triggered on version tags (v*) - Support manual workflow dispatch with dry-run option - Publish fetchkit library first, then fetchkit-cli - Run tests before publishing - Add version dependency to fetchkit-cli for crates.io compatibility
1 parent d61cebc commit e1cb948

2 files changed

Lines changed: 103 additions & 1 deletion

File tree

.github/workflows/publish.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Publish to crates.io
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v[0-9]+.[0-9]+.[0-9]+'
7+
- 'v[0-9]+.[0-9]+.[0-9]+-*'
8+
workflow_dispatch:
9+
inputs:
10+
dry_run:
11+
description: 'Dry run (no actual publish)'
12+
required: false
13+
default: 'true'
14+
type: boolean
15+
crate:
16+
description: 'Crate to publish (all, fetchkit, fetchkit-cli)'
17+
required: false
18+
default: 'all'
19+
type: choice
20+
options:
21+
- all
22+
- fetchkit
23+
- fetchkit-cli
24+
25+
permissions:
26+
contents: read
27+
28+
env:
29+
CARGO_TERM_COLOR: always
30+
RUST_BACKTRACE: 1
31+
32+
jobs:
33+
test:
34+
name: Test before publish
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v4
38+
- uses: dtolnay/rust-toolchain@stable
39+
- uses: Swatinem/rust-cache@v2
40+
- name: Run tests
41+
run: cargo test --workspace
42+
- name: Check formatting
43+
run: cargo fmt --all -- --check
44+
- name: Clippy
45+
run: cargo clippy --workspace --all-targets -- -D warnings
46+
47+
publish-fetchkit:
48+
name: Publish fetchkit
49+
needs: test
50+
runs-on: ubuntu-latest
51+
if: >-
52+
github.event_name == 'push' ||
53+
(github.event_name == 'workflow_dispatch' &&
54+
(github.event.inputs.crate == 'all' || github.event.inputs.crate == 'fetchkit'))
55+
steps:
56+
- uses: actions/checkout@v4
57+
- uses: dtolnay/rust-toolchain@stable
58+
- uses: Swatinem/rust-cache@v2
59+
60+
- name: Verify crate can be packaged
61+
run: cargo package -p fetchkit --allow-dirty
62+
63+
- name: Publish fetchkit (dry run)
64+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'true'
65+
run: cargo publish -p fetchkit --dry-run
66+
67+
- name: Publish fetchkit
68+
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'false')
69+
run: cargo publish -p fetchkit
70+
env:
71+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
72+
73+
publish-fetchkit-cli:
74+
name: Publish fetchkit-cli
75+
needs: [test, publish-fetchkit]
76+
runs-on: ubuntu-latest
77+
if: >-
78+
github.event_name == 'push' ||
79+
(github.event_name == 'workflow_dispatch' &&
80+
(github.event.inputs.crate == 'all' || github.event.inputs.crate == 'fetchkit-cli'))
81+
steps:
82+
- uses: actions/checkout@v4
83+
- uses: dtolnay/rust-toolchain@stable
84+
- uses: Swatinem/rust-cache@v2
85+
86+
# Wait for crates.io index to update after fetchkit publish
87+
- name: Wait for crates.io index
88+
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'false')
89+
run: sleep 30
90+
91+
- name: Verify crate can be packaged
92+
run: cargo package -p fetchkit-cli --allow-dirty
93+
94+
- name: Publish fetchkit-cli (dry run)
95+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'true'
96+
run: cargo publish -p fetchkit-cli --dry-run
97+
98+
- name: Publish fetchkit-cli
99+
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'false')
100+
run: cargo publish -p fetchkit-cli
101+
env:
102+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

crates/fetchkit-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ name = "fetchkit"
1212
path = "src/main.rs"
1313

1414
[dependencies]
15-
fetchkit = { path = "../fetchkit" }
15+
fetchkit = { version = "0.1.0", path = "../fetchkit" }
1616
tokio = { workspace = true }
1717
clap = { workspace = true }
1818
serde = { workspace = true }

0 commit comments

Comments
 (0)