Skip to content

Commit

Permalink
Improve (or fix) release workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
AmauryCarrade committed Nov 24, 2020
1 parent 15bb316 commit 1dfa998
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 16 deletions.
21 changes: 14 additions & 7 deletions workflow-templates/release-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,23 @@ on:
tags:
- 'v*'

env:
JAVA_VERSION: 8

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Java
- name: Set up Java ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v1
with:
java-version: 8
java-version: ${{ env.JAVA_VERSION }}

- uses: actions/cache@v2
- name: Cache all the things
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand All @@ -44,16 +48,20 @@ jobs:
script: return context.repo.repo
result-encoding: string

- name: Publish to GitHub Packages
- name: Build and publish ${{ steps.project-name.outputs.result }} to GitHub Packages
id: maven-publish
run: |
TAG_NAME=${GIT_REF_NAME##*/}
REVISION_NAME=${TAG_NAME:1}
mvn -B deploy "-Drevision=$REVISION_NAME"
JAR_PATH=$(ls ./target/*.jar | tail -n 1)
# Maven shade keeps the unshaded JAR under target/original-vvv.jar
# We don't want to put this unshaded JAR in the release because it wouldn't
# work on a server.
JAR_PATH=$(ls ./target/*.jar | grep -vE "^./[^/]+/original-" | tail -n 1)
JAR_NAME=$(basename $JAR_PATH)
echo "::set-output name=jar_path::$JAR_PATH"
echo "::set-output name=jar_name::$JAR_NAME"
env:
Expand All @@ -71,7 +79,7 @@ jobs:
draft: true
prerelease: false

- name: Upload GitHub Release Asset
- name: Add ${{ steps.project-name.outputs.result }} JAR to GitHub Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -80,4 +88,3 @@ jobs:
asset_path: ${{ steps.maven-publish.outputs.jar_path }}
asset_name: ${{ steps.maven-publish.outputs.jar_name }}
asset_content_type: application/java-archive

38 changes: 29 additions & 9 deletions workflow-templates/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# To trigger, create a tag (not a release) with semantic
# versioning (the tag must start with a v).
#
# git tag -a v0.2 -m "Version 0.2"
# git push --tags
# git tag -am "Version 0.2" v0.2
# git push && git push --tags
#
# This workflow will automatically:
# - build the project using Maven;
Expand All @@ -17,19 +17,23 @@ on:
tags:
- 'v*'

env:
JAVA_VERSION: 8

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Java
- name: Set up Java ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v1
with:
java-version: 8
java-version: ${{ env.JAVA_VERSION }}

- uses: actions/cache@v2
- name: Cache all the things
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand All @@ -42,6 +46,23 @@ jobs:
script: return context.repo.repo
result-encoding: string

- name: Build ${{ steps.project-name.outputs.result }}
id: maven-build
run: |
mvn -B clean install
# Maven shade keeps the unshaded JAR under target/original-vvv.jar
# We don't want to put this unshaded JAR in the release because it wouldn't
# work on a server.
JAR_PATH=$(ls ./target/*.jar | grep -vE "^./[^/]+/original-" | tail -n 1)
JAR_NAME=$(basename $JAR_PATH)
echo "::set-output name=jar_path::$JAR_PATH"
echo "::set-output name=jar_name::$JAR_NAME"
env:
GIT_REF_NAME: ${{ github.ref }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create new GitHub Release
id: create-release
uses: actions/create-release@v1
Expand All @@ -53,13 +74,12 @@ jobs:
draft: true
prerelease: false

- name: Upload GitHub Release Asset
- name: Add ${{ steps.project-name.outputs.result }} JAR to GitHub Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.upload_url }}
asset_path: ${{ steps.maven-publish.outputs.jar_path }}
asset_name: ${{ steps.maven-publish.outputs.jar_name }}
asset_path: ${{ steps.maven-build.outputs.jar_path }}
asset_name: ${{ steps.maven-build.outputs.jar_name }}
asset_content_type: application/java-archive

0 comments on commit 1dfa998

Please sign in to comment.