From 919c2bcd270a0eeaeb7d51ad2a32fe2170ec1f5e Mon Sep 17 00:00:00 2001 From: unkin-agent Date: Wed, 18 Nov 2026 23:39:24 +1100 Subject: [PATCH] Add GitHub Actions CI and GoReleaser release --- .github/CODEOWNERS | 1 + .github/workflows/ci.yml | 52 ++++++++++++++++++++++++++++ .github/workflows/release.yml | 56 ++++++++++++++++++++++++++++++ .goreleaser.yml | 40 ++++++++++++++++++++++ .woodpecker/release.yml | 59 -------------------------------- Makefile | 8 +---- scripts/sign.sh | 9 +++++ terraform-registry-manifest.json | 6 ++++ 8 files changed, 165 insertions(+), 66 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yml delete mode 100644 .woodpecker/release.yml create mode 100755 scripts/sign.sh create mode 100644 terraform-registry-manifest.json diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..711107c --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @IUCLabs/maintainers diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..61a15a7 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,52 @@ +name: ci + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + pre-commit: + runs-on: iuclabs-k8s + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0 + with: + go-version-file: go.mod + - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 + - run: uvx pre-commit run --all-files --show-diff-on-failure + + lint: + runs-on: iuclabs-k8s + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0 + with: + go-version-file: go.mod + - run: go vet ./... + + test: + runs-on: iuclabs-k8s + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0 + with: + go-version-file: go.mod + # runner image has no C toolchain, so no -race + - run: go test -count=1 ./... + + build: + runs-on: iuclabs-k8s + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0 + with: + go-version-file: go.mod + - run: go build -trimpath -ldflags="-s -w" ./... diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..08969ce --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,56 @@ +name: release + +on: + push: + tags: ["v*"] + +permissions: + contents: write + id-token: write + +env: + VAULT_ADDR: https://vault.service.consul:8200 + ARTIFACTAPI: https://artifactapi.k8s.syd1.au.unkin.net + +jobs: + release: + runs-on: iuclabs-release + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + - uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0 + with: + go-version-file: go.mod + - uses: hashicorp/vault-action@892a26828f195e65540a40b4768ae4571f51ebfc # v4.0.0 + with: + url: ${{ env.VAULT_ADDR }} + method: jwt + path: jwt/github/iuclabs + role: release + jwtGithubAudience: ${{ env.VAULT_ADDR }} + exportToken: true + - uses: goreleaser/goreleaser-action@a4f02ab5355a589de60d917a659ce617ed19b3de # v7.3.0 + with: + distribution: goreleaser + version: v2.20.2 + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # fresh login: vault tokens live 15m and the build may eat most of the first one + - uses: hashicorp/vault-action@892a26828f195e65540a40b4768ae4571f51ebfc # v4.0.0 + with: + url: ${{ env.VAULT_ADDR }} + method: jwt + path: jwt/github/iuclabs + role: release + jwtGithubAudience: ${{ env.VAULT_ADDR }} + secrets: | + identity/oidc/token/artifactapi-writer token | ARTIFACTAPI_TOKEN + - name: Upload linux_amd64 to artifactapi + run: | + file="terraform-provider-artifactapi_${GITHUB_REF_NAME#v}_linux_amd64.zip" + curl -sSf --cacert /etc/vault-ca/ca.crt -X PUT \ + -H "Authorization: Bearer ${ARTIFACTAPI_TOKEN}" -H "Content-Type: application/zip" \ + --data-binary "@dist/${file}" \ + "${ARTIFACTAPI}/api/v2/remotes/terraform-unkin/files/unkin/artifactapi/${file}" diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..65f9ec2 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,40 @@ +version: 2 +project_name: terraform-provider-artifactapi + +builds: + - env: + - CGO_ENABLED=0 + mod_timestamp: "{{ .CommitTimestamp }}" + flags: + - -trimpath + ldflags: + - -s -w -X main.version={{ .Version }} + goos: [linux, darwin, windows, freebsd] + goarch: [amd64, arm64] + binary: "{{ .ProjectName }}_v{{ .Version }}" + +archives: + - formats: [zip] + name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" + files: + - none* + +checksum: + name_template: "{{ .ProjectName }}_{{ .Version }}_SHA256SUMS" + algorithm: sha256 + extra_files: + - glob: terraform-registry-manifest.json + name_template: "{{ .ProjectName }}_{{ .Version }}_manifest.json" + +signs: + - artifacts: checksum + cmd: scripts/sign.sh + args: ["${artifact}", "${signature}"] + +release: + extra_files: + - glob: terraform-registry-manifest.json + name_template: "{{ .ProjectName }}_{{ .Version }}_manifest.json" + +changelog: + disable: true diff --git a/.woodpecker/release.yml b/.woodpecker/release.yml deleted file mode 100644 index fbee441..0000000 --- a/.woodpecker/release.yml +++ /dev/null @@ -1,59 +0,0 @@ -when: - - event: tag - -steps: - - name: package - image: artifactapi.k8s.syd1.au.unkin.net/docker-internal/gobuilder:0.1.2-alma9 - environment: - GOCACHE_S3_BUCKET: gocache - GOCACHE_S3_REGION: us-east-1 - GOCACHE_S3_ENDPOINT_URL: https://s3.ceph.unkin.net - GOCACHE_S3_PATH_STYLE: "true" - GOCACHE_KEY_PREFIX: ci-terraform-provider-artifactapi - GOCACHE_METRICS: "true" - GOCACHEPROG: go-cache-plugin --cache-dir=/tmp/gocache - AWS_ACCESS_KEY_ID: - from_secret: GOCACHE_AWS_ACCESS_KEY_ID - AWS_SECRET_ACCESS_KEY: - from_secret: GOCACHE_AWS_SECRET_ACCESS_KEY - commands: - - make package VERSION=${CI_COMMIT_TAG} - backend_options: - kubernetes: - serviceAccountName: default - resources: - requests: - memory: 512Mi - cpu: 1 - limits: - memory: 2Gi - cpu: 2 - - - name: upload - image: git.unkin.net/unkin/almalinux9-base:20260606 - commands: - - | - VERSION=$$(echo ${CI_COMMIT_TAG} | sed 's/^v//') - FILE="terraform-provider-artifactapi_$${VERSION}_linux_amd64.zip" - set -o pipefail - VAULT="https://vault.service.consul:8200" - AUTH=$$(mktemp) - VT=$$(jq -n --rawfile jwt /var/run/secrets/kubernetes.io/serviceaccount/token '{role:"woodpecker_artifactapi_writer",jwt:$$jwt}' \ - | curl -sf -d @- "$$VAULT/v1/auth/k8s/au/syd1/login" | jq -er .auth.client_token) || exit 1 - printf 'X-Vault-Token: %s\n' "$$VT" | curl -sf -H @- "$$VAULT/v1/identity/oidc/token/artifactapi-writer" \ - | jq -er '"Authorization: Bearer " + .data.token' > "$$AUTH" || exit 1 - curl -f -X PUT \ - "https://artifactapi.k8s.syd1.au.unkin.net/api/v2/remotes/terraform-unkin/files/unkin/artifactapi/$${FILE}" \ - -H "Content-Type: application/zip" -H @"$$AUTH" \ - --data-binary @"$${FILE}" - depends_on: [package] - backend_options: - kubernetes: - serviceAccountName: default - resources: - requests: - memory: 128Mi - cpu: 100m - limits: - memory: 512Mi - cpu: 500m diff --git a/Makefile b/Makefile index 9b118f3..2936860 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,10 @@ -.PHONY: build install test lint fmt clean tidy patch minor major package docs +.PHONY: build install test lint fmt clean tidy patch minor major docs BINARY := terraform-provider-artifactapi VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "0.0.0-dev") OS_ARCH := linux_amd64 INSTALL_VERSION := $(shell echo $(VERSION) | sed 's/^v//') INSTALL_DIR := ~/.terraform.d/plugins/registry.terraform.io/iuclabs/artifactapi/$(INSTALL_VERSION)/$(OS_ARCH) -ZIP := $(BINARY)_$(INSTALL_VERSION)_$(OS_ARCH).zip GO_VERSION_REQUIRED := 1.23 GO_VERSION_ACTUAL := $(shell go version | sed 's/go version go\([0-9]*\.[0-9]*\).*/\1/') @@ -31,11 +30,6 @@ lint: check-go fmt: check-go gofmt -w . -package: build - cp $(BINARY) $(BINARY)_v$(INSTALL_VERSION) - python3 -c "import zipfile,sys; z=zipfile.ZipFile(sys.argv[1],'w',zipfile.ZIP_DEFLATED); z.write(sys.argv[2]); z.close()" $(ZIP) $(BINARY)_v$(INSTALL_VERSION) - rm $(BINARY)_v$(INSTALL_VERSION) - clean: rm -f $(BINARY) *.zip diff --git a/scripts/sign.sh b/scripts/sign.sh new file mode 100755 index 0000000..e95575d --- /dev/null +++ b/scripts/sign.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# Detached binary signature of $1 into $2 via the Vault gpg engine. +set -euo pipefail +b=$(base64 -w0 "$1") +jq -n --arg input "$b" '{input: $input, format: "base64"}' \ + | curl -sSf --cacert "${VAULT_CACERT:-/etc/vault-ca/ca.crt}" \ + -H "X-Vault-Token: ${VAULT_TOKEN}" -d @- \ + "${VAULT_ADDR}/v1/gpg/sign/iuclabs-release" \ + | jq -er .data.signature | base64 -d > "$2" diff --git a/terraform-registry-manifest.json b/terraform-registry-manifest.json new file mode 100644 index 0000000..295001a --- /dev/null +++ b/terraform-registry-manifest.json @@ -0,0 +1,6 @@ +{ + "version": 1, + "metadata": { + "protocol_versions": ["6.0"] + } +}