-
Notifications
You must be signed in to change notification settings - Fork 1
131 lines (112 loc) · 3.43 KB
/
Copy pathrelease.yml
File metadata and controls
131 lines (112 loc) · 3.43 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
131
name: Release
# 仅当推送符合语义化版本的 tag(如 v1.2.3)时触发,
# 自动创建 GitHub Release 并将对应版本的 Docker 镜像推送到 GHCR。
on:
push:
tags:
- 'v*'
permissions:
contents: write
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
release:
runs-on: ubuntu-latest
services:
# 质量门禁:单元测试需要数据库
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: vnerp_test
MYSQL_USER: test
MYSQL_PASSWORD: test123
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping -h 127.0.0.1 -uroot -proot --silent"
--health-interval=10s
--health-timeout=5s
--health-retries=10
redis:
image: redis:7
ports:
- 6379:6379
options: >-
--health-cmd="redis-cli ping"
--health-interval=10s
--health-timeout=5s
--health-retries=10
env:
DB_HOST: 127.0.0.1
DB_PORT: 3306
DB_USER: test
DB_PASSWORD: test123
DB_NAME: vnerp_test
REDIS_URL: redis://127.0.0.1:6379
JWT_SECRET: test-jwt-secret
NODE_ENV: test
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
# ============================================================
# 质量门禁:只有通过 lint / 类型检查 / 单元测试的代码才允许发布
# 确保只有 CI 通过的代码才能发布
# ============================================================
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run linter
run: pnpm lint
- name: Run lint gate
run: pnpm lint:gate
- name: Run TypeScript check
run: pnpm ts-check
- name: Run unit tests
run: pnpm test:unit:run
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
generate_release_notes: true
prerelease: ${{ contains(github.ref_name, '-') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}