Publish master docker image #67
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: Publish master docker image | |
on: | |
workflow_dispatch: | |
inputs: | |
distinct_id: | |
description: 'run identifier' | |
required: false | |
env: | |
REGISTRY: ghcr.io | |
GITHUB_REPOSITORY: ${{ github.repository }} | |
jobs: | |
build-and-push-image: | |
environment: master | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
packages: write | |
steps: | |
- name: echo distinct ID ${{ github.event.inputs.distinct_id }} | |
run: echo ${{ github.event.inputs.distinct_id }} | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Merge develop -> master | |
run: | | |
git fetch | |
git checkout master | |
git pull | |
CHANGES=$(git log master..origin/develop --oneline) | |
if [[ -z "$CHANGES" ]]; then | |
echo "No changes to merge." | |
echo "has_changes=no" >> $GITHUB_ENV | |
else | |
git merge origin/develop | |
echo "has_changes=yes" >> $GITHUB_ENV | |
fi | |
- name: Push version changes to master | |
if: env.has_changes == 'yes' | |
uses: ad-m/github-push-action@master | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: master | |
- name: Resolve docker image name | |
if: env.has_changes == 'yes' | |
id: image_name | |
run: | | |
echo "IMAGE_NAME=${GITHUB_REPOSITORY@L}" >> $GITHUB_OUTPUT | |
- name: Log in to the Container registry | |
if: env.has_changes == 'yes' | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
if: env.has_changes == 'yes' | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ steps.image_name.outputs.IMAGE_NAME }} | |
- name: Resolve driver card authencicator version | |
if: env.has_changes == 'yes' | |
run: | | |
echo "CARD_AUTH_VERSION=$(curl -sS -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.PACKAGES_PAT }}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/orgs/Metatavu/packages/maven/fi.metatavu.vp.keycloak.vp-kuljetus-transport-management-driver-card-keycloak-auth-provider/versions|jq '.[].name'|grep -v develop|grep -v SNAPSHOT|head -n 1|sed 's/"//g')" >> $GITHUB_ENV | |
- name: Download driver card authencicator | |
if: env.has_changes == 'yes' | |
run: | | |
mkdir -p providers && | |
curl -L "https://${{ secrets.PACKAGES_PAT }}@maven.pkg.github.com/Metatavu/vp-kuljetus-transport-management-driver-card-keycloak-auth-provider/fi/metatavu/vp/keycloak/vp-kuljetus-transport-management-driver-card-keycloak-auth-provider/${{ env.CARD_AUTH_VERSION }}/vp-kuljetus-transport-management-driver-card-keycloak-auth-provider-${{ env.CARD_AUTH_VERSION }}.jar" -o providers/driver-card-keycloak-auth-provider.jar | |
- name: Build and push Docker image | |
if: env.has_changes == 'yes' | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
file: Dockerfile | |
tags: ${{ steps.meta.outputs.tags }},${{ env.REGISTRY }}/${{ steps.image_name.outputs.IMAGE_NAME }}:latest | |
labels: ${{ steps.meta.outputs.labels }} |