From 7c5afce0b4c028bb8c7fb9f08e6ecedca5412ffb Mon Sep 17 00:00:00 2001 From: YoursFunny Date: Tue, 4 Aug 2026 01:58:19 +0800 Subject: [PATCH] ci: build once on tagged commits, bump docker actions --- .github/workflows/docker.yml | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index d60bc18..d508461 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -12,12 +12,35 @@ env: DOCKERHUB_REPO: yoursfunny/telegram-twitter-media-bot jobs: + # A tag push and a branch push to the same commit fire two workflow runs; + # build only once. Tag runs always build; master runs build only when the + # pushed commit is not already tagged (the tag run covers it). + should-build: + runs-on: ubuntu-latest + outputs: + build: ${{ steps.check.outputs.build }} + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + - id: check + shell: bash + run: | + if [ "$GITHUB_REF_TYPE" = "branch" ] && git tag --points-at "$GITHUB_SHA" | grep -q .; then + echo "commit already tagged; the tag run builds the image" + echo "build=false" >> "$GITHUB_OUTPUT" + else + echo "build=true" >> "$GITHUB_OUTPUT" + fi + docker: + needs: should-build + if: needs.should-build.outputs.build == 'true' runs-on: ubuntu-latest steps: - name: Docker meta id: meta - uses: docker/metadata-action@v5 + uses: docker/metadata-action@v6 with: images: ${{ env.DOCKERHUB_REPO }} tags: | @@ -28,22 +51,22 @@ jobs: type=sha - name: Set up QEMU - uses: docker/setup-qemu-action@v3 + uses: docker/setup-qemu-action@v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + uses: docker/setup-buildx-action@v4 - name: Login to Docker Hub - uses: docker/login-action@v3 + uses: docker/login-action@v4 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v7 with: push: true build-args: | APP_NAME=${{ env.APP_NAME }} tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file + labels: ${{ steps.meta.outputs.labels }}