diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..f629fe9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,54 @@ +name: CI + +on: + pull_request: + branches: + - main + push: + branches: + - main + +permissions: + contents: read + +concurrency: + group: ci-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: true + + - name: Set up Just + uses: extractions/setup-just@v3 + + - name: Run tests + run: just test + + cross-build: + runs-on: ubuntu-latest + needs: test + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: true + + - name: Set up Just + uses: extractions/setup-just@v3 + + - name: Validate cross-platform builds + run: just clean && just build-all diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..907e89a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,61 @@ +name: Release + +on: + push: + tags: + - "*" + - "*/*" + +permissions: + contents: write + +concurrency: + group: release-${{ github.ref }} + cancel-in-progress: true + +jobs: + build-and-release: + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: true + + - name: Set up Just + uses: extractions/setup-just@v3 + + - name: Build release binaries + run: just clean && VERSION="${GITHUB_REF_NAME}" just build-all + + - name: Package release artifacts + shell: bash + run: | + mkdir -p release + for file in dist/*; do + base="$(basename "$file")" + stem="${base%.exe}" + versioned="${stem}-${GITHUB_REF_NAME}" + if [[ "$base" == *.exe ]]; then + zip -j "release/${versioned}.zip" "$file" + continue + fi + tar -C dist -czf "release/${versioned}.tar.gz" "$base" + done + ( + cd release + sha256sum * > checksums.txt + ) + + - name: Create GitHub release + uses: softprops/action-gh-release@v2 + with: + files: release/* + fail_on_unmatched_files: true + generate_release_notes: true diff --git a/Makefile b/Makefile deleted file mode 100644 index 8961e7d..0000000 --- a/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -BINARY ?= olh -DIST ?= dist -VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev) -COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown) -DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ") -LDFLAGS = -s -w -X github.com/formation-res/open-location-hub-cli/internal/build.Version=$(VERSION) -X github.com/formation-res/open-location-hub-cli/internal/build.Commit=$(COMMIT) -X github.com/formation-res/open-location-hub-cli/internal/build.Date=$(DATE) - -.PHONY: generate tidy build test clean build-all - -generate: - go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@v2.4.1 -config internal/openapi/client.cfg.yaml api/omlox-hub.v0.yaml - -tidy: - go mod tidy - -build: generate - go build -ldflags "$(LDFLAGS)" -o $(DIST)/$(BINARY) ./cmd/olh - -test: generate - go test ./... - -clean: - rm -rf $(DIST) - -build-all: generate - mkdir -p $(DIST) - GOOS=darwin GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o $(DIST)/$(BINARY)-darwin-amd64 ./cmd/olh - GOOS=darwin GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o $(DIST)/$(BINARY)-darwin-arm64 ./cmd/olh - GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o $(DIST)/$(BINARY)-linux-amd64 ./cmd/olh - GOOS=linux GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o $(DIST)/$(BINARY)-linux-arm64 ./cmd/olh - GOOS=windows GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o $(DIST)/$(BINARY)-windows-amd64.exe ./cmd/olh diff --git a/README.md b/README.md index f940a27..0e6a7e7 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ Current scope: ## Build ```bash -make build -make build-all +just build +just build-all ``` Artifacts are written to `dist/`. diff --git a/justfile b/justfile new file mode 100644 index 0000000..023d78d --- /dev/null +++ b/justfile @@ -0,0 +1,35 @@ +set shell := ["bash", "-eu", "-o", "pipefail", "-c"] + +module := "github.com/formation-res/open-location-hub-cli" +binary := env_var_or_default("BINARY", "olh") +dist := env_var_or_default("DIST", "dist") +version := env_var_or_default("VERSION", `git describe --tags --always --dirty 2>/dev/null || echo dev`) +commit := env_var_or_default("COMMIT", `git rev-parse --short HEAD 2>/dev/null || echo unknown`) +date := env_var_or_default("DATE", `date -u +"%Y-%m-%dT%H:%M:%SZ"`) +default: + @just --list + +generate: + go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@v2.4.1 -config internal/openapi/client.cfg.yaml api/omlox-hub.v0.yaml + +tidy: + go mod tidy + +build: generate + mkdir -p {{dist}} + go build -ldflags "-s -w -X {{module}}/internal/build.Version={{version}} -X {{module}}/internal/build.Commit={{commit}} -X {{module}}/internal/build.Date={{date}}" -o {{dist}}/{{binary}} ./cmd/olh + +test: generate + go test ./... + +clean: + rm -rf {{dist}} + +build-all: generate + mkdir -p {{dist}} + GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -X {{module}}/internal/build.Version={{version}} -X {{module}}/internal/build.Commit={{commit}} -X {{module}}/internal/build.Date={{date}}" -o {{dist}}/{{binary}}-darwin-amd64 ./cmd/olh + GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -X {{module}}/internal/build.Version={{version}} -X {{module}}/internal/build.Commit={{commit}} -X {{module}}/internal/build.Date={{date}}" -o {{dist}}/{{binary}}-darwin-arm64 ./cmd/olh + GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X {{module}}/internal/build.Version={{version}} -X {{module}}/internal/build.Commit={{commit}} -X {{module}}/internal/build.Date={{date}}" -o {{dist}}/{{binary}}-linux-amd64 ./cmd/olh + GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -X {{module}}/internal/build.Version={{version}} -X {{module}}/internal/build.Commit={{commit}} -X {{module}}/internal/build.Date={{date}}" -o {{dist}}/{{binary}}-linux-arm64 ./cmd/olh + GOOS=windows GOARCH=386 go build -ldflags "-s -w -X {{module}}/internal/build.Version={{version}} -X {{module}}/internal/build.Commit={{commit}} -X {{module}}/internal/build.Date={{date}}" -o {{dist}}/{{binary}}-windows-386.exe ./cmd/olh + GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -X {{module}}/internal/build.Version={{version}} -X {{module}}/internal/build.Commit={{commit}} -X {{module}}/internal/build.Date={{date}}" -o {{dist}}/{{binary}}-windows-amd64.exe ./cmd/olh