Skip to content

update version

update version #4

name: Build & Push Docker image on package version change
on:
push:
branches: [ main, vcf_sanity_check ]
paths:
- DESCRIPTION
- .github/workflows/dockerhub-on-version.yml
workflow_dispatch:
# Cancel older runs of the same ref to save minutes
concurrency:
group: docker-${{ github.ref }}
cancel-in-progress: true
env:
IMAGE: docker.io/breedinginsight/bigapp
jobs:
check-version:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.ver.outputs.changed }}
version: ${{ steps.ver.outputs.version }}
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }
- id: ver
shell: bash
run: |
set -euo pipefail
cur_ver=$(sed -n 's/^Version:[[:space:]]*//p' DESCRIPTION | tr -d '[:space:]')
prev_sha="${{ github.event.before }}"
if git show "${prev_sha}:DESCRIPTION" >/dev/null 2>&1; then
prev_ver=$(git show "${prev_sha}:DESCRIPTION" | sed -n 's/^Version:[[:space:]]*//p' | tr -d '[:space:]')
else
prev_ver=""
fi
changed=false
if [[ -z "${prev_ver}" || "${cur_ver}" != "${prev_ver}" ]]; then changed=true; fi
echo "version=${cur_ver}" >> "$GITHUB_OUTPUT"
echo "changed=${changed}" >> "$GITHUB_OUTPUT"
build-amd64:
needs: check-version
if: needs.check-version.outputs.changed == 'true'
runs-on: ubuntu-latest
timeout-minutes: 350
env:
PKG_VERSION: ${{ needs.check-version.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
tags: |
type=raw,value=v${{ env.PKG_VERSION }}-amd64
type=raw,value=sha-${{ github.sha }}-amd64
- name: Build & push amd64
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=registry,ref=${{ env.IMAGE }}:buildcache-amd64
cache-to: type=registry,ref=${{ env.IMAGE }}:buildcache-amd64,mode=max
build-arm64:
needs: check-version
if: needs.check-version.outputs.changed == 'true' && github.ref_name == 'main'
runs-on: ubuntu-latest
timeout-minutes: 350
env:
PKG_VERSION: ${{ needs.check-version.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
tags: |
type=raw,value=v${{ env.PKG_VERSION }}-arm64
type=raw,value=sha-${{ github.sha }}-arm64
- name: Build & push arm64
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=registry,ref=${{ env.IMAGE }}:buildcache-arm64
cache-to: type=registry,ref=${{ env.IMAGE }}:buildcache-arm64,mode=max
manifest:
needs: [build-amd64, build-arm64]
if: github.ref_name == 'main' && needs.check-version.outputs.changed == 'true'
runs-on: ubuntu-latest
steps:
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Create multi-arch manifest
env:
PKG_VERSION: ${{ needs.check-version.outputs.version }}
run: |
docker buildx imagetools create \
-t $IMAGE:v${PKG_VERSION} -t $IMAGE:latest \
$IMAGE:v${PKG_VERSION}-amd64 \
$IMAGE:v${PKG_VERSION}-arm64