Skip to content

Commit 3af7d72

Browse files
committed
add github workflow
1 parent 268ddff commit 3af7d72

4 files changed

Lines changed: 124 additions & 0 deletions

File tree

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: cargo
4+
directory: /
5+
schedule:
6+
interval: weekly
7+
- package-ecosystem: github-actions
8+
directory: /
9+
schedule:
10+
interval: weekly

.github/workflows/audit.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Security Audit
2+
on:
3+
push:
4+
paths:
5+
- Cargo.lock
6+
pull_request:
7+
paths:
8+
- Cargo.lock
9+
jobs:
10+
audit:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v6
14+
- name: Install Rust
15+
uses: actions-rust-lang/setup-rust-toolchain@v1
16+
- name: Cache cargo
17+
uses: Swatinem/rust-cache@v2
18+
- name: Install cargo-audit
19+
run: cargo install cargo-audit
20+
- name: Run audit
21+
run: cargo audit

.github/workflows/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: CI
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
branches: [master]
7+
workflow_call:
8+
env:
9+
CARGO_TERM_COLOR: always
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v6
15+
- name: Install additional packages
16+
run: sudo apt-get update && sudo apt-get install -y build-essential libgtksourceview-5-dev
17+
- name: Install Rust
18+
uses: actions-rust-lang/setup-rust-toolchain@v1
19+
with:
20+
components: clippy, rustfmt
21+
- name: Cache cargo
22+
uses: Swatinem/rust-cache@v2
23+
- name: Check formatting
24+
run: cargo fmt -- --check
25+
- name: Clippy
26+
run: cargo clippy --all-targets -- -D warnings -W clippy::pedantic
27+
- name: Build
28+
run: cargo build --locked
29+
- name: Run tests
30+
run: cargo test --all-targets --locked

.github/workflows/publish.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Publish to crates.io
2+
on:
3+
workflow_dispatch:
4+
jobs:
5+
checks:
6+
runs-on: ubuntu-latest
7+
if: false
8+
steps:
9+
- uses: actions/checkout@v6
10+
with:
11+
fetch-depth: 0
12+
- name: Check HEAD has a tag
13+
id: get_tag
14+
run: |
15+
TAG=$(git tag --points-at HEAD | head -n1)
16+
if [ -z "$TAG" ]; then
17+
echo "Error: HEAD commit has no tag. Please tag this commit before publishing."
18+
exit 1
19+
fi
20+
echo "Found tag: $TAG"
21+
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
22+
- name: Check tag matches Cargo.toml version
23+
run: |
24+
TAG="${{ steps.get_tag.outputs.tag }}"
25+
# Strip leading 'v' if present (v0.4.1 -> 0.4.1)
26+
VERSION="${TAG#v}"
27+
CARGO_VERSION=$(grep -m1 '^version' Cargo.toml | sed 's/.*"\(.*\)".*/\1/')
28+
if [ "$VERSION" != "$CARGO_VERSION" ]; then
29+
echo "Error: Tag version ($VERSION) does not match Cargo.toml version ($CARGO_VERSION)"
30+
exit 1
31+
fi
32+
echo "Tag matches Cargo.toml version: $VERSION"
33+
- name: Check version not already on crates.io
34+
run: |
35+
TAG="${{ steps.get_tag.outputs.tag }}"
36+
# Strip leading 'v' if present (v0.4.1 -> 0.4.1)
37+
VERSION="${TAG#v}"
38+
echo "Checking if $VERSION exists on crates.io..."
39+
40+
CRATE_NAME=$(grep -m1 '^name' Cargo.toml | sed 's/.*"\(.*\)".*/\1/')
41+
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://crates.io/api/v1/crates/$CRATE_NAME/$VERSION")
42+
if [ "$HTTP_STATUS" = "200" ]; then
43+
echo "Error: Version $VERSION already exists on crates.io"
44+
exit 1
45+
fi
46+
echo "Version $VERSION not yet published, proceeding."
47+
ci:
48+
needs: checks
49+
uses: ./.github/workflows/ci.yml
50+
publish:
51+
needs: ci
52+
runs-on: ubuntu-latest
53+
steps:
54+
- uses: actions/checkout@v6
55+
# TODO: check which packages are needed, if any
56+
- name: Install packages needed for build
57+
run: sudo apt-get update && sudo apt-get install -y build-essential
58+
- name: Install Rust
59+
uses: actions-rust-lang/setup-rust-toolchain@v1
60+
- name: Publish to crates.io
61+
run: cargo publish
62+
env:
63+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

0 commit comments

Comments
 (0)