From be6f51410bd37bd3db140f157b6c047b2eca2717 Mon Sep 17 00:00:00 2001 From: HUANGDADA Date: Fri, 4 Sep 2026 10:45:41 +0800 Subject: [PATCH] ci: publish Docker image to GHCR --- .github/workflows/test.yml | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dff9e3f..ceca122 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: test +name: test-and-publish on: push: @@ -7,6 +7,10 @@ on: permissions: contents: read + packages: write + +env: + IMAGE_NAME: ghcr.io/coderdoubleflower/sub2apiauditer jobs: pytest: @@ -27,8 +31,33 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - uses: docker/setup-qemu-action@v3 - uses: docker/setup-buildx-action@v3 - - uses: docker/build-push-action@v6 + + - name: Log in to GHCR + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.IMAGE_NAME }} + tags: | + type=raw,value=latest,enable=${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} + type=sha,format=short + + - name: Build and optionally publish image + uses: docker/build-push-action@v6 with: context: . - push: false + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max