-
Notifications
You must be signed in to change notification settings - Fork 0
160 lines (132 loc) · 4.76 KB
/
release.yml
File metadata and controls
160 lines (132 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Release
on:
push:
tags:
- 'v*'
env:
CARGO_TERM_COLOR: always
jobs:
pre-release-checks:
name: Pre-release Checks
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Get version from tag
id: get_version
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Verify version matches Cargo.toml
run: |
CARGO_VERSION=$(grep "^version = " Cargo.toml | sed 's/version = "\(.*\)"/\1/')
if [ "$CARGO_VERSION" != "${{ steps.get_version.outputs.version }}" ]; then
echo "Version mismatch: Cargo.toml has $CARGO_VERSION but tag is ${{ steps.get_version.outputs.version }}"
exit 1
fi
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
# - name: Check formatting
# run: cargo fmt --all -- --check
- name: Run clippy
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Build
run: cargo build --verbose --all-features
- name: Run tests
run: cargo test --verbose --all-features
- name: Test CLI functionality
run: |
cargo run -- --help
cargo run -- check --help
cargo run -- rules
publish-crates-io:
name: Publish to crates.io
needs: pre-release-checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Publish to crates.io
run: cargo publish --token ${{ secrets.CRATES_TOKEN }}
create-github-release:
name: Create GitHub Release
needs: [pre-release-checks, publish-crates-io]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Build release binaries
run: |
# Build for different targets
cargo build --release --all-features
# Create release directory
mkdir -p release-artifacts
# Copy binary and create archive
cp target/release/rust-guardian release-artifacts/
tar -czf release-artifacts/rust-guardian-${{ needs.pre-release-checks.outputs.version }}-x86_64-unknown-linux-gnu.tar.gz -C release-artifacts rust-guardian
# Generate checksums
cd release-artifacts
sha256sum * > checksums.txt
- name: Generate changelog
id: changelog
run: |
# Try to get changelog from git log since last tag
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -n "$PREVIOUS_TAG" ]; then
echo "## Changes since $PREVIOUS_TAG" > CHANGELOG.md
git log --pretty=format:"- %s (%h)" ${PREVIOUS_TAG}..HEAD >> CHANGELOG.md
else
echo "## Release ${{ needs.pre-release-checks.outputs.version }}" > CHANGELOG.md
echo "Initial release of rust-guardian" >> CHANGELOG.md
fi
# Add installation instructions
echo "" >> CHANGELOG.md
echo "## Installation" >> CHANGELOG.md
echo "" >> CHANGELOG.md
echo "\`\`\`bash" >> CHANGELOG.md
echo "cargo install rust-guardian" >> CHANGELOG.md
echo "\`\`\`" >> CHANGELOG.md
echo "" >> CHANGELOG.md
echo "## Documentation" >> CHANGELOG.md
echo "" >> CHANGELOG.md
echo "- [Crates.io](https://crates.io/crates/rust-guardian)" >> CHANGELOG.md
echo "- [Documentation](https://docs.rs/rust-guardian)" >> CHANGELOG.md
echo "- [Repository](https://github.com/cloudfunnels/rust-guardian)" >> CHANGELOG.md
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.pre-release-checks.outputs.version }}
name: Release v${{ needs.pre-release-checks.outputs.version }}
body_path: CHANGELOG.md
files: |
release-artifacts/*.tar.gz
release-artifacts/checksums.txt
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}