Skip to content

Commit df13038

Browse files
authored
Merge pull request #101 from oschwald/greg/gh-actions-updates
Update GitHub Actions
2 parents bd45717 + c7052ea commit df13038

File tree

6 files changed

+176
-33
lines changed

6 files changed

+176
-33
lines changed

.github/workflows/audit.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Security Audit
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
schedule:
8+
- cron: "0 0 * * *" # Daily at midnight
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
audit:
15+
name: Cargo Audit
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v6
20+
21+
- name: Run cargo-audit
22+
uses: actions-rust-lang/audit@v1

.github/workflows/codeql.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: CodeQL
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
schedule:
9+
- cron: "0 6 * * 1" # Weekly on Monday
10+
11+
jobs:
12+
analyze:
13+
name: Analyze
14+
runs-on: ubuntu-latest
15+
permissions:
16+
security-events: write
17+
actions: read
18+
contents: read
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v6
23+
24+
- name: Initialize CodeQL
25+
uses: github/codeql-action/init@v3
26+
with:
27+
languages: rust
28+
29+
- name: Perform CodeQL Analysis
30+
uses: github/codeql-action/analyze@v3

.github/workflows/doc.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,10 @@ jobs:
1515
uses: actions/checkout@v6
1616

1717
- name: Install Rust toolchain
18-
uses: actions-rs/toolchain@v1
19-
with:
20-
toolchain: stable
21-
profile: minimal
22-
override: true
18+
uses: dtolnay/rust-toolchain@stable
2319

2420
- name: Build Documentation
25-
uses: actions-rs/cargo@v1
26-
with:
27-
command: doc
28-
args: --all --no-deps
21+
run: cargo doc --all --no-deps
2922

3023
- name: Create index
3124
run: echo '<meta http-equiv=refresh content=0;url=maxminddb/index.html>' > target/doc/index.html

.github/workflows/release.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Publish to crates.io
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
publish:
10+
name: Publish
11+
runs-on: ubuntu-latest
12+
environment: release
13+
permissions:
14+
id-token: write
15+
contents: read
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Install Rust toolchain
21+
uses: dtolnay/rust-toolchain@stable
22+
23+
- name: Authenticate with crates.io
24+
uses: rust-lang/crates-io-auth-action@v1
25+
id: auth
26+
27+
- name: Publish to crates.io
28+
run: cargo publish
29+
env:
30+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}

.github/workflows/rust.yml

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,14 @@ jobs:
2020

2121
steps:
2222
- uses: actions/checkout@v6
23+
2324
- name: Install ${{ matrix.toolchain }} toolchain
24-
uses: actions-rs/toolchain@v1
25+
uses: dtolnay/rust-toolchain@master
2526
with:
26-
profile: minimal
2727
toolchain: ${{ matrix.toolchain }}
28-
override: true
2928

3029
- name: Run cargo check
31-
uses: actions-rs/cargo@v1
32-
with:
33-
command: check
30+
run: cargo check
3431

3532
test:
3633
name: Test Suite
@@ -46,16 +43,12 @@ jobs:
4643
submodules: true
4744

4845
- name: Install ${{ matrix.toolchain }} toolchain
49-
uses: actions-rs/toolchain@v1
46+
uses: dtolnay/rust-toolchain@master
5047
with:
51-
profile: minimal
5248
toolchain: ${{ matrix.toolchain }}
53-
override: true
5449

5550
- name: Run cargo test
56-
uses: actions-rs/cargo@v1
57-
with:
58-
command: test
51+
run: cargo test
5952

6053
lints:
6154
name: Lints
@@ -65,21 +58,12 @@ jobs:
6558
uses: actions/checkout@v6
6659

6760
- name: Install stable toolchain
68-
uses: actions-rs/toolchain@v1
61+
uses: dtolnay/rust-toolchain@stable
6962
with:
70-
profile: minimal
71-
toolchain: stable
72-
override: true
7363
components: rustfmt, clippy
7464

7565
- name: Run cargo fmt
76-
uses: actions-rs/cargo@v1
77-
with:
78-
command: fmt
79-
args: --all -- --check
66+
run: cargo fmt --all -- --check
8067

8168
- name: Run cargo clippy
82-
uses: actions-rs/cargo@v1
83-
with:
84-
command: clippy
85-
args: -- -D warnings
69+
run: cargo clippy -- -D warnings

dev-bin/release.sh

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash
2+
3+
set -eu -o pipefail
4+
5+
# Check that we're not on the main branch
6+
current_branch=$(git branch --show-current)
7+
if [ "$current_branch" = "main" ]; then
8+
echo "Error: Releases should not be done directly on the main branch."
9+
echo "Please create a release branch and run this script from there."
10+
exit 1
11+
fi
12+
13+
# Fetch latest changes and check that we're not behind origin/main
14+
echo "Fetching from origin..."
15+
git fetch origin
16+
17+
if ! git merge-base --is-ancestor origin/main HEAD; then
18+
echo "Error: Current branch is behind origin/main."
19+
echo "Please merge or rebase with origin/main before releasing."
20+
exit 1
21+
fi
22+
23+
changelog=$(cat CHANGELOG.md)
24+
25+
# Match: ## X.Y.Z - YYYY-MM-DD
26+
regex='## ([0-9]+\.[0-9]+\.[0-9]+) - ([0-9]{4}-[0-9]{2}-[0-9]{2})'
27+
28+
if [[ ! $changelog =~ $regex ]]; then
29+
echo "Could not find version/date line in CHANGELOG.md!"
30+
echo "Expected format: ## X.Y.Z - YYYY-MM-DD"
31+
exit 1
32+
fi
33+
34+
version="${BASH_REMATCH[1]}"
35+
date="${BASH_REMATCH[2]}"
36+
37+
# Extract release notes (everything between first ## version and next ## version)
38+
notes=$(sed -n '/^## '"$version"'/,/^## [0-9]/p' CHANGELOG.md | sed '1d;$d')
39+
40+
if [[ "$date" != $(date +"%Y-%m-%d") ]]; then
41+
echo "Release date $date is not today ($(date +"%Y-%m-%d"))!"
42+
exit 1
43+
fi
44+
45+
tag="v$version"
46+
47+
if [ -n "$(git status --porcelain)" ]; then
48+
echo "Working directory is not clean." >&2
49+
exit 1
50+
fi
51+
52+
# Update version in Cargo.toml
53+
current_cargo_version=$(grep -E '^version = "[0-9]+\.[0-9]+\.[0-9]+"' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
54+
if [ "$current_cargo_version" != "$version" ]; then
55+
echo "Updating Cargo.toml version from $current_cargo_version to $version"
56+
sed -i "s/^version = \"$current_cargo_version\"/version = \"$version\"/" Cargo.toml
57+
fi
58+
59+
echo "Running tests..."
60+
cargo test
61+
62+
echo $'\nDiff:'
63+
git diff
64+
65+
echo $'\nRelease notes:'
66+
echo "$notes"
67+
68+
read -r -p "Commit changes and push to origin? [y/N] " should_push
69+
70+
if [ "$should_push" != "y" ]; then
71+
echo "Aborting"
72+
git checkout -- Cargo.toml
73+
exit 1
74+
fi
75+
76+
if [ -n "$(git status --porcelain)" ]; then
77+
git commit -m "Prepare $tag release" -a
78+
fi
79+
80+
git push
81+
82+
gh release create --target "$(git branch --show-current)" -t "$version" -n "$notes" "$tag"
83+
84+
git push --tags

0 commit comments

Comments
 (0)