-
-
Notifications
You must be signed in to change notification settings - Fork 119
136 lines (118 loc) · 4.05 KB
/
ci.yml
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
131
132
133
134
135
136
name: Build & Publish Image
on:
push:
branches: ["develop", "ci/*", "v*"]
tags: ["v*"]
paths: ["src/GZCTF/**"]
workflow_dispatch:
inputs:
skip-build:
type: boolean
description: "Skip build step"
default: false
required: false
env:
# latest tag is only created for `v*.*.*` or `v*.*.*-patch.*` tags
RELEASE: ${{ startsWith(github.ref, 'refs/tags/v') && (contains(github.ref, 'patch') || !contains(github.ref, '-')) }}
jobs:
build:
runs-on: ubuntu-latest
if: ${{ !github.event.inputs.skip-build }}
permissions:
contents: read
packages: write
defaults:
run:
working-directory: src/GZCTF
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
global-json-file: src/global.json
- uses: actions/setup-node@v4
with:
node-version: latest
- name: Get current date time
id: datetime
uses: Kaven-Universe/github-action-current-date-time@v1
with:
format: "YYYY-MM-DDTHH:mm:ssZ"
- name: Docker setup QEMU
uses: docker/setup-qemu-action@v3
- name: Docker setup Buildx
uses: docker/setup-buildx-action@v3
- name: Prebuild project
run: |
npm i -g pnpm
dotnet build "GZCTF.csproj" -c Release -o build
- name: Publish project
run: |
dotnet publish "GZCTF.csproj" -c Release -o publish/linux/amd64 -r linux-x64 --no-self-contained /p:PublishReadyToRun=true
# ignore arm64 for non-release tags
if [ "${{ env.RELEASE }}" = "true" ]; then
dotnet publish "GZCTF.csproj" -c Release -o publish/linux/arm64 -r linux-arm64 --no-self-contained /p:PublishReadyToRun=true /p:EFOptimizeContext=false
fi
env:
VITE_APP_BUILD_TIMESTAMP: ${{ steps.datetime.outputs.time }}
VITE_APP_GIT_SHA: ${{ github.sha }}
VITE_APP_GIT_NAME: ${{ github.ref_name }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: gztime
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Aliyun Container Registry
uses: docker/login-action@v3
with:
registry: registry.cn-shanghai.aliyuncs.com
username: ${{ secrets.ALIYUN_USER }}
password: ${{ secrets.ALIYUN_PASSWORD }}
- name: Docker metadata action
uses: docker/metadata-action@v5
id: meta
with:
images: |
gztime/gzctf
ghcr.io/${{ github.repository }}/gzctf
registry.cn-shanghai.aliyuncs.com/gztime/gzctf
flavor: |
latest=${{ env.RELEASE }}
tags: |
type=ref,event=branch
type=match,enable=${{ env.RELEASE }},pattern=v\d+,group=0
type=match,enable=${{ env.RELEASE }},pattern=v\d+.\d+,group=0
type=match,enable=${{ env.RELEASE }},pattern=v\d+.\d+.\d+,group=0
- name: Publish images
uses: docker/build-push-action@v6
with:
context: ./src/GZCTF
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ env.RELEASE == 'true' && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
push: true
prune:
runs-on: ubuntu-latest
needs: build
if: always()
permissions:
contents: read
packages: write
steps:
- name: Prune old packages
uses: dataaxiom/ghcr-cleanup-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
package: gzctf/gzctf
use-regex: true
exclude-tags: "^latest$|^develop$|v\\d+(\\.\\d+){0,2}"
validate: true
dry-run: false
delete-untagged: true
delete-ghost-images: true
delete-partial-images: true