Skip to content

Commit 84f8c3a

Browse files
authored
Merge pull request #5 from cloudfunnels/copilot/fix-4
Add GitHub Actions workflows for automated crates.io publishing and CI/CD
2 parents e5fa28e + 77b250e commit 84f8c3a

File tree

8 files changed

+708
-12
lines changed

8 files changed

+708
-12
lines changed

.github/mlc_config.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"ignorePatterns": [
3+
{
4+
"pattern": "^http://localhost"
5+
},
6+
{
7+
"pattern": "^https://localhost"
8+
}
9+
],
10+
"replacementPatterns": [],
11+
"httpHeaders": [
12+
{
13+
"urls": ["https://crates.io", "https://docs.rs"],
14+
"headers": {
15+
"User-Agent": "Mozilla/5.0 (compatible; link-checker)"
16+
}
17+
}
18+
],
19+
"timeout": "10s",
20+
"retryOn429": true,
21+
"retryCount": 3,
22+
"fallbackHttpStatus": [400, 401, 403, 404, 429, 500, 502, 503, 504]
23+
}

.github/workflows/ci.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
test:
14+
name: Test
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
rust:
19+
- stable
20+
- beta
21+
- nightly
22+
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- name: Install Rust
27+
uses: dtolnay/rust-toolchain@master
28+
with:
29+
toolchain: ${{ matrix.rust }}
30+
components: rustfmt, clippy
31+
32+
- name: Cache cargo registry
33+
uses: actions/cache@v4
34+
with:
35+
path: |
36+
~/.cargo/registry
37+
~/.cargo/git
38+
target
39+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
40+
restore-keys: |
41+
${{ runner.os }}-cargo-
42+
43+
- name: Check formatting
44+
if: matrix.rust == 'stable'
45+
run: cargo fmt --all -- --check
46+
47+
- name: Run clippy
48+
if: matrix.rust == 'stable'
49+
run: cargo clippy --all-targets --all-features -- -D warnings
50+
51+
- name: Build
52+
run: cargo build --verbose --all-features
53+
54+
- name: Run tests
55+
run: cargo test --verbose --all-features
56+
57+
- name: Test CLI
58+
run: |
59+
cargo run -- --help
60+
cargo run -- check --help
61+
cargo run -- rules
62+
63+
coverage:
64+
name: Coverage
65+
runs-on: ubuntu-latest
66+
steps:
67+
- uses: actions/checkout@v4
68+
69+
- name: Install Rust
70+
uses: dtolnay/rust-toolchain@stable
71+
72+
- name: Install cargo-llvm-cov
73+
uses: taiki-e/install-action@cargo-llvm-cov
74+
75+
- name: Generate code coverage
76+
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
77+
78+
- name: Upload coverage to Codecov
79+
uses: codecov/codecov-action@v4
80+
with:
81+
file: lcov.info
82+
fail_ci_if_error: true
83+
84+
security:
85+
name: Security Audit
86+
runs-on: ubuntu-latest
87+
steps:
88+
- uses: actions/checkout@v4
89+
90+
- name: Install Rust
91+
uses: dtolnay/rust-toolchain@stable
92+
93+
- name: Install cargo-audit
94+
run: cargo install cargo-audit
95+
96+
- name: Run security audit
97+
run: cargo audit
98+
99+
minimal-versions:
100+
name: Minimal Versions
101+
runs-on: ubuntu-latest
102+
steps:
103+
- uses: actions/checkout@v4
104+
105+
- name: Install Rust
106+
uses: dtolnay/rust-toolchain@nightly
107+
108+
- name: Install minimal-versions
109+
run: cargo install cargo-minimal-versions
110+
111+
- name: Check minimal versions
112+
run: cargo minimal-versions check

.github/workflows/docs.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Documentation
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths:
7+
- 'src/**'
8+
- 'README.md'
9+
- 'Cargo.toml'
10+
- 'examples/**'
11+
pull_request:
12+
branches: [ main ]
13+
paths:
14+
- 'src/**'
15+
- 'README.md'
16+
- 'Cargo.toml'
17+
- 'examples/**'
18+
19+
env:
20+
CARGO_TERM_COLOR: always
21+
22+
jobs:
23+
doc-tests:
24+
name: Documentation Tests
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- uses: actions/checkout@v4
29+
30+
- name: Install Rust
31+
uses: dtolnay/rust-toolchain@stable
32+
33+
- name: Cache cargo registry
34+
uses: actions/cache@v4
35+
with:
36+
path: |
37+
~/.cargo/registry
38+
~/.cargo/git
39+
target
40+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
41+
restore-keys: |
42+
${{ runner.os }}-cargo-
43+
44+
- name: Test documentation examples
45+
run: cargo test --doc --all-features
46+
47+
- name: Build documentation
48+
run: |
49+
cargo doc --all-features --no-deps
50+
# Check that docs build without warnings
51+
cargo doc --all-features --no-deps 2>&1 | tee doc-warnings.txt
52+
if grep -q "warning:" doc-warnings.txt; then
53+
echo "Documentation has warnings!"
54+
cat doc-warnings.txt
55+
exit 1
56+
fi
57+
58+
- name: Check README examples
59+
run: |
60+
# Extract and test code examples from README
61+
echo "Checking README examples compile..."
62+
# This is a basic check - in practice you might want more sophisticated validation
63+
64+
check-links:
65+
name: Check Documentation Links
66+
runs-on: ubuntu-latest
67+
68+
steps:
69+
- uses: actions/checkout@v4
70+
71+
- name: Check links in README
72+
uses: gaurav-nelson/github-action-markdown-link-check@v1
73+
with:
74+
use-quiet-mode: 'yes'
75+
use-verbose-mode: 'yes'
76+
config-file: '.github/mlc_config.json'
77+
78+
validate-metadata:
79+
name: Validate Package Metadata
80+
runs-on: ubuntu-latest
81+
82+
steps:
83+
- uses: actions/checkout@v4
84+
85+
- name: Install Rust
86+
uses: dtolnay/rust-toolchain@stable
87+
88+
- name: Check package metadata
89+
run: |
90+
# Verify all required metadata is present for crates.io
91+
echo "Checking package metadata..."
92+
cargo metadata --format-version 1 | jq -r '.packages[] | select(.name == "rust-guardian") | {name, version, description, license, repository, documentation, keywords, categories}'
93+
94+
# Verify the package can be packaged (list files)
95+
cargo package --list --allow-dirty

.github/workflows/release.yml

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

0 commit comments

Comments
 (0)