Skip to content

Commit 60d7258

Browse files
authored
ci: migrate workflows from Go to Rust (#56)
* Migrate GitHub Action workflows from Go to Rust - Update ci.yaml: Replace Go test with Rust build/test/fmt/clippy - Update release.yml: Use GoReleaser v2.5+ native Rust support - Add .goreleaser.yaml: cargo-zigbuild cross-compilation config - Update Makefile: Replace Go targets with cargo equivalents - Delete old .goreleaser.yml (Go-specific config) Targets: linux (gnu/musl), macOS (x86_64/aarch64 + universal), Windows * ci: use only musl targets for static binaries (#2)
1 parent ffabf1f commit 60d7258

File tree

6 files changed

+117
-121
lines changed

6 files changed

+117
-121
lines changed

.github/workflows/ci.yaml

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
1+
name: CI
2+
13
on:
24
push:
3-
branches:
4-
- master
5+
branches: [master]
56
pull_request:
6-
branches:
7-
- master
7+
branches: [master]
88

99
jobs:
10-
unittests:
11-
name: Run Unit Tests
10+
test:
11+
name: Build and Test
1212
runs-on: ubuntu-latest
1313
steps:
14-
- name: Check out repository
15-
uses: actions/checkout@v2
16-
- name: run unit tests
17-
run: make test
14+
- uses: actions/checkout@v4
15+
- uses: dtolnay/rust-toolchain@stable
16+
with:
17+
components: rustfmt, clippy
18+
- uses: Swatinem/rust-cache@v2
19+
20+
- name: Build
21+
run: cargo build --release
22+
23+
- name: Run tests
24+
run: cargo test
25+
26+
- name: Check formatting
27+
run: cargo fmt --check
28+
29+
- name: Clippy
30+
run: cargo clippy --all-targets --all-features -- -W clippy::all

.github/workflows/goreleaser.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- 'v*'
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
goreleaser:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
- uses: mlugg/setup-zig@v2
20+
- uses: goreleaser/goreleaser-action@v6
21+
with:
22+
distribution: goreleaser
23+
version: "~> v2"
24+
args: release --clean
25+
env:
26+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
version: 2
2+
project_name: dictpress
3+
4+
before:
5+
hooks:
6+
- rustup default stable
7+
- cargo install --locked cargo-zigbuild
8+
- cargo fetch --locked
9+
10+
builds:
11+
- builder: rust
12+
targets:
13+
- x86_64-unknown-linux-musl
14+
- aarch64-unknown-linux-musl
15+
# NOTE: macOS/Windows targets excluded due to mimalloc cross-compilation issues
16+
# The mimalloc C library can't cross-compile with cargo-zigbuild:
17+
# - macOS: Missing CommonCrypto headers
18+
# - Windows: -Werror,-Wdate-time fails on __DATE__/__TIME__ macros
19+
#
20+
# To enable macOS/Windows targets, make mimalloc optional in Cargo.toml:
21+
# mimalloc = { version = "0.1", default-features = false, optional = true }
22+
# [features]
23+
# musl = ["mimalloc"]
24+
25+
archives:
26+
- format: tar.gz
27+
# Include Target to differentiate gnu vs musl builds
28+
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Target }}"
29+
format_overrides:
30+
- goos: windows
31+
format: zip
32+
33+
changelog:
34+
sort: asc
35+
filters:
36+
exclude:
37+
- "^docs:"
38+
- "^test:"
39+
- "^ci:"
40+
41+
# universal_binaries disabled: no macOS targets currently
42+
# universal_binaries:
43+
# - replace: true
44+
45+
release:
46+
footer: |
47+
---
48+
Released with [GoReleaser](https://goreleaser.com).

.goreleaser.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

Makefile

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,33 @@
1-
# Try to get the commit hash from 1) git 2) the VERSION file 3) fallback.
2-
LAST_COMMIT := $(or $(shell git rev-parse --short HEAD 2> /dev/null),$(shell head -n 1 VERSION | grep -oP -m 1 "^[a-z0-9]+$$"),"UNKNOWN")
3-
4-
# Try to get the semver from 1) git 2) the VERSION file 3) fallback.
5-
VERSION := $(or $(shell git describe --tags --abbrev=0 2> /dev/null),$(shell grep -oP "tag: \K(.*)(?=,)" VERSION),"v0.0.0")
6-
7-
BUILDSTR := ${VERSION} (\#${LAST_COMMIT} $(shell date -u +"%Y-%m-%dT%H:%M:%S%z"))
8-
9-
GOPATH ?= $(HOME)/go
10-
STUFFBIN ?= $(GOPATH)/bin/stuffbin
1+
# Try to get the semver from 1) git 2) fallback.
2+
VERSION := $(or $(shell git describe --tags --abbrev=0 2> /dev/null),"v0.0.0")
3+
COMMIT := $(or $(shell git rev-parse --short HEAD 2> /dev/null),"unknown")
114

125
BIN := dictpress
13-
STATIC := config.sample.toml schema.sql queries.sql admin go.mod go.sum
146

157
.PHONY: build
16-
build: $(BIN)
17-
18-
$(STUFFBIN):
19-
go install github.com/knadh/stuffbin/...
20-
21-
$(BIN): $(shell find . -type f -name "*.go") ${STATIC}
22-
CGO_ENABLED=0 go build -o ${BIN} -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}'" cmd/${BIN}/*.go
8+
build:
9+
cargo build --release
2310

2411
.PHONY: run
2512
run:
26-
CGO_ENABLED=0 go run -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}'" cmd/${BIN}/*.go
27-
13+
cargo run
2814

29-
run-mock-db:
30-
docker run --rm -d -p 5432:5432 --name dictpress-db -e POSTGRES_PASSWORD=dictpress -e POSTGRES_USER=dictpress -e POSTGRES_DB=dictpress postgres:13 -c log_statement=all
31-
sleep 1
32-
docker exec -i dictpress-db psql -U dictpress -d dictpress < schema.sql
33-
touch run-mock-db
15+
.PHONY: test
16+
test:
17+
cargo test
3418

35-
clean-mock-db:
36-
docker rm -f dictpress-db
37-
rm run-mock-db
19+
.PHONY: fmt
20+
fmt:
21+
cargo fmt
3822

39-
# Run Go tests.
40-
.PHONY: test
41-
test: run-mock-db unit-test clean-mock-db
23+
.PHONY: lint
24+
lint:
25+
cargo clippy -- -D warnings
4226

43-
unit-test:
44-
go test ./...
27+
.PHONY: clean
28+
clean:
29+
cargo clean
4530

4631
.PHONY: dist
47-
dist: $(STUFFBIN) build pack-bin
48-
49-
# pack-releases runns stuffbin packing on the given binary. This is used
50-
# in the .goreleaser post-build hook.
51-
.PHONY: pack-bin
52-
pack-bin: $(BIN) $(STUFFBIN)
53-
$(STUFFBIN) -a stuff -in ${BIN} -out ${BIN} ${STATIC}
54-
55-
# Use goreleaser to do a dry run producing local builds.
56-
.PHONY: release-dry
57-
release-dry:
58-
goreleaser --parallelism 1 --rm-dist --snapshot --skip-validate --skip-publish
59-
60-
# Use goreleaser to build production releases and publish them.
61-
.PHONY: release
62-
release:
63-
goreleaser --parallelism 1 --rm-dist --skip-validate
32+
dist: build
33+
@echo "Binary at: target/release/$(BIN)"

0 commit comments

Comments
 (0)