Skip to content

Try to get correct env property #5

Try to get correct env property

Try to get correct env property #5

Workflow file for this run

# This workflow will build a Java project with Gradle, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Java CI with Gradle
on:
push:
branches: [ "main", "v3-gradle" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
name: Checkout
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Setup Gradle
uses: gradle/gradle-build-action@v3
- name: Build with Gradle
run: gradle clean build
container-image:
if: github.repository_owner == 'opentransportro' && github.event_name == 'push' && (github.ref == 'refs/heads/v3-gradle')
runs-on: ubuntu-latest
needs:
- build
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
cache: gradle
- name: Setup Gradle
uses: gradle/gradle-build-action@v3
- name: Build container image with Jib, push to Dockerhub
env:
CONTAINER_REPO: docker.io/otrro/transitclock-server-v3
CONTAINER_REGISTRY_USER: ${{secrets.DOCKER_USER}}
CONTAINER_REGISTRY_PASSWORD: ${{ secrets.DOCKER_AUTH }}
run: |
# we give the container two tags
# - "latest"
# - a string like "2.3_2022-12-12T21-38"
version_with_snapshot=`gradle properties -q | awk '/^version:/ {print $2}'`
version=${version_with_snapshot/-SNAPSHOT/}
image_version=${version}
## if the Gradle version contains SNAPSHOT, then add date to tag
if [[ $version_with_snapshot == *"SNAPSHOT"* ]]; then
image_date=`date +%Y-%m-%dT%H-%M`
image_version="${version}_${image_date}"
echo "Gradle version ${version_with_snapshot} contains SNAPSHOT, adding date to container image tag"
fi
gradle build jib -Djib.to.tags=latest,$image_version