scheduled image build #52
This file contains hidden or 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: scheduled image build | |
| on: | |
| schedule: | |
| - cron: '0 10 * * 2' # Every tuesday at 10:00 UTC | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| packages: write | |
| contents: write | |
| steps: | |
| - name: Check out Git repository | |
| uses: actions/checkout@v6 | |
| - name: Fetch latest tag matching vX.X.X | |
| id: get_tag | |
| run: | | |
| git fetch --tags | |
| latest_tag=$(git tag --list 'v[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | head -n 1) | |
| echo "latest_tag=$latest_tag" >> $GITHUB_OUTPUT | |
| - name: Check out latest tag | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ steps.get_tag.outputs.latest_tag }} | |
| - name: Set up JDK | |
| uses: actions/setup-java@v5 | |
| with: | |
| java-version: "21" | |
| distribution: "temurin" | |
| cache: "maven" | |
| - name: Perform maven build | |
| run: mvn -B -ntp package -DskipTests | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to ghcr.io | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata (tags, labels) for image | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/${{ github.repository }} | |
| flavor: | | |
| latest=false | |
| prefix= | |
| suffix= | |
| tags: | | |
| type=semver,pattern={{version}},value=${{ steps.get_tag.outputs.latest_tag }} | |
| type=schedule,pattern={{date 'YYYYMMDD'}},prefix=${{ steps.get_tag.outputs.latest_tag }}- | |
| - name: Build and push image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ./microservice | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |