From 1a217e21e9bb845c729559c19c5746dab25b81a7 Mon Sep 17 00:00:00 2001 From: Dreamacro <305009791@qq.com> Date: Thu, 4 Jun 2020 10:38:30 +0800 Subject: [PATCH] Chore: use actions build docker image --- .github/workflows/docker.yml | 51 ++++++++++++++++++++++++++++++++++++ .github/workflows/go.yml | 8 +++--- 2 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..dec252b2 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,51 @@ +name: Publish Docker Image +on: + push: + branches: + - dev + tags: + - '*' +jobs: + + build: + name: Build + runs-on: ubuntu-latest + steps: + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + + - name: Set up docker buildx + id: buildx + uses: crazy-max/ghaction-docker-buildx@v2 + with: + buildx-version: latest + skip-cache: false + qemu-version: latest + + - name: Docker login + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + run: | + echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin + + - name: Docker buildx image and push on dev branch + if: github.ref == 'refs/heads/dev' + run: | + docker buildx build --output "type=image,push=true" --platform=linux/amd64,linux/arm/v7,linux/arm64 --tag dreamacro/clash:dev . + + - name: Replace tag without `v` + if: startsWith(github.ref, 'refs/tags/') + uses: actions/github-script@v1 + id: version + with: + script: | + return context.payload.ref.replace(/\/refs\/tags\//v, '') + result-encoding: string + + - name: Docker buildx image and push on release + if: startsWith(github.ref, 'refs/tags/') + run: | + docker buildx build --output "type=image,push=true" --platform=linux/amd64,linux/arm/v7,linux/arm64 --tag dreamacro/clash:${{steps.version.outputs.result}} . + docker buildx build --output "type=image,push=true" --platform=linux/amd64,linux/arm/v7,linux/arm64 --tag dreamacro/clash:latest . diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 1fd7f402..33aaded3 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -7,15 +7,15 @@ jobs: runs-on: ubuntu-latest steps: - name: Setup Go - uses: actions/setup-go@v1 + uses: actions/setup-go@v2 with: go-version: 1.14.x - name: Check out code into the Go module directory - uses: actions/checkout@v1 - + uses: actions/checkout@v2 + - name: Cache go module - uses: actions/cache@v1 + uses: actions/cache@v2 with: path: ~/go/pkg/mod key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}