Skip to content

Commit 01be603

Browse files
authored
Merge pull request #1 from DIG-Network/develop
feat: add CI
2 parents 706df0f + bc69f2b commit 01be603

19 files changed

Lines changed: 1333 additions & 921 deletions

File tree

.github/workflows/ci.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: CI
2+
3+
env:
4+
RUST_TOOLCHAIN: "1.90.0"
5+
6+
permissions:
7+
contents: read
8+
9+
on:
10+
pull_request:
11+
branches: [main]
12+
paths-ignore:
13+
- "**/*.md"
14+
- LICENSE
15+
- "**/*.gitignore"
16+
- .editorconfig
17+
- docs/**
18+
19+
jobs:
20+
validate-pr:
21+
name: Validate PR source and version bump
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout PR head
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
28+
29+
- name: Fetch main branch for comparison
30+
run: git fetch origin main:refs/remotes/origin/main
31+
32+
- name: Read versions (Cargo.toml)
33+
id: versions
34+
shell: bash
35+
run: |
36+
PR_CRATE_VER=$(grep -m1 '^version\s*=\s*"' Cargo.toml | sed -E 's/.*"([^"]+)".*/\1/')
37+
MAIN_CRATE_VER=$(git show origin/main:Cargo.toml | grep -m1 '^version\s*=\s*"' | sed -E 's/.*"([^"]+)".*/\1/')
38+
echo "pr_crate_ver=$PR_CRATE_VER" >> $GITHUB_OUTPUT
39+
echo "main_crate_ver=$MAIN_CRATE_VER" >> $GITHUB_OUTPUT
40+
echo "PR Cargo.toml version: $PR_CRATE_VER"
41+
echo "Main Cargo.toml version: $MAIN_CRATE_VER"
42+
43+
- name: Ensure workspace/package versions match (if both present)
44+
if: ${{ github.event.pull_request.base.ref == 'main' }}
45+
shell: bash
46+
run: |
47+
set -euo pipefail
48+
PKG_VER=$(grep -m1 '^version\s*=\s*"' Cargo.toml | sed -E 's/.*"([^"]+)".*/\1/' || true)
49+
WS_VER=$(awk '/^\[workspace.package\]/{f=1;next} /^\[/{f=0} f && /^version\s*=/{print; exit}' Cargo.toml | sed -E 's/.*"([^"]+)".*/\1/' || true)
50+
if [ -n "${WS_VER}" ] && [ -n "${PKG_VER}" ] && [ "${WS_VER}" != "${PKG_VER}" ]; then
51+
echo "[workspace.package].version (${WS_VER}) does not match [package].version (${PKG_VER}). Please keep them in sync before merging to main." >&2
52+
exit 1
53+
fi
54+
55+
- name: Ensure version increased
56+
if: ${{ github.event.pull_request.base.ref == 'main' }}
57+
shell: bash
58+
run: |
59+
cmp_versions () { [ "$1" = "$2" ] && return 1; printf '%s\n%s\n' "$2" "$1" | sort -V | head -n1 | grep -q "^$2$"; }
60+
if ! cmp_versions "${{ steps.versions.outputs.pr_crate_ver }}" "${{ steps.versions.outputs.main_crate_ver }}"; then
61+
echo "Cargo.toml version must be greater in the PR than on main (current: ${{ steps.versions.outputs.pr_crate_ver }}, main: ${{ steps.versions.outputs.main_crate_ver }})." >&2
62+
exit 1
63+
fi
64+
65+
rust-checks:
66+
name: Rust checks (${{ matrix.os }})
67+
needs: validate-pr
68+
runs-on: ${{ matrix.os }}
69+
strategy:
70+
fail-fast: false
71+
matrix:
72+
os: [ubuntu-latest, macos-latest, windows-latest]
73+
74+
steps:
75+
- uses: actions/checkout@v4
76+
77+
# --- Rust toolchain ---
78+
- name: Setup Rust toolchain (pinned)
79+
uses: actions-rust-lang/setup-rust-toolchain@v1
80+
with:
81+
toolchain: ${{ env.RUST_TOOLCHAIN }}
82+
components: clippy,rustfmt
83+
84+
- name: Cache cargo
85+
uses: actions/cache@v4
86+
with:
87+
path: |
88+
~/.cargo/registry/index/
89+
~/.cargo/registry/cache/
90+
~/.cargo/git/db/
91+
target/
92+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
93+
94+
- name: Show versions
95+
shell: bash
96+
run: |
97+
rustc -Vv
98+
cargo -V
99+
echo "Running on: $(uname -a || echo windows)"
100+
101+
- name: Test
102+
run: cargo test --all-features
103+
104+
- name: Clippy
105+
run: cargo clippy --all-targets --all-features -- -D warnings
106+
107+
- name: Fmt
108+
run: cargo fmt --all -- --check

.github/workflows/release.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: Release on push to main
2+
3+
env:
4+
RUST_TOOLCHAIN: "1.75.0"
5+
6+
permissions:
7+
contents: write
8+
id-token: write
9+
10+
on:
11+
push:
12+
branches: [main]
13+
14+
jobs:
15+
rust-tests:
16+
name: Rust tests (${{ matrix.os }})
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
os: [ubuntu-latest, macos-latest, windows-latest]
22+
steps:
23+
- uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Setup Rust toolchain (pinned)
28+
uses: actions-rust-lang/setup-rust-toolchain@v1
29+
with:
30+
toolchain: ${{ env.RUST_TOOLCHAIN }}
31+
32+
- name: Test
33+
run: cargo test --all-features
34+
35+
create-release:
36+
name: Create GitHub Release
37+
needs: rust-tests
38+
runs-on: ubuntu-latest
39+
steps:
40+
- uses: actions/checkout@v4
41+
with:
42+
fetch-depth: 0
43+
44+
- name: Read crate version
45+
id: ver
46+
shell: bash
47+
run: |
48+
set -euo pipefail
49+
VERSION=$(grep -m1 '^version\s*=\s*"' Cargo.toml | sed -E 's/.*"([^"]+)".*/\1/')
50+
if [ -z "$VERSION" ]; then
51+
echo "Failed to read version from Cargo.toml" >&2
52+
exit 1
53+
fi
54+
echo "version=v$VERSION" >> "$GITHUB_OUTPUT"
55+
56+
- name: Create tag if missing
57+
shell: bash
58+
run: |
59+
set -euo pipefail
60+
TAG="${{ steps.ver.outputs.version }}"
61+
if ! git rev-parse "$TAG" >/dev/null 2>&1; then
62+
git tag "$TAG" "${GITHUB_SHA}"
63+
git push origin "$TAG"
64+
fi
65+
66+
- name: Create GitHub Release
67+
uses: softprops/action-gh-release@v2
68+
with:
69+
tag_name: ${{ steps.ver.outputs.version }}
70+
name: Release ${{ steps.ver.outputs.version }}
71+
generate_release_notes: true
72+
draft: false
73+
prerelease: false
74+
env:
75+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76+
77+
publish-crates:
78+
name: Publish to crates.io
79+
needs: [rust-tests, create-release]
80+
runs-on: ubuntu-latest
81+
steps:
82+
- uses: actions/checkout@v4
83+
with:
84+
fetch-depth: 0
85+
86+
- name: Setup Rust toolchain (pinned)
87+
uses: actions-rust-lang/setup-rust-toolchain@v1
88+
with:
89+
toolchain: ${{ env.RUST_TOOLCHAIN }}
90+
91+
- name: Check crates.io token is present
92+
shell: bash
93+
env:
94+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
95+
run: |
96+
if [ -z "${CARGO_REGISTRY_TOKEN}" ]; then
97+
echo "CARGO_REGISTRY_TOKEN is empty/missing." >&2
98+
exit 1
99+
fi
100+
101+
- name: Publish crate
102+
env:
103+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
104+
run: cargo publish --no-verify --allow-dirty

Cargo.lock

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "action-layer-driver"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
5-
rust-version = "1.75.0"
5+
rust-version = "1.90.0"
66
description = "Generic driver for Action Layer (CHIP-0050) singleton spend construction on Chia"
77
license = "MIT"
88
authors = ["DIG Network"]
@@ -32,20 +32,16 @@ hex-literal = "0.4"
3232
# Error handling
3333
thiserror = "2"
3434

35-
[dev-dependencies]
36-
tokio = { version = "1", features = ["full"] }
37-
anyhow = "1.0"
38-
3935
[workspace]
4036
members = [
4137
"examples/singlelaunch",
4238
"examples/wallet",
4339
]
4440

4541
[workspace.package]
46-
version = "0.1.0"
42+
version = "0.1.1"
4743
edition = "2021"
48-
rust-version = "1.75.0"
44+
rust-version = "1.90.0"
4945
license = "MIT"
5046
authors = ["DIG Network"]
5147

0 commit comments

Comments
 (0)