Created
January 6, 2024 05:55
-
-
Save Ran-Xing/1247f8e3fd5783f841d948f64258e7e8 to your computer and use it in GitHub Desktop.
Github CICD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 编译测试 | |
# 该脚本仅在 PR MERGE 的时候进行测试,不建议 将测试结果上传到 github | |
# 可以通过变量来判断,比如 PR close 的时候 发布 github release & tag | |
on: | |
pull_request: | |
branches: | |
- master # 正式版本 | |
types: | |
- synchronize | |
- opened | |
- closed | |
workflow_dispatch: # 手动触发 | |
permissions: write-all | |
jobs: | |
like_admin: | |
name: 编译后端 | |
runs-on: ubuntu-latest | |
steps: | |
- name: 获取代码 | |
uses: actions/checkout@v4 | |
- name: 设置 java 环境 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: '8' | |
- name: 编译 | |
run: | | |
cd ./server | |
mvn clean install -Dmaven.test.skip=true -f pom.xml | |
find ${PWD} -name "*.jar" -exec zip -j like-admin.zip {} + | |
- name: 上传 | |
uses: actions/upload-artifact@v4 | |
with: | |
name: like-admin.zip | |
path: server/like-admin.zip | |
retention-days: 5 | |
uniapp: | |
runs-on: ubuntu-latest | |
name: 编译前端 | |
steps: | |
- name: 获取代码 | |
uses: actions/checkout@v4 | |
- name: 设置 node 环境 | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '16' | |
- name: 打包 | |
run: | | |
cd ./uniapp | |
npm install | |
npm run build:h5 | |
cd .. | |
zip -rj uniapp.zip ./h5 | |
- name: 上传 | |
uses: actions/upload-artifact@v4 | |
id: artifact-upload-step | |
with: | |
name: uniapp.zip | |
path: uniapp.zip | |
retention-days: 5 | |
Make_Release: | |
# 该任务可在 merge 也就是 pr clone 的时候 进行上传任务 当然也可以合并成一个 cli | |
needs: [ like_admin, uniapp ] | |
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && (github.event.pull_request.merge_commit_sha != '' || github.event.pull_request.merged == true)) | |
name: 发布编译好的软件 | |
runs-on: ubuntu-latest | |
steps: | |
- name: 获取代码 | |
uses: actions/checkout@v4 | |
- name: 下载 | |
if: github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true | |
id: download-artifact | |
uses: actions/download-artifact@v4 | |
with: | |
path: ./ | |
merge-multiple: true | |
- name: 解压 | |
if: github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true | |
run: | | |
unzip like-admin.zip -d ./dist | |
mv uniapp.zip ./dist | |
- name: 生成版本号 | |
if: github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true # 只有被合并的 pr 才会 发布 | |
id: tag_version | |
uses: mathieudutour/github-tag-action@v6.1 | |
- name: 发布 | |
if: github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true # 只有被合并的 pr 才会 发布 | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: "dist/**" | |
body: "Update ${{ steps.tag_version.outputs.new_tag }}" | |
name: "Release ${{ steps.tag_version.outputs.new_tag }}" | |
tag_name: "${{ steps.tag_version.outputs.new_tag }}" | |
draft: false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment