From 0a363bea0478b64a2aa42475abcd6579e7c2542c Mon Sep 17 00:00:00 2001 From: KwokRonny Date: Thu, 4 Jul 2024 14:30:46 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20=E4=BC=98=E5=8C=96=E5=8F=8A?= =?UTF-8?q?=E6=8B=86=E5=88=86CI=E6=9E=84=E5=BB=BA=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0dockerhub=E6=BA=90=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-doc.yml | 1 - .github/workflows/publish-image.yml | 53 +++++++++++++++++++ .../{docker-image.yml => release.yml} | 15 +----- 3 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/publish-image.yml rename .github/workflows/{docker-image.yml => release.yml} (70%) diff --git a/.github/workflows/deploy-doc.yml b/.github/workflows/deploy-doc.yml index ed7832c..e444208 100644 --- a/.github/workflows/deploy-doc.yml +++ b/.github/workflows/deploy-doc.yml @@ -6,7 +6,6 @@ on: paths: - 'packages/docs/**' - 'CHANGELOG.md' - - ".github/workflows/deploy-doc.yml" jobs: build: diff --git a/.github/workflows/publish-image.yml b/.github/workflows/publish-image.yml new file mode 100644 index 0000000..a1b89d7 --- /dev/null +++ b/.github/workflows/publish-image.yml @@ -0,0 +1,53 @@ +name: Docker Publish on Tag + +on: + push: + tags: + - 'v*.*.*' # 只有符合vX.Y.Z格式的标签才会触发此工作流 + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker image tags + id: tag + run: | + echo ::set-output name=tag::${GITHUB_REF#refs/tags/} + echo ::set-output name=version::${GITHUB_REF#refs/tags/v} + + - name: Build and push to Docker Hub + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + push: true + tags: | + kwokronny68/roadbook:${{ steps.tag.outputs.version }} + kwokronny68/roadbook:latest + + - name: Build and push to GitHub Container Registry + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + push: true + tags: | + ghcr.io/kwokronny/roadbook:${{ steps.tag.outputs.version }} + ghcr.io/kwokronny/roadbook:latest \ No newline at end of file diff --git a/.github/workflows/docker-image.yml b/.github/workflows/release.yml similarity index 70% rename from .github/workflows/docker-image.yml rename to .github/workflows/release.yml index 83b5433..260c877 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Docker Image CI +name: Release on: push: @@ -7,7 +7,6 @@ on: - "packages/roadbook-api/**" - "packages/roadbook-vue/**" - "Dockerfile" - - ".github/workflows/docker-image.yml" jobs: @@ -45,15 +44,3 @@ jobs: git tag v${{env.RELEASE}} git push origin v${{env.RELEASE}} - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build & Publish Docker Image - uses: docker/build-push-action@v5 - with: - push: true - tags: ghcr.io/kwokronny/roadbook:latest, ghcr.io/kwokronny/roadbook:${{ env.RELEASE }}