From 16cbf6a81bd6f758307f89e2acde059a3b2a629c Mon Sep 17 00:00:00 2001 From: Ato Araki Date: Sun, 20 Sep 2026 07:47:14 +0900 Subject: [PATCH 1/2] Migrate CI from CircleCI to GitHub Actions --- .circleci/config.yml | 88 ----------------------------------- .github/workflows/release.yml | 60 ++++++++++++++++++++++++ .github/workflows/test.yml | 34 ++++++++++++++ scripts/build-deb.sh | 42 +++++++++++++++++ 4 files changed, 136 insertions(+), 88 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml create mode 100755 scripts/build-deb.sh diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 5776ec8..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,88 +0,0 @@ -version: 2.1 - -executors: - build: - docker: - - image: atotto/debian-builder:latest - working_directory: /workspace - environment: - GOPATH: / - GOCACHE: /.cache/go-build - deploy: - docker: - - image: atotto/debian-builder:latest - working_directory: /workspace - environment: - GOPATH: / - GOCACHE: /.cache/go-build - -jobs: - build: - executor: - name: build - steps: - - run: go env - - checkout - - restore_cache: - keys: - - go-module-cache-v1-{{ checksum "/workspace/go.sum" }} - - go-module-cache-v1- - - run: go mod download - - save_cache: - key: go-module-cache-v1-{{ checksum "/workspace/go.sum" }} - paths: - - /pkg/mod/cache - - run: go vet ./... - - run: staticcheck ./... - - run: go test -v ./... - - run: go build && go clean - - persist_to_workspace: - root: /workspace - paths: - - . - - deploy: - executor: - name: deploy - steps: - - attach_workspace: - at: /workspace - - restore_cache: - keys: - - go-module-cache-v1-{{ checksum "/workspace/go.sum" }} - - go-module-cache-v1- - - run: - name: release version ${CIRCLE_TAG#v} - command: echo "release version ${CIRCLE_TAG#v}" - - run: - name: build for arm64 - command: rm -rf pkg-build && export GOARCH=arm64 && go build && go-bin-deb generate --arch ${GOARCH} --version ${CIRCLE_TAG#v} - - run: - name: build for armhf v7 - command: rm -rf pkg-build && GOARCH=arm GOARM=7 go build && go-bin-deb generate --arch armhf --version ${CIRCLE_TAG#v} - - run: - name: build for amd64 - command: rm -rf pkg-build && export GOARCH=amd64 && go build && go-bin-deb generate --arch ${GOARCH} --version ${CIRCLE_TAG#v} - - run: ./packagecloud push atotto/debian-utils/any/any packagecloud_*.deb - -workflows: - version: 2 - test: - jobs: - - build - build_and_deploy: - jobs: - - build: - filters: - tags: - only: /^v.*/ - branches: - ignore: /.*/ - - deploy: - requires: - - build - filters: - tags: - only: /^v.*/ - branches: - ignore: /.*/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..5d9480a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,60 @@ +name: Release + +on: + push: + tags: + - "v*" + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: go vet + run: go vet ./... + + - name: Install staticcheck + run: go install honnef.co/go/tools/cmd/staticcheck@latest + + - name: staticcheck + run: staticcheck ./... + + - name: go test + run: go test -v ./... + env: + PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }} + + - name: Install Debian package build dependencies + run: | + sudo apt-get update + sudo apt-get install --yes fakeroot lintian + + - name: Install go-bin-deb + env: + GO_BIN_DEB_SHA256: 520eeaee7ebd3a7c317fda0c57a93a56c870d36a0dcee0c3d397807f5ef8b8d4 + GO_BIN_DEB_URL: https://github.com/groove-x/go-bin-deb/releases/download/0.0.19%2Bgx11/go-bin-deb-amd64.deb + run: | + curl --fail --location --silent --show-error \ + --output "$RUNNER_TEMP/go-bin-deb.deb" "$GO_BIN_DEB_URL" + echo "$GO_BIN_DEB_SHA256 $RUNNER_TEMP/go-bin-deb.deb" | sha256sum --check --strict + dpkg-deb --extract "$RUNNER_TEMP/go-bin-deb.deb" "$RUNNER_TEMP/go-bin-deb" + echo "$RUNNER_TEMP/go-bin-deb/usr/bin" >> "$GITHUB_PATH" + + - name: Build Debian packages + run: ./scripts/build-deb.sh "$GITHUB_REF_NAME" + + - name: Create GitHub Release + run: gh release create "$GITHUB_REF_NAME" packagecloud_*.deb --generate-notes + env: + GH_TOKEN: ${{ github.token }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..ed856a3 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,34 @@ +name: Test + +on: + push: + branches: + - main + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: go vet + run: go vet ./... + + - name: Install staticcheck + run: go install honnef.co/go/tools/cmd/staticcheck@latest + + - name: staticcheck + run: staticcheck ./... + + - name: go test + run: go test -v ./... + env: + PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }} + + - name: go build + run: go build && go clean diff --git a/scripts/build-deb.sh b/scripts/build-deb.sh new file mode 100755 index 0000000..e43e69e --- /dev/null +++ b/scripts/build-deb.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +set -euo pipefail + +if [[ $# -ne 1 ]]; then + echo "usage: $0 " >&2 + exit 2 +fi + +tag=$1 +if [[ ! $tag =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "tag must have the form vMAJOR.MINOR.PATCH: $tag" >&2 + exit 2 +fi +version=${tag#v} + +script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) +project_dir=$(cd -- "$script_dir/.." && pwd) +cd "$project_dir" + +rm -f packagecloud_*.deb + +build_and_package() { + local arch=$1 goos=$2 goarch=$3 goarm=$4 + local work_dir + work_dir=$(mktemp -d "${TMPDIR:-/tmp}/packagecloud-deb.XXXXXX") + trap 'rm -rf -- "$work_dir"' RETURN + + env CGO_ENABLED=0 GOOS="$goos" GOARCH="$goarch" GOARM="$goarm" \ + go build -trimpath -ldflags='-s -w' -o packagecloud . + + go-bin-deb generate \ + --file deb.json \ + --version "$version" \ + --arch "$arch" \ + --wd "$work_dir" \ + --output "$project_dir" +} + +build_and_package arm64 linux arm64 "" +build_and_package armhf linux arm 7 +build_and_package amd64 linux amd64 "" From 5038df5c7338d12a13de2edf24719e9a75083ef9 Mon Sep 17 00:00:00 2001 From: Ato Araki Date: Sun, 20 Sep 2026 07:47:14 +0900 Subject: [PATCH 2/2] Skip tests instead of failing when PACKAGECLOUD_TOKEN is unset --- api/v1/packagecloudtest/context.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/v1/packagecloudtest/context.go b/api/v1/packagecloudtest/context.go index 6cd800e..038ba13 100644 --- a/api/v1/packagecloudtest/context.go +++ b/api/v1/packagecloudtest/context.go @@ -9,7 +9,7 @@ import ( func SetupToken(tb testing.TB, ctx context.Context, token string) context.Context { if token == "" { - tb.Fatalf("empty token") + tb.Skip("PACKAGECLOUD_TOKEN is not set") } return packagecloud.WithPackagecloudToken(ctx, token) }