Skip to content

Commit fcda3be

Browse files
authored
feat: CI (#1255)
* feat: 发布release前,自动更新版本号文件
1 parent bf81654 commit fcda3be

File tree

6 files changed

+269
-317
lines changed

6 files changed

+269
-317
lines changed

.github/workflows/build_test.yml

Lines changed: 0 additions & 64 deletions
This file was deleted.

.github/workflows/ci.yaml

Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ '*' ]
6+
pull_request:
7+
release:
8+
types: [ created, edited ]
9+
workflow_dispatch:
10+
inputs:
11+
gva_version:
12+
required: true
13+
type: string
14+
15+
jobs:
16+
init:
17+
if: github.repository_owner == 'flipped-aurora'
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: init
21+
run: |
22+
echo "flipped-aurora"
23+
frontend:
24+
if: github.event_name == 'push' || github.event_name == 'pull_request' || github.event_name == 'release'
25+
name: Frontend node ${{ matrix.node-version }}
26+
runs-on: ubuntu-latest
27+
strategy:
28+
matrix:
29+
node-version: [16.8.0]
30+
steps:
31+
- name: Check out branch
32+
uses: actions/checkout@v2
33+
34+
- name: Use Node.js ${{ matrix.node-version }}
35+
uses: actions/setup-node@v1
36+
with:
37+
node-version: ${{ matrix.node-version }}
38+
39+
- name: Build test
40+
run: |
41+
npm install
42+
npm run build
43+
working-directory: ./web
44+
45+
backend:
46+
if: github.event_name == 'push' || github.event_name == 'pull_request' || github.event_name == 'release'
47+
name: Backend go
48+
runs-on: ubuntu-latest
49+
strategy:
50+
matrix:
51+
go-version: [1.16]
52+
steps:
53+
- name: Set up Go ${{ matrix.go-version }}
54+
uses: actions/setup-go@v1
55+
with:
56+
go-version: ${{ matrix.go-version }}
57+
id: go
58+
59+
- name: Check out branch
60+
uses: actions/checkout@v2
61+
62+
- name: Download dependencies
63+
run: |
64+
go get -v -t -d ./...
65+
if [ -f Gopkg.toml ]; then
66+
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
67+
dep ensure
68+
fi
69+
working-directory: ./server
70+
71+
- name: Test and Build
72+
run: |
73+
go build -v -race
74+
working-directory: ./server
75+
76+
devops-test:
77+
if: github.ref == 'refs/heads/test'
78+
name: devops-test
79+
needs:
80+
- init
81+
- backend
82+
- frontend
83+
runs-on: ubuntu-latest
84+
strategy:
85+
matrix:
86+
node-version: [16.8.0]
87+
go-version: [1.16]
88+
steps:
89+
- name: Check out branch
90+
uses: actions/checkout@v2
91+
- name: Sed Config
92+
env:
93+
PROD: ${{ secrets.PROD }}
94+
TESTING: ${{ secrets.TESTING }}
95+
shell: bash
96+
run: |
97+
git branch
98+
ls -l
99+
sed -i "s/${PROD}/${TESTING}/g" web/.env.production
100+
sed -i 's/${basePath}:${basePort}/${basePath}/g' web/src/view/systemTools/formCreate/index.vue
101+
- name: Use Node.js ${{ matrix.node-version }}
102+
uses: actions/[email protected]
103+
with:
104+
node-version: ${{ matrix.node-version }}
105+
- name: Build-Node
106+
run: |
107+
cd web/ && yarn install && yarn run build
108+
- name: Use Go ${{ matrix.go-version }}
109+
uses: actions/setup-go@v1
110+
with:
111+
go-version: ${{ matrix.go-version }}
112+
- name: Build-go
113+
run: |
114+
cd server/ && go mod tidy && go build && mkdir ../web/ser && mv server ../web/ser/ && cd ../web/ser/ && ls -s
115+
- name: restart
116+
env:
117+
KEY: ${{ secrets.KEY }}
118+
HOST: ${{ secrets.HOST }}
119+
USER: ${{ secrets.USER }}
120+
PROT: ${{ secrets.PROT }}
121+
MKDIRTEST: ${{ secrets.MKDIRTEST }}
122+
run: |
123+
mkdir -p ~/.ssh/ && echo "$KEY" > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa
124+
ssh-keyscan github.com >> ~/.ssh/known_hosts
125+
scp -P ${PROT} -o StrictHostKeyChecking=no -r web/dist/* ${USER}@${HOST}:${MKDIRTEST}dist/
126+
scp -P ${PROT} -o StrictHostKeyChecking=no -r web/ser/* ${USER}@${HOST}:${MKDIRTEST}
127+
ssh -p ${PROT} -o StrictHostKeyChecking=no ${USER}@${HOST} "cd ${MKDIRTEST}resource/ && rm -rf ${MKDIRTEST}resource/*"
128+
scp -P ${PROT} -o StrictHostKeyChecking=no -r server/resource/* ${USER}@${HOST}:${MKDIRTEST}resource/
129+
ssh -p ${PROT} -o StrictHostKeyChecking=no ${USER}@${HOST} "cd ${MKDIRTEST} && bash restart.sh > /dev/null 2>&1 &"
130+
131+
release-pr:
132+
if: ${{ github.event_name == 'workflow_dispatch' && github.repository_owner == 'flipped-aurora'}}
133+
runs-on: ubuntu-latest
134+
steps:
135+
- name: Check out branch
136+
uses: actions/checkout@v2
137+
- name: Sed Config
138+
env:
139+
GVA_VERSION: ${{ inputs.gva_version }}
140+
shell: bash
141+
run: |
142+
sed -i 's/当前版本.*`$/当前版本:v'${GVA_VERSION##v}'`/' web/src/core/config.js
143+
sed -i 's/当前版本.*$/当前版本:v'${GVA_VERSION##v}'/' server/core/server.go
144+
sed -i 's/当前版本.*$/当前版本:v'${GVA_VERSION##v}'/' web/src/core/gin-vue-admin.js
145+
sed -i 's/"version": ".*",$/"version": "'${GVA_VERSION##v}'",/' web/package.json
146+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
147+
git config --local user.name "github-actions[bot]"
148+
git add . && git commit -m "release: v${GVA_VERSION##v}"
149+
- name: Push
150+
uses: ad-m/github-push-action@master
151+
with:
152+
github_token: ${{ secrets.GITHUB_TOKEN }}
153+
branch: ${{ github.ref }}
154+
- uses: google-github-actions/release-please-action@v3
155+
with:
156+
command: release-pr
157+
release-type: simple
158+
changelog-path: docs/CHANGELOG.md
159+
release-as: ${{ inputs.gva_version }}
160+
package-name: gin-vue-admin
161+
changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":false}]'
162+
163+
release-please:
164+
if: github.ref == 'refs/heads/main' || github.event_name == 'release'
165+
runs-on: ubuntu-latest
166+
needs:
167+
- init
168+
- backend
169+
- frontend
170+
outputs:
171+
release_created: ${{ steps.release_please.outputs.release_created }}
172+
tag_name: ${{ steps.release_please.outputs.tag_name }}
173+
steps:
174+
- uses: google-github-actions/release-please-action@v3
175+
id: release_please
176+
with:
177+
#token: ${{ secrets.GAV_TOKEN }}
178+
command: github-release
179+
#signoff: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
180+
release-type: simple
181+
changelog-path: docs/CHANGELOG.md
182+
#release-as: ${{ inputs.deploy_target }}
183+
package-name: gin-vue-admin
184+
#extra-files: |
185+
# x-release-please-version.json
186+
changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":false}]'
187+
188+
devops-prod:
189+
if: needs.release-please.outputs.release_created || github.event_name == 'release'
190+
runs-on: ubuntu-latest
191+
needs:
192+
- init
193+
- release-please
194+
name: devops-prod
195+
strategy:
196+
matrix:
197+
node-version: ['16.x']
198+
go-version: ['1.16']
199+
steps:
200+
- uses: actions/checkout@v2
201+
- name: tag major and minor versions
202+
run: |
203+
echo " ${{ needs.release-please.outputs.tag_name }}"
204+
- name: Sed Config
205+
shell: bash
206+
run: |
207+
git branch
208+
ls -l
209+
sed -i 's/${basePath}:${basePort}/${basePath}/g' web/src/view/systemTools/formCreate/index.vue
210+
- name: Use Node.js ${{ matrix.node-version }}
211+
uses: actions/[email protected]
212+
with:
213+
node-version: ${{ matrix.node-version }}
214+
- name: Build-Node
215+
run: |
216+
cd web/ && yarn install && yarn run build
217+
- name: Use Go ${{ matrix.go-version }}
218+
uses: actions/setup-go@v1
219+
with:
220+
go-version: ${{ matrix.go-version }}
221+
- name: Build-go
222+
run: |
223+
cd server/ && go mod tidy && go build && mkdir ../web/ser && mv server ../web/ser/ && cd ../web/ser/ && ls -s
224+
- name: restart
225+
env:
226+
KEY: ${{ secrets.KEY }}
227+
HOST: ${{ secrets.HOST }}
228+
USER: ${{ secrets.USER }}
229+
PROT: ${{ secrets.PROT }}
230+
MKDIR: ${{ secrets.MKDIR }}
231+
run: |
232+
mkdir -p ~/.ssh/ && echo "$KEY" > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa
233+
ssh-keyscan github.com >> ~/.ssh/known_hosts
234+
scp -P ${PROT} -o StrictHostKeyChecking=no -r web/dist/* ${USER}@${HOST}:${MKDIR}dist/
235+
scp -P ${PROT} -o StrictHostKeyChecking=no -r web/ser/* ${USER}@${HOST}:${MKDIR}
236+
ssh -p ${PROT} -o StrictHostKeyChecking=no ${USER}@${HOST} "cd ${MKDIR}resource/ && rm -rf ${MKDIR}resource/*"
237+
scp -P ${PROT} -o StrictHostKeyChecking=no -r server/resource/* ${USER}@${HOST}:${MKDIR}resource/
238+
ssh -p ${PROT} -o StrictHostKeyChecking=no ${USER}@${HOST} "cd ${MKDIR} && bash restart.sh > /dev/null 2>&1 &"
239+
240+
docker:
241+
name: docker
242+
if: github.ref == 'refs/heads/stop-stop-stop'
243+
runs-on: ubuntu-latest
244+
needs:
245+
- init
246+
- release-please
247+
steps:
248+
- name: Check out branch
249+
uses: actions/checkout@v2
250+
- name: Login to Aliyun Registry
251+
uses: docker/login-action@v1
252+
with:
253+
registry: ${{ secrets.ALIYUN_REGISTRY }}
254+
username: ${{ secrets.ALIYUN_DOCKERHUB_USER }}
255+
password: ${{ secrets.ALIYUN_DOCKERHUB_PASSWORD }}
256+
- name: Sed Config
257+
shell: bash
258+
run: |
259+
sed -i 56c"\ && yarn install && yarn build" Makefile
260+
make image TAGS_OPT="latest"
261+
sed -i 's#./entrypoint.sh"#./entrypoint.sh","actions"#g' deploy/docker/Dockerfile
262+
sed -i "s#COPY build/ /usr/share/nginx/html/#COPY . /opt/gva#g" deploy/docker/Dockerfile
263+
sed -i 16c"\ && cd /opt/gva/server/ && go mod tidy && cd /opt/gva/web/ && yarn" deploy/docker/Dockerfile
264+
sed -i "s#open: true#open: false#g" web/vite.config.js
265+
make images TAGS_OPT="latest"
266+
docker push registry.cn-hangzhou.aliyuncs.com/gva/gin-vue-admin:latest
267+
docker push registry.cn-hangzhou.aliyuncs.com/gva/web:latest
268+
docker push registry.cn-hangzhou.aliyuncs.com/gva/server:latest
269+
docker push registry.cn-hangzhou.aliyuncs.com/gva/all:latest

.github/workflows/devops-test.yaml

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)