From 2ae2878efe284c98e5317ea9307b213dd4f6515c Mon Sep 17 00:00:00 2001 From: elliotxx <951376975@qq.com> Date: Fri, 13 May 2022 21:56:38 +0800 Subject: [PATCH 1/2] chore: refine workflow configurations --- .github/workflows/release.yaml | 55 +++++++++++++++++++++++++++++----- .github/workflows/test.yaml | 47 ++++++++++++++--------------- 2 files changed, 71 insertions(+), 31 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index a7fb030..c232278 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -3,13 +3,57 @@ name: Release on: push: + branches: + - main tags: - "v*" permissions: contents: write jobs: - goreleaser: + Test: + name: Unit tests with coverage runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up Go 1.17 + uses: actions/setup-go@v2 + with: + go-version: 1.17 + - name: Running go tests with coverage + env: + GO111MODULE: on + run: make cover + - name: Send coverage + uses: shogo82148/actions-goveralls@v1 + with: + path-to-profile: coverage.out + Lint: + name: Lint checks + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up Go 1.17 + uses: actions/setup-go@v2 + with: + go-version: 1.17 + - name: Download golangci-lint + run: | + wget https://github.com/golangci/golangci-lint/releases/download/v1.41.0/golangci-lint-1.41.0-linux-amd64.tar.gz + tar -xvf ./golangci-lint-1.41.0-linux-amd64.tar.gz + - name: Running golangci-lint + env: + GO111MODULE: on + GOPATH: /home/runner/work/ + run: GOLINTER=./golangci-lint-1.41.0-linux-amd64/golangci-lint make lint + Publish: + runs-on: ubuntu-latest + needs: [Test, Lint] steps: - name: Checkout uses: actions/checkout@v2 @@ -21,19 +65,16 @@ jobs: go-version: 1.17 - name: Login to Docker Hub if: startsWith(github.ref, 'refs/tags/v') - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - # TODO: default GITHUB_TOKEN insufficient permissions + # Publish image to Docker Hub, changelog and package to Github Release by GoReleaser - name: Run GoReleaser uses: goreleaser/goreleaser-action@v2 with: - # either 'goreleaser' (default) or 'goreleaser-pro' distribution: goreleaser version: latest args: release --rm-dist env: - GITHUB_TOKEN: ${{ secrets.GH_PAT }} - # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution - # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GH_PAT }} \ No newline at end of file diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 047f5bf..5a4e39f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,39 +10,38 @@ on: - main jobs: - test: + Test: name: Unit tests with coverage - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest] + runs-on: ubuntu-latest steps: - - name: Set up Go 1.17 - uses: actions/setup-go@v2 - with: - go-version: 1.17 - id: go - - name: Check out code into the Go module directory - uses: actions/checkout@main - - name: Running go tests with coverage - env: - GO111MODULE: on - run: make cover - - name: Send coverage - uses: shogo82148/actions-goveralls@v1 - with: - path-to-profile: coverage.out - lint: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up Go 1.17 + uses: actions/setup-go@v2 + with: + go-version: 1.17 + - name: Running go tests with coverage + env: + GO111MODULE: on + run: make cover + - name: Send coverage + uses: shogo82148/actions-goveralls@v1 + with: + path-to-profile: coverage.out + Lint: name: Lint checks runs-on: ubuntu-latest steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Set up Go 1.17 uses: actions/setup-go@v2 with: go-version: 1.17 - id: go - - name: Check out code into the Go module directory - uses: actions/checkout@main - name: Download golangci-lint run: | wget https://github.com/golangci/golangci-lint/releases/download/v1.41.0/golangci-lint-1.41.0-linux-amd64.tar.gz From c83a9609f29b77342cb1896f151b6d45751bc014 Mon Sep 17 00:00:00 2001 From: elliotxx <951376975@qq.com> Date: Fri, 13 May 2022 22:00:25 +0800 Subject: [PATCH 2/2] chore: remove push branch condition in release.yaml --- .github/workflows/release.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c232278..43e7be9 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -3,8 +3,6 @@ name: Release on: push: - branches: - - main tags: - "v*" permissions: