Merge pull request #137 #366
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Build Java JAR and publish as Docker image to Docker Hub. | |
# | |
# Adopted from | |
# | |
# - https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle | |
# - | |
name: Build and Publish | |
on: | |
workflow_dispatch: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
jobs: | |
build-and-test: | |
name: Build and Test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
- name: Build and Test with Gradle | |
uses: gradle/gradle-build-action@v2 | |
with: | |
arguments: clean build test cucumber jacocoTestReport | |
- name: Attach JAR as Build Artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: train-delays-0.0.1-SNAPSHOT.jar | |
path: build/libs/train-delays-0.0.1-SNAPSHOT.jar | |
- name: Attach Test Results as Build Artifacts | |
if: always() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: test-results | |
path: | | |
build/reports/jacoco/test | |
build/reports/tests | |
publish-reports: | |
name: Publish Test Reports | |
runs-on: ubuntu-latest | |
# Repository secrets may only be used when running on the controlled main branch | |
# otherwise we run the risk of exposing secrets to a malicious attacker | |
# AND | |
# Ensure this job never runs on forked repos. It's only executed for 'dspace/dspace' | |
if: github.ref == 'refs/heads/main' && github.repository == 'wonderbird/train-delays' | |
needs: build-and-test | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
- name: Download Test Results | |
uses: actions/download-artifact@v3 | |
with: | |
name: test-results | |
path: build/reports | |
- name: Report Coverage to Coveralls | |
uses: gradle/gradle-build-action@0d13054264b0bb894ded474f08ebb30921341cee | |
env: | |
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} | |
with: | |
arguments: coveralls | |
- name: Report Coverage to CodeClimate | |
uses: paambaati/codeclimate-action@v3.0.0 | |
env: | |
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} | |
JACOCO_SOURCE_PATH: "src/main/java" | |
with: | |
coverageLocations: build/reports/jacoco/test/jacocoTestReport.xml:jacoco | |
publish-docker-image: | |
# Documentation: https://docs.github.com/en/actions/publishing-packages/publishing-docker-images | |
name: Publish Docker Image | |
runs-on: ubuntu-latest | |
# Repository secrets may only be used when running on the controlled main branch | |
# otherwise we run the risk of exposing secrets to a malicious attacker | |
# AND | |
# Ensure this job never runs on forked repos. It's only executed for 'dspace/dspace' | |
if: github.ref == 'refs/heads/main' && github.repository == 'wonderbird/train-delays' | |
needs: build-and-test | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Download JAR | |
uses: actions/download-artifact@v3 | |
with: | |
name: train-delays-0.0.1-SNAPSHOT.jar | |
path: build/libs | |
- name: Log in to Docker Hub | |
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 | |
with: | |
images: boos/train-delays | |
tags: type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |