Skip to content

Commit 4c18c2b

Browse files
authored
Merge pull request #10 from LuisFerLCC/gh-config
Add GitHub Actions: Tests and Publish on PR into stable
2 parents b0716c2 + 9143e88 commit 4c18c2b

3 files changed

Lines changed: 125 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Publish to crates.io
2+
3+
on:
4+
push:
5+
branches:
6+
- stable
7+
8+
permissions:
9+
contents: write
10+
discussions: write
11+
12+
13+
jobs:
14+
test:
15+
name: Run tests and publish
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
21+
22+
- name: Setup Rust toolchain
23+
uses: actions-rust-lang/setup-rust-toolchain@2fcdc490d667999e01ddbbf0f2823181beef6b39
24+
with:
25+
components: rustfmt, clippy
26+
27+
- name: Run RustFMT
28+
uses: actions-rust-lang/rustfmt@559aa3035a47390ba96088dffa783b5d26da9326
29+
30+
- name: Run Clippy
31+
run: cargo clippy --all-targets --all-features
32+
33+
- name: Run tests
34+
run: cargo test --verbose --all-targets --all-features
35+
36+
- name: Run documentation tests
37+
run: cargo test --verbose --doc --all-features
38+
39+
- name: Get crate version
40+
id: get_crate_info
41+
run: |
42+
CRATE_VERSION=$(grep '^version = ' Cargo.toml | head -n 1 | cut -d '"' -f 2)
43+
echo "Crate error-stack-macros2"
44+
echo "Crate Version: $CRATE_VERSION"
45+
echo "crate_version=$CRATE_VERSION" >> "$GITHUB_OUTPUT"
46+
47+
- name: Publish crate
48+
env:
49+
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATESIO_API_TOKEN }}
50+
run: cargo publish
51+
52+
- name: Create GitHub release
53+
uses: softprops/action-gh-release@6cbd405e2c4e67a21c47fa9e383d020e4e28b836
54+
with:
55+
body_path: RELEASE.md
56+
prerelease: true
57+
name: "`error-stack-macros2` ${{ steps.get_crate_info.outputs.crate_version }}"
58+
tag_name: v${{ steps.get_crate_info.outputs.crate_version }}
59+
target_commitish: stable

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111

1212
workflow_dispatch:
1313

14+
1415
jobs:
1516
test:
1617
name: Run tests

.github/workflows/testToStable.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Run tests and check version on crates.io
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- stable
7+
8+
9+
jobs:
10+
test:
11+
name: Run tests on PR into stable
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
17+
18+
- name: Setup Rust toolchain
19+
uses: actions-rust-lang/setup-rust-toolchain@2fcdc490d667999e01ddbbf0f2823181beef6b39
20+
with:
21+
components: rustfmt, clippy
22+
23+
- name: Run RustFMT
24+
uses: actions-rust-lang/rustfmt@559aa3035a47390ba96088dffa783b5d26da9326
25+
26+
- name: Run Clippy
27+
run: cargo clippy --all-targets --all-features
28+
29+
- name: Run tests
30+
run: cargo test --verbose --all-targets --all-features
31+
32+
- name: Run documentation tests
33+
run: cargo test --verbose --doc --all-features
34+
35+
36+
check-version:
37+
name: Check version on crates.io
38+
runs-on: ubuntu-latest
39+
40+
steps:
41+
- name: Checkout repository
42+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
43+
44+
- name: Get crate version
45+
id: get_crate_info
46+
run: |
47+
CRATE_VERSION=$(grep '^version = ' Cargo.toml | head -n 1 | cut -d '"' -f 2)
48+
echo "Crate error-stack-macros2"
49+
echo "Crate Version: $CRATE_VERSION"
50+
echo "crate_version=$CRATE_VERSION" >> "$GITHUB_OUTPUT"
51+
52+
- name: Check if version already exists on crates.io
53+
run: |
54+
CRATE_VERSION="${{ steps.get_crate_info.outputs.crate_version }}"
55+
API_URL="https://crates.io/api/v1/crates/error-stack-macros2/$CRATE_VERSION"
56+
57+
echo "Checking $API_URL"
58+
59+
if curl --head -f "$API_URL"; then
60+
echo "Error: Version $CRATE_VERSION already exists on crates.io!"
61+
echo "Please increment the version in Cargo.toml."
62+
exit 1
63+
else
64+
echo "Version $CRATE_VERSION does not exist on crates.io. You're good to go!"
65+
fi

0 commit comments

Comments
 (0)