Skip to content

Commit

Permalink
chore(ci) Split the release in several jobs.
Browse files Browse the repository at this point in the history
The goal is to avoid calling `actions/create-release` more than once,
because it will fail.
  • Loading branch information
Hywan committed May 5, 2020
1 parent 789520d commit 210c1e5
Showing 1 changed file with 58 additions and 9 deletions.
67 changes: 58 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ on:
- '**'

jobs:
release:
name: Release
test:
name: Test

strategy:
matrix:
Expand Down Expand Up @@ -61,13 +61,16 @@ jobs:
export PATH="$HOME/.cargo/bin:$PATH"
make test
- name: Create the JAR
id: create_jar
shell: bash
run: |
export PATH="$HOME/.cargo/bin:$PATH"
make package
create_pre_release:
name: Release

needs: [test]

runs-on: ubuntu-latest

steps:
# The pre-release must be created only once, hence the split
# into multiple jobs with different `strategy`.
- name: Create a Github pre-release
id: create_pre_release
uses: actions/create-release@v1
Expand All @@ -79,12 +82,58 @@ jobs:
draft: false
prerelease: true

- name: Output `release_url` into a temporary file
run: echo "${{ steps.create_pre_release.outputs.upload_url }}" > release_url.txt

- name: Save the `release_url` temporary file
uses: actions/upload-artifact@v1
with:
name: release_url
path: release_url.txt

publish_jar:
name: Publish the JARs

needs: [create_pre_release]

strategy:
matrix:
# The job runs on 3 different OS.
os: [ubuntu-latest, macos-latest, windows-latest]
# The job runs on different Java versions (LTS).
java: [8]
# As soon as one job fails in the matrix, all the other
# in-progress jobs are canceled.
fail-fast: true

runs-on: ${{ matrix.os }}

steps:
- name: Create the JAR
id: create_jar
shell: bash
run: |
export PATH="$HOME/.cargo/bin:$PATH"
make package
- name: Load the `release_url` from the temporary file
uses: actions/download-artifact@v1
with:
name: release_url

- name: Read the `release_url` temporary file
id: get_release_info
shell: bash
run: |
value=$(cat release_url/release_url.txt)
echo ::set-output name=upload_url::$value
- name: Upload JAR as Github pre-release asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_pre_release.outputs.upload_url }}
upload_url: ${{ steps.get_release_info.outputs.upload_url }}
asset_path: ${{ steps.create_jar.outputs.path }}
asset_name: ${{ steps.create_jar.outputs.name }}
asset_content_type: application/java-archive

0 comments on commit 210c1e5

Please sign in to comment.