简体   繁体   中英

Github Actions: Multiple jobs single release

I am having 2 jobs in the Github runner. The first job builds the android apk. The second one to build a zip file. I want to have both the apk and the zip file in the same release. But after the apk is published into a release, the zip file does not get published into the release. The error shown is:
Validation Failed {"resource":"Release","code":"already_exists","field":"tag_name"}
buid.yml :

name: Build Process

on:
 push:
  tags:
   - v*

jobs:
 Build_Android:
if: "!contains(github.event.head_commit.message, 'skip-android')"
name: Build APK
runs-on: ubuntu-latest

steps:
  - uses: actions/checkout@v2
  - name: Setup Java
    uses: actions/setup-java@v2
    with:
      distribution: "zulu"
      java-version: "12.x"

  - name: Setup Flutter
    uses: subosito/flutter-action@v1
    with:
      channel: "stable"

  - name: Get Packages
    run: flutter pub get

  - name: Build APK
    run: flutter build apk --split-per-abi --release

  - name: Create Github Release
    uses: ncipollo/release-action@v1
    with:
      artifacts: "build/app/outputs/flutter-apk/*.apk"
      replacesArtifacts: false
      token: ${{ secrets.TOKEN }}

Build_Windows:
if: "!contains(github.event.head_commit.message, 'skip-windows')"
name: Building zip
runs-on: windows-latest

steps:
  - uses: actions/checkout@v2
  - name: Setup Java
    uses: actions/setup-java@v2
    with:
      distribution: "zulu"
      java-version: "12.x"

  - name: Setup Flutter
    uses: subosito/flutter-action@v1
    with:
      channel: "stable"

  - name: Get Packages
    run: flutter pub get

  - name: Enable windows build
    run: flutter config --enable-windows-desktop

  - name: Build Artifacts
    run: flutter build windows --release

  - name: Archive Artifacts
    uses: thedoctor0/zip-release@master
    with:
      type: "zip"
      filename: AppName-${{github.ref_name}}-windows.zip
      directory: build/windows/runner/Release

  - name: Create Github Release
    uses: ncipollo/release-action@v1
    with:
      artifacts: "build/windows/runner/Release/AppName-${{github.ref_name}}-windows.zip"
      replacesArtifacts: false
      token: ${{ secrets.TOKEN }}

Any help is greatly appreciated!
Thank!

The error says that:

Release with this tag name already exists

It is coming from your last step:

ncipollo/release-action@v1

By default this action seems to be always trying to create a new release ("This action will create a GitHub release"), but according to its documentation here you can alter that behaviour by adding:

allowUpdates = "true"

- name: Create Github Release
  uses: ncipollo/release-action@v1
  with:
    artifacts: "build/windows/runner/Release/AppName-${{github.ref_name}}-windows.zip"
    replacesArtifacts: false
    token: ${{ secrets.TOKEN }}
    allowUpdates: true

I faced a similar situation when I wanted to publish windows and linux binaries, all in a same release. And finally I came to the conclusion that I should solve this by organizing the jobs flows. I changed my yml file so that

  • I had a separate job for each deployment that only produces it's own artifacts (ex. Windows_Publish and Linux_publish jobs)
  • Each of these jobs, persists it's generated artifacts. But all jobs use same name and path for it. So all artifacts would be accumulated in one place.
  • I had a third job (say Deploy_Artifacts job) that restores all those artifacts and simply deploys them all at once.
  • NOTE that the Deploy_Artifacts job, had to depend on both Windows_Publish and Linux_publish jobs. (needs: [Deploy_Artifacts,Windows_Publish])

I used actions/upload-artifact@master for persistence and restoring artifacts [See] and ncipollo/release-action@v1 for sending the artifacts to release. And [this] is the yml file I finally came up with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM