Build and publish to demo #18
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
name: Build and publish to demo | |
on: | |
workflow_dispatch: # execute manually | |
schedule: # it's important that the hour in the cron-job is after the hour of project_start_date in step calculate-time-passed | |
- cron: '0 13 * * 6' # execute automatically every Saturday at 13:00, change!! day of week if needed | |
env: | |
SPRINT_LENGTH_IN_WEEKS: 3 | |
jobs: | |
build-and-docker-push: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get seconds passed since project start # project_start_date needs to be changed!! if different dispatch day is preferred | |
id: calculate-time-passed | |
run: | # 2023-10-28 is a Saturday and is used as the base for calculating the weeks passed | |
project_start_date=$(echo -n "2023-10-28 10:00") # it's important that the hour in this step is before the hour given in the cron-job | |
project_start_epoch_seconds=$(date -d "$project_start_date" +%s) | |
time_passed=$(($(date +"%s")-$project_start_epoch_seconds)) | |
echo "::set-output name=time_passed::$time_passed" | |
- name: Get number of weeks passed | |
id: get-number-of-weeks | |
run: | # 604800 is 1 week in seconds | |
num_weeks_mod_sprint=$(((${{ steps.calculate-time-passed.outputs.time_passed }}/604800)%${{ env.SPRINT_LENGTH_IN_WEEKS }})) | |
echo "::set-output name=num_weeks_mod_sprint::$num_weeks_mod_sprint" | |
- name: Check if job should be run # the automatically triggered actions should only be executed at the end of a sprint | |
if: github.event_name != 'workflow_dispatch' && steps.get-number-of-weeks.outputs.num_weeks_mod_sprint != 0 | |
run: | # canceling the job if the conditions weren't met, https://stackoverflow.com/a/75809743 | |
gh run cancel ${{ github.run_id }} | |
gh run watch ${{ github.run_id }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Git checkout to main branch # the workflow is triggered in the default branch, which doesn't have to be MAIN | |
uses: actions/checkout@v4 | |
with: { ref: main } # this also serves as a safeguard for workflows triggered manually | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Build with Maven | |
run: mvn --update-snapshots -f pom.xml verify | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
tags: ghcr.io/it-at-m/mobidam-s3-eai:demo |