NiceLeeのBlog 用爱发电 bilibili~

一次GitHub Action自动化发布集成部署(Java 篇)

2020-04-08
nIceLee

阅读:


一直发布release都是手动编译打包再上传,捣鼓了一下,可以解放了。。

参考

GitHub Action 入门教程
官方语法文档

简单实现

# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java#apache-maven-with-a-settings-path

name: CI

on:
  ## 触发条件, release.json有被修改
  push:
    paths:
      # Trigger only when src/** changes
      - ".github/release.json"
      
  pull_request:
    paths:
    # Trigger only when src/** changes
      - ".github/release.json"

jobs:
  build:

    runs-on: ubuntu-latest
   
    steps:
    ## 取出项目代码,设置java环境
    - uses: actions/checkout@v2
    - name: Set up JDK 1.8
      uses: actions/setup-java@v1
      with:
        java-version: 1.8
    
    ## 从release.json 读取相关信息
    - name: Read tag_main
      id: tag_main
      uses:  ashley-taylor/read-json-property-action@v1.0
      with:
        path: ./.github/release.json
        property: tag_main
    
    - name: Read tag_latest
      id: tag_latest
      uses:  ashley-taylor/read-json-property-action@v1.0
      with:
        path: ./.github/release.json
        property: tag_latest
        
    - name: Read description
      id: description
      uses: juliangruber/read-file-action@v1
      with:
        path: ./.github/release.info
 
    ## 打包项目jar包
    - name: MVN Package
      run: |
        mvn -B package assembly:single --file pom.xml -Dmaven.test.skip=true

    ## 将jar包和其它相关文件打包压缩
    - name: ZIP files
      run: |
        mv -f ./target/live-record-${ {steps.tag_main.outputs.value}}-jar-with-dependencies.jar BiliLiveRecorder.jar
        rm -rf ./plugin
        rm -rf ./LICENSE
        mkdir ./plugin/
        mkdir ./LICENSE/
        mv -f ./release/run-zhanqi.bat .
        mv -f ./release/run-yy.bat .
        mv -f ./release/run-kuaishou.bat .
        mv -f ./release/run-huya.bat .
        mv -f ./release/run-douyu.bat .
        mv -f ./release/run-bili.bat .
        mv -f ./release/checkFlv.splitScripts.bat .
        mv -f ./release/checkFlv.bat .
        mv -f ./release/plugin/* ./plugin/
        mv -f ./release/LICENSE/* ./LICENSE/        
        
        zip BilibiliLiveRecord\ v${ {steps.tag_latest.outputs.value}}.zip BiliLiveRecorder.jar
        zip -m BilibiliLiveRecord\ v${ {steps.tag_latest.outputs.value}}.zip ./run-zhanqi.bat
        zip -m BilibiliLiveRecord\ v${ {steps.tag_latest.outputs.value}}.zip ./run-yy.bat
        zip -m BilibiliLiveRecord\ v${ {steps.tag_latest.outputs.value}}.zip ./run-kuaishou.bat
        zip -m BilibiliLiveRecord\ v${ {steps.tag_latest.outputs.value}}.zip ./run-huya.bat
        zip -m BilibiliLiveRecord\ v${ {steps.tag_latest.outputs.value}}.zip ./run-douyu.bat
        zip -m BilibiliLiveRecord\ v${ {steps.tag_latest.outputs.value}}.zip ./run-bili.bat
        zip -m BilibiliLiveRecord\ v${ {steps.tag_latest.outputs.value}}.zip ./checkFlv.bat
        zip -m BilibiliLiveRecord\ v${ {steps.tag_latest.outputs.value}}.zip ./checkFlv.splitScripts.bat
        zip -rm BilibiliLiveRecord\ v${ {steps.tag_latest.outputs.value}}.zip ./plugin/
        zip -rm BilibiliLiveRecord\ v${ {steps.tag_latest.outputs.value}}.zip ./LICENSE/
    
    ## 发布Release
    - name: Create Release
      id: create_release
      uses: actions/create-release@latest
      env:
        GITHUB_TOKEN: ${ { secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
      with:
        tag_name: V${ {steps.tag_latest.outputs.value}}
        release_name: BiliLiveRecorder - v${ {steps.tag_latest.outputs.value}}
        body: |
          ${ {steps.description.outputs.content}}
        draft: false
        prerelease: false

    ## 上传附件
    - name: Upload Release Asset
      id: upload-release-asset
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${ { secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${ { steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
        asset_path: ./BilibiliLiveRecord v${ {steps.tag_latest.outputs.value}}.zip
        asset_name: BilibiliLiveRecord.v${ {steps.tag_latest.outputs.value}}.zip
        asset_content_type: application/zip

内容
隐藏