From 56614e85197b26226574c496d64a36bafe66a165 Mon Sep 17 00:00:00 2001 From: Victoria Nadasdi Date: Sat, 20 Apr 2024 21:48:36 +0200 Subject: [PATCH] feat: auto-build image on new upstream tag Signed-off-by: Victoria Nadasdi --- .github/workflows/build-and-publish.yaml | 37 ++++++++++++++++++++++-- README.md | 2 +- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-publish.yaml b/.github/workflows/build-and-publish.yaml index 846e2f0..0031f60 100644 --- a/.github/workflows/build-and-publish.yaml +++ b/.github/workflows/build-and-publish.yaml @@ -7,10 +7,14 @@ on: description: Target Phanpy version required: true type: string + default: latest + schedule: + - cron: "0 */6 * * *" env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} + UPSTREAM: cheeaun/phanpy jobs: build_and_push_to_registry: @@ -20,28 +24,57 @@ jobs: contents: read packages: write steps: + - name: Check version + id: version + run: | + echo "### Status" >> ${GITHUB_STEP_SUMMARY} + + tag="${{ inputs.logLevel || 'latest' }}" + + if [[ "${tag}" == "latest" ]]; then + tag=$(curl -s https://api.github.com/repos/${UPSTREAM}/releases/latest \ + | jq --raw-output '.tag_name') + fi + + echo "value=${tag}" >> ${GITHUB_OUTPUT} + echo " - Tag: ${tag}" >> ${GITHUB_STEP_SUMMARY} + - uses: warjiang/setup-skopeo@main + - name: Check if tag needs_update + id: tag_check + run: | + if skopeo inspect docker://${REGISTRY}/${IMAGE_NAME}:${{ steps.version.outputs.value }}; then + echo ":green_square: We are up to date!" >> ${GITHUB_STEP_SUMMARY} + echo "needs_update=false" + else + echo ":red_square: **Update required!**" >> ${GITHUB_STEP_SUMMARY} + echo "needs_update=true" + fi - name: Checkout repository + if: ${{ steps.tag_check.outputs.needs_update == 'true' }} uses: actions/checkout@v4 - name: Log in to the Container registry + if: ${{ steps.tag_check.outputs.needs_update == 'true' }} uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata for Docker + if: ${{ steps.tag_check.outputs.needs_update == 'true' }} id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | - ${{ inputs.phanpy_version }} + ${{ steps.version.outputs.value }} latest - name: Build and push Docker image + if: ${{ steps.tag_check.outputs.needs_update == 'true' }} uses: docker/build-push-action@v5 with: context: . push: true build-args: | - VERSION=${{ inputs.phanpy_version }} + VERSION=${{ steps.version.outputs.value }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/README.md b/README.md index 0214914..152ac0d 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ docker run ghcr.io/yitsushi/phanpy-docker:latest version: "3.9" services: phanpy: - image: ghcr.io/cheeaun/phanpy:latest + image: ghcr.io/yitsushi/phanpy-docker:latest container_name: phanpy ports: - 8080:80