Build Docker #550
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 Docker | |
on: | |
workflow_dispatch: | |
push: | |
tags: | |
- 'v*' | |
schedule: | |
- cron: '00 20 * * *' # runs daily at 20:00 UTC | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Required to count the commits | |
submodules: true | |
- name: Get new commits | |
run: echo "NEW_COMMIT_COUNT=$(git log --oneline --since '24 hours ago' | wc -l)" >> $GITHUB_ENV | |
- name: Get current date | |
id: date | |
run: echo "date=$(date +'%Y-%m-%d')" >> "$GITHUB_ENV" | |
- name: Set version Relese | |
if: github.event_name == 'push' | |
run: | | |
sed -i "s/\(project.version=\).*/\1${GITHUB_REF#refs/*/v}/g" src/main/resources/application.properties | |
- name: Set version Nightly | |
if: github.event_name != 'push' | |
run: | | |
sed -i "s/\(project.version=\).*/\1nightly-$date/g" src/main/resources/application.properties | |
- name: Set up QEMU | |
if: ${{ github.event_name != 'schedule' || env.NEW_COMMIT_COUNT > 0 }} | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
if: ${{ github.event_name != 'schedule' || env.NEW_COMMIT_COUNT > 0 }} | |
uses: docker/setup-buildx-action@v3 | |
- name: Docker meta | |
if: ${{ github.event_name != 'schedule' || env.NEW_COMMIT_COUNT > 0 }} | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=semver,pattern=v{{version}} | |
type=semver,pattern=v{{major}}.{{minor}} | |
type=schedule | |
type=schedule,pattern={{date 'YYYY-MM-DD'}} | |
type=ref,event=branch | |
- name: Log into registry ${{ env.REGISTRY }} | |
if: ${{ github.event_name != 'schedule' || env.NEW_COMMIT_COUNT > 0 }} | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push Docker image | |
if: ${{ github.event_name != 'schedule' || env.NEW_COMMIT_COUNT > 0 }} | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
platforms: linux/amd64,linux/arm64/v8 |