Skip to content

Commit

Permalink
Release workflow (#10)
Browse files Browse the repository at this point in the history
Add automatic release deployment to t2iapi for both Java and Python.
Tags will be released as pre-releases on github, unless they begin with
a "v", in which case they are considered proper releases and won't
include a build number in the deployments.

# Checklist

The following aspects have been respected by the author of this pull
request, confirmed by both pull request assignee **and** reviewer:

* Changelog update (necessity checked and entry added or not added
respectively)
  * [x] Pull Request Assignee
  * [x] Reviewer
* README update (necessity checked and entry added or not added
respectively)
  * [x] Pull Request Assignee
  * [x] Reviewer
  • Loading branch information
ldeichmann authored Nov 22, 2022
1 parent b166700 commit 5cfe677
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 8 deletions.
44 changes: 42 additions & 2 deletions .github/workflows/build-java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:

env:
GRADLE_VERSION: 7.5.1
RELEASE_VERSION: 0

jobs:
build-java:
Expand All @@ -17,6 +18,10 @@ jobs:
working-directory: config
run: |
cat versions.txt >> $GITHUB_ENV
- name: Detect release version
if: startsWith(github.ref, 'refs/tags/v')
run: |
echo RELEASE_VERSION=1 >> $GITHUB_ENV
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
Expand Down Expand Up @@ -49,6 +54,10 @@ jobs:
with:
name: target_jars
path: java/build/libs/
- name: Detect release version
if: startsWith(github.ref, 'refs/tags/v')
run: |
echo RELEASE_VERSION=1 >> $GITHUB_ENV
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
Expand All @@ -69,15 +78,25 @@ jobs:
deploy-github-packages:
runs-on: ubuntu-latest
needs: run-tests-java11
if: github.ref == 'refs/heads/main'
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
permissions:
packages: write
contents: write
steps:
- uses: actions/checkout@v3
- name: Source dependency versions
working-directory: config
run: |
cat versions.txt >> $GITHUB_ENV
- name: Download t2iapi test results artifact
uses: actions/download-artifact@v3
with:
name: test_results
path: test_results/
- name: Detect release version
if: startsWith(github.ref, 'refs/tags/v')
run: |
echo RELEASE_VERSION=1 >> $GITHUB_ENV
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
Expand All @@ -95,4 +114,25 @@ jobs:
working-directory: ./java
run: ./gradlew publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install zip
if: startsWith(github.ref, 'refs/tags/')
uses: montudor/action-zip@v1

- name: Zip test results
if: startsWith(github.ref, 'refs/tags/')
run: |
zip -qq -r java-test-results.zip test_results
- name: Attach artifacts to github release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
CHANGELOG.md
java/build/libs/*.jar
java/build/publications/maven/pom-default.xml
java-test-results.zip
prerelease: ${{ !startsWith(github.ref, 'refs/tags/v') }}
body_path: CHANGELOG.md
24 changes: 22 additions & 2 deletions .github/workflows/build-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ env:
PIP_VERSION: 22.0.4
WHEEL_VERSION: 0.37.0
HTML_TEST_RUNNER_VERSION: 1.2.1
RELEASE_VERSION: 0

jobs:
build-python:
Expand All @@ -20,6 +21,10 @@ jobs:
working-directory: config
run: |
cat versions.txt >> $GITHUB_ENV
- name: Detect release version
if: startsWith(github.ref, 'refs/tags/v')
run: |
echo RELEASE_VERSION=1 >> $GITHUB_ENV
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
Expand Down Expand Up @@ -75,15 +80,30 @@ jobs:
retention-days: 1
deploy-pypi-packages:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
needs: run-tests-python
permissions:
contents: write
steps:
- name: Download t2iapi wheel artifact
uses: actions/download-artifact@v3
with:
name: dist
path: dist/
- name: Download t2iapi test results artifact
uses: actions/download-artifact@v3
with:
name: html_unit_test
path: unittest_results/
- name: Publish t2iapi to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Attach artifacts to github release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
dist/*.whl
unittest_results/*.html
prerelease: ${{ !startsWith(github.ref, 'refs/tags/v') }}
7 changes: 5 additions & 2 deletions java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ val configFileMap = configFile.associate { it.split("=")[0] to it.split("=")[1]

val protocVersion = configFileMap["JAVA_PROTOC_VERSION"]
val grpcVersion = configFileMap["JAVA_GRPC_VERSION"]
val baseVersion = configFileMap["BASE_PACKAGE_VERSION"]
val baseVersion = configFileMap["BASE_PACKAGE_VERSION"]!!
val buildId: String? = System.getenv("GITHUB_RUN_NUMBER")
val t2iapiVersion = baseVersion + ( buildId?.let { ".$it" } ?: "" )
val t2iapiVersion: String = when (System.getenv("RELEASE_VERSION") == "1") {
true -> baseVersion
false -> baseVersion + ( buildId?.let { ".$it" } ?: "" )
}

version = t2iapiVersion
group = "com.draeger.medical"
Expand Down
3 changes: 3 additions & 0 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def get_build_version():
@return: package version
"""
package = os.getenv('BASE_PACKAGE_VERSION', default='0.0.0')
is_release_version = os.getenv("RELEASE_VERSION") == "1"
if is_release_version:
return package
dev_release_segment = f'dev{os.getenv("GITHUB_RUN_NUMBER", default=0)}'
return f'{package}.{dev_release_segment}'

Expand Down
7 changes: 5 additions & 2 deletions tests/java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ val configFile = File("../../config/versions.txt").readLines()
val configFileMap = configFile.associate { it.split("=")[0] to it.split("=")[1] }

val grpcVersion = configFileMap["JAVA_GRPC_VERSION"]
val baseVersion = configFileMap["BASE_PACKAGE_VERSION"]
val baseVersion = configFileMap["BASE_PACKAGE_VERSION"]!!
val buildId: String? = System.getenv("GITHUB_RUN_NUMBER")
val t2iapiVersion = baseVersion + ( buildId?.let { ".$it" } ?: "" )
val t2iapiVersion: String = when (System.getenv("RELEASE_VERSION") == "1") {
true -> baseVersion
false -> baseVersion + ( buildId?.let { ".$it" } ?: "" )
}

dependencies {
testImplementation("io.grpc:grpc-protobuf:${grpcVersion}")
Expand Down

0 comments on commit 5cfe677

Please sign in to comment.