Skip to content

Commit 299bc2e

Browse files
committed
Add GitHub Actions workflow for Rust CI/CD
1 parent 2b37c04 commit 299bc2e

2 files changed

Lines changed: 68 additions & 2 deletions

File tree

.github/workflows/rust.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Rust
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Build
19+
run: cargo build --verbose
20+
- name: Run tests
21+
run: cargo test --verbose
22+
23+
publish:
24+
name: Publish to crates.io
25+
needs: build
26+
runs-on: ubuntu-latest
27+
# Only run on pushes to main branch, not on pull requests
28+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
29+
steps:
30+
- uses: actions/checkout@v4
31+
32+
# Setup Rust toolchain
33+
- uses: actions-rs/toolchain@v1
34+
with:
35+
toolchain: stable
36+
override: true
37+
38+
# Check if version has changed compared to the published version
39+
- name: Check version
40+
id: check-version
41+
run: |
42+
CURRENT_VERSION=$(grep -m 1 "version" Cargo.toml | sed -E 's/version = "(.*)"/\1/')
43+
PUBLISHED_VERSION=$(cargo search unit-enum --limit 1 | grep -m 1 "unit-enum" | sed -E 's/unit-enum = "(.*)"/\1/' || echo "0.0.0")
44+
45+
if [ "$CURRENT_VERSION" != "$PUBLISHED_VERSION" ]; then
46+
echo "Version changed from $PUBLISHED_VERSION to $CURRENT_VERSION"
47+
echo "version_changed=true" >> $GITHUB_OUTPUT
48+
else
49+
echo "Version unchanged: $CURRENT_VERSION"
50+
echo "version_changed=false" >> $GITHUB_OUTPUT
51+
fi
52+
53+
# Publish to crates.io if version has changed
54+
- name: Publish to crates.io
55+
if: steps.check-version.outputs.version_changed == 'true'
56+
uses: actions-rs/cargo@v1
57+
with:
58+
command: publish
59+
args: --token ${{ secrets.CRATES_IO_TOKEN }}

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
## Version 1.4.2 (2025-05-17)
11+
12+
### Added
13+
14+
- Add documentation and funding links
15+
- Setup GitHub actions
16+
1017
## Version 1.4.1 (2024-11-18)
1118

1219
### Fixed
1320

14-
Update documentation examples to ignore code blocks so client tests are not impacted
21+
- Update documentation examples to ignore code blocks so client tests are not impacted
1522

1623
## Version 1.4.0 (2024-10-28)
1724

@@ -42,4 +49,4 @@ Update documentation examples to ignore code blocks so client tests are not impa
4249

4350
### Added
4451

45-
- Initial Revision
52+
- Initial Revision

0 commit comments

Comments
 (0)