Repository navigation
130 lines (124 loc) · 3.88 KB
/
Copy pathbuild.yml
File metadata and controls
130 lines (124 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Build And Release
on:
push:
branches: [main]
tags: ['v*']
pull_request:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: build-${{ github.ref }}
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }}
jobs:
build:
runs-on: ubuntu-24.04
env:
CGO_ENABLED: '0'
GOTOOLCHAIN: local
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: '22.13.0'
cache: npm
cache-dependency-path: web/package-lock.json
- name: Check And Build Frontend
working-directory: web
run: |
npm ci
npm run lint
npm run build
- uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache-dependency-path: go.sum
- name: Run Unit Tests
run: go test -mod=readonly ./cmd/... ./internal/...
- name: Check Minimum Go Version
run: |
go version
go vet ./...
go build -mod=readonly ./cmd/aistudio2api
- uses: actions/setup-go@v7
with:
go-version: stable
cache: false
- name: Build Packages
shell: bash
run: |
version="${GITHUB_SHA:0:7}"
if [[ "$GITHUB_REF_TYPE" == tag ]]; then version="$GITHUB_REF_NAME"; fi
mkdir -p dist
for target in windows/amd64 linux/amd64 linux/arm64 darwin/amd64 darwin/arm64; do
export GOOS="${target%/*}" GOARCH="${target#*/}"
name="aistudio2api-${version}-${GOOS}-${GOARCH}"
directory="dist/$name"
mkdir -p "$directory"
binary=aistudio2api
if [[ "$GOOS" == windows ]]; then binary+=.exe; cp start.bat "$directory/"; fi
go build -mod=readonly -trimpath -ldflags='-s -w' -o "$directory/$binary" ./cmd/aistudio2api
cp README.md README_en.md LICENSE .env.example "$directory/"
cp -r docs "$directory/"
if [[ "$GOOS" == windows ]]; then
(cd dist && zip -qr "$name.zip" "$name")
else
tar -czf "dist/$name.tar.gz" -C dist "$name"
fi
done
- uses: actions/upload-artifact@v7
with:
name: packages
path: |
dist/*.zip
dist/*.tar.gz
retention-days: 7
release:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
needs: build
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
- uses: actions/download-artifact@v8
with:
name: packages
path: dist
- name: Publish Release
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
RELEASE_TAG: ${{ github.ref_name }}
shell: bash
run: |
flags=()
if [[ "$RELEASE_TAG" == *-* ]]; then flags+=(--prerelease); fi
gh release create "$RELEASE_TAG" dist/* --verify-tag --generate-notes --title "$RELEASE_TAG" "${flags[@]}"
docker:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
needs: build
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v7
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: type=semver,pattern={{raw}}
- uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}