Skip to content

Commit 23d9121

Browse files
pan93412claude
andcommitted
ci: add CI workflows, golangci-lint config, and release pipeline
- Add .golangci.yml (v2 format): standard linters + modernize, formatter gofumpt - Add tests.yml: lint/format check and unit tests via Nix on PRs and pushes to main - Add release.yml: build on PRs (VERSION=0.0.0), push to Docker Hub and Huawei SWR on v* tag push; GHA cache enabled with mode=max Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a8f4807 commit 23d9121

4 files changed

Lines changed: 138 additions & 2 deletions

File tree

.github/workflows/release.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
pull_request:
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
actions: write
13+
14+
jobs:
15+
release:
16+
name: Build and push
17+
runs-on: blacksmith-2vcpu-ubuntu-2404-arm
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
22+
23+
- name: Set up QEMU
24+
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0
25+
26+
- name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
28+
29+
- name: Login to Docker Hub
30+
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
31+
if: github.event_name != 'pull_request'
32+
with:
33+
username: ${{ secrets.DOCKERHUB_USERNAME }}
34+
password: ${{ secrets.DOCKERHUB_TOKEN }}
35+
36+
- name: Login to Huawei SWR
37+
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
38+
if: github.event_name != 'pull_request'
39+
with:
40+
registry: swr.cn-east-3.myhuaweicloud.com
41+
username: ${{ secrets.HUAWEI_SWR_USERNAME }}
42+
password: ${{ secrets.HUAWEI_SWR_TOKEN }}
43+
44+
- name: Extract version
45+
id: version
46+
run: |
47+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
48+
echo "VERSION=0.0.0" >> "$GITHUB_OUTPUT"
49+
else
50+
echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
51+
fi
52+
53+
- name: Build
54+
run: docker buildx bake --set "*.cache-from=type=gha" --set "*.cache-to=type=gha,mode=max"
55+
env:
56+
VERSION: ${{ steps.version.outputs.VERSION }}
57+
58+
- name: Push to Docker Hub
59+
if: github.event_name != 'pull_request'
60+
run: docker buildx bake --push --set "*.cache-from=type=gha"
61+
env:
62+
VERSION: ${{ steps.version.outputs.VERSION }}
63+
64+
- name: Push to Huawei SWR
65+
if: github.event_name != 'pull_request'
66+
run: docker buildx bake --push --set "*.cache-from=type=gha"
67+
env:
68+
VERSION: ${{ steps.version.outputs.VERSION }}
69+
REGISTRY: swr.cn-east-3.myhuaweicloud.com

.github/workflows/tests.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
permissions:
11+
id-token: write
12+
contents: read
13+
14+
concurrency:
15+
group: tests-${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
lint:
20+
name: Lint and format
21+
runs-on: blacksmith-2vcpu-ubuntu-2404-arm
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
26+
27+
- name: Install Nix
28+
uses: DeterminateSystems/determinate-nix-action@bafaa638b9d5ec0e7e3ac1a7fc80453ef1fd265f # v3.20.0
29+
30+
- name: Set up FlakeHub cache
31+
uses: DeterminateSystems/flakehub-cache-action@1f9a51a2959d3e26c7838c6f3bf9f48acae525ea # v3.20.0
32+
33+
- name: Verify formatting
34+
run: nix develop --command golangci-lint fmt --diff
35+
36+
- name: Run golangci-lint
37+
run: nix develop --command golangci-lint run ./...
38+
39+
unit:
40+
name: Unit tests
41+
runs-on: blacksmith-2vcpu-ubuntu-2404-arm
42+
43+
steps:
44+
- name: Checkout
45+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
46+
47+
- name: Install Nix
48+
uses: DeterminateSystems/determinate-nix-action@bafaa638b9d5ec0e7e3ac1a7fc80453ef1fd265f # v3.20.0
49+
50+
- name: Set up FlakeHub cache
51+
uses: DeterminateSystems/flakehub-cache-action@1f9a51a2959d3e26c7838c6f3bf9f48acae525ea # v3.20.0
52+
53+
- name: Run unit tests
54+
run: nix develop --command go test ./...

.golangci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: "2"
2+
3+
run:
4+
timeout: 5m
5+
6+
linters:
7+
default: standard
8+
enable:
9+
- modernize
10+
11+
formatters:
12+
enable:
13+
- gofumpt

examples/push-image/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222
"github.com/google/go-containerregistry/pkg/v1/empty"
2323
"github.com/google/go-containerregistry/pkg/v1/layout"
2424

25-
stratusconfig "github.com/zeabur/stratus/v2/pkg/config"
26-
stratuspush "github.com/zeabur/stratus/v2/pkg/push"
25+
stratusconfig "github.com/zeabur/stratus/v2/pkg/config"
26+
stratuspush "github.com/zeabur/stratus/v2/pkg/push"
2727
stratusstorage "github.com/zeabur/stratus/v2/pkg/storage"
2828
)
2929

0 commit comments

Comments
 (0)