From ca7effe2e89f741d02234adbc07fba8bcec2d71a Mon Sep 17 00:00:00 2001 From: Myth Date: Mon, 25 Sep 2023 18:25:33 +0800 Subject: [PATCH] ci: separate build.yml and docker.yml from main.yml --- .github/workflows/{main.yml => build.yml} | 48 ++---------------- .github/workflows/docker.yml | 61 +++++++++++++++++++++++ 2 files changed, 65 insertions(+), 44 deletions(-) rename .github/workflows/{main.yml => build.yml} (70%) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/main.yml b/.github/workflows/build.yml similarity index 70% rename from .github/workflows/main.yml rename to .github/workflows/build.yml index 072ae23..b0f90bc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/build.yml @@ -12,6 +12,10 @@ on: pull_request: types: - opened + paths: + - "**/*.go" + - "go.mod" + - "go.sum" permissions: write-all @@ -125,47 +129,3 @@ jobs: GITHUB_TOKEN: ${{ github.token }} run: | gh release upload ${{ github.event.release.tag_name }} zju-connect-${{ steps.get_filename.outputs.ASSET_NAME }}.zip - - - # https://github.com/docker/setup-qemu-action - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - # https://github.com/docker/setup-buildx-action - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v2 - - # https://github.com/docker/login-action - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - # https://github.com/docker/metadata-action - - name: Docker meta - id: meta - uses: docker/metadata-action@v3 - with: - images: | - mythologyli/zju-connect - tags: | - type=schedule - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - type=sha - type=raw,value=latest - - # https://github.com/docker/build-push-action - - name: Build and push - uses: docker/build-push-action@v3 - with: - context: . - platforms: linux/amd64,linux/arm64 - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..23f5577 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,61 @@ +name: Publish Docker image + +on: + release: + types: [ published ] + push: + paths: + - "**/*.go" + - "go.mod" + - "go.sum" + - ".github/workflows/*.yml" + +permissions: write-all + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout codebase + uses: actions/checkout@v3 + + # https://github.com/docker/setup-qemu-action + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + # https://github.com/docker/setup-buildx-action + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + + # https://github.com/docker/login-action + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + # https://github.com/docker/metadata-action + - name: Docker meta + id: meta + uses: docker/metadata-action@v3 + with: + images: | + mythologyli/zju-connect + tags: | + type=schedule + type=ref,event=branch + type=semver,pattern={{version}},enable=${{ github.event_name == 'release' }} + type=sha + type=raw,value=latest,enable=${{ github.event_name == 'release' }} + + # https://github.com/docker/build-push-action + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }}