ci.yaml 9.9 KB

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