Check for new Release #37
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: Check for new Release | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 20 * * *' # Run every day | |
jobs: | |
check-release: | |
runs-on: ubuntu-latest | |
outputs: | |
new_release: ${{ steps.release.outputs.new_release }} | |
current_release: ${{ steps.release.outputs.current_release }} | |
steps: | |
- name: Login to GitHub Container Registry | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
- name: Get current release from container repository | |
id: current | |
run: | | |
repo_owner=${{ github.repository_owner }} | |
repo_name=${{ github.repository }} | |
package_type="container" | |
package_name=${{ github.repository}} | |
current_release=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/orgs/$repo_owner/packages/$package_type/$package_name/versions" | jq -r '.[0].metadata.container.tags[0]' | sed 's/-arm64//') | |
# Set to empty string if no container exists yet | |
current_release=${current_release:-""} | |
echo "Current release in the container repository: $current_release" | |
echo "current_release=$current_release" >> $GITHUB_OUTPUT | |
- name: Check for new releases | |
id: release | |
run: | | |
latest_release=$(curl -s https://api.github.com/repos/keycloak/keycloak/releases/latest | jq -r '.tag_name') | |
echo "latest release: $latest_release" | |
if [ "$latest_release" != "${{ steps.current.outputs.current_release }}" ]; then | |
echo "New release found." | |
echo "new_release=true" >> $GITHUB_OUTPUT | |
echo "current_release=$latest_release" >> $GITHUB_OUTPUT | |
else | |
echo "No new releases found. Exiting." | |
exit 0 | |
fi | |
build: | |
needs: check-release | |
if: ${{ needs.check-release.outputs.new_release == 'true' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out Keycloak-Containers | |
uses: actions/checkout@master | |
with: | |
repository: keycloak/keycloak | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v1 | |
with: | |
platforms: linux/amd64,linux/arm64 | |
- name: Setup Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Log in to registry | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
- name: build & push image (keycloak:latest) | |
uses: docker/build-push-action@v5 | |
env: | |
CURRENT_RELEASE: ${{ needs.check-release.outputs.current_release }} | |
with: | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
file: ./quarkus/container/Dockerfile | |
context: ./quarkus/container/ | |
build-args: | | |
KEYCLOAK_VERSION=${{ env.CURRENT_RELEASE }} | |
KEYCLOAK_DIST=https://github.com/keycloak/keycloak/releases/download/${{ env.CURRENT_RELEASE }}/keycloak-${{ env.CURRENT_RELEASE }}.tar.gz | |
tags: | | |
ghcr.io/opencirclepkgs/keycloak:latest, ghcr.io/opencirclepkgs/keycloak:${{ env.CURRENT_RELEASE }} | |