From b9e1557a786522728827afdaba0936d787fb63fe Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Thu, 13 Apr 2023 13:29:03 -0400 Subject: [PATCH] .github/workflows: Refresh and modernize workflows (#265) Verified locally via `act pull_request`. --- .github/workflows/incoming.yaml | 56 --------------------------------- .github/workflows/release.yaml | 54 ++++++++++++++----------------- .github/workflows/test.yaml | 47 +++++++++++++++++++++++++++ .goreleaser.yml | 8 +++++ 4 files changed, 78 insertions(+), 87 deletions(-) delete mode 100644 .github/workflows/incoming.yaml create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/incoming.yaml b/.github/workflows/incoming.yaml deleted file mode 100644 index f5b75c37..00000000 --- a/.github/workflows/incoming.yaml +++ /dev/null @@ -1,56 +0,0 @@ -name: Incoming Checks -on: [pull_request, push] - -env: - GO_VERSION: "1.16" - -jobs: - go_mod: - # Ignore duplicate events for local repository pull requests - if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) - name: go mod - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 - with: - go-version: ${{ env.GO_VERSION }} - - name: go mod - run: | - echo "==> Checking source code with go mod vendor..." - go mod tidy - git diff --exit-code -- go.mod go.sum || \ - (echo; echo "Unexpected difference in go.mod/go.sum files. Run 'go mod tidy' command or revert any go.mod/go.sum changes and commit."; exit 1) - echo "==> Checking source code with go mod vendor..." - go mod vendor - git diff --compact-summary --exit-code -- vendor || \ - (echo; echo "Unexpected difference in vendor/ directory. Run 'go mod vendor' command or revert any go.mod/go.sum/vendor changes and commit."; exit 1) - go_test: - # Ignore duplicate events for local repository pull requests - if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) - name: go test - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 - with: - go-version: ${{ env.GO_VERSION }} - - run: go test ./... - goreleaser: - # Ignore duplicate events for local repository pull requests - if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) - name: goreleaser - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 - with: - go-version: ${{ env.GO_VERSION }} - - name: goreleaser check - uses: goreleaser/goreleaser-action@v2 - with: - args: check - - name: goreleaser build - uses: goreleaser/goreleaser-action@v2 - with: - args: build --snapshot diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 7a9b236e..6afd024e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -4,20 +4,18 @@ on: tags: - "v[0-9]+.[0-9]+.[0-9]+" -env: - GO_VERSION: "1.16" +permissions: + contents: write jobs: go_mod: - # Ignore duplicate events for local repository pull requests - if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) name: go mod runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 + - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 + - uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0 with: - go-version: ${{ env.GO_VERSION }} + go-version-file: 'go.mod' - name: go mod run: | go mod tidy @@ -27,51 +25,45 @@ jobs: git diff --compact-summary --exit-code -- vendor || \ (echo; echo "Unexpected difference in vendor/ directory. Run 'go mod vendor' command or revert any go.mod/go.sum/vendor changes and commit."; exit 1) go_test: - # Ignore duplicate events for local repository pull requests - if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) name: go test runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 + - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 + - uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0 with: - go-version: ${{ env.GO_VERSION }} + go-version-file: 'go.mod' - run: go test ./... goreleaser: - # Ignore duplicate events for local repository pull requests - if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) name: goreleaser needs: [go_mod, go_test] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 with: fetch-depth: 0 - - uses: actions/setup-go@v2 + - uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0 with: - go-version: ${{ env.GO_VERSION }} - - 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 + go-version-file: 'go.mod' + - uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Import GPG key id: import_gpg - uses: crazy-max/ghaction-import-gpg@v2 - env: - GPG_PRIVATE_KEY: ${{ secrets.GPG_KEY }} + uses: crazy-max/ghaction-import-gpg@111c56156bcc6918c056dbef52164cfa583dc549 # v5.2.0 + with: + gpg_private_key: ${{ secrets.GPG_KEY }} - name: Generate Release Notes run: | sed -n -e "1{/# v/d;}" -e "2{/^$/d;}" -e "/# $(git describe --abbrev=0 --exclude="$(git describe --abbrev=0 --match='v*.*.*' --tags)" --match='v*.*.*' --tags)/q;p" CHANGELOG.md > RELEASE-NOTES.md - name: goreleaser check - uses: goreleaser/goreleaser-action@v2 + uses: goreleaser/goreleaser-action@f82d6c1c344bcacabba2c841718984797f664a6b # v4.2.0 with: args: check - name: goreleaser release - uses: goreleaser/goreleaser-action@v2 + uses: goreleaser/goreleaser-action@f82d6c1c344bcacabba2c841718984797f664a6b # v4.2.0 env: - GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} with: - args: release --release-notes RELEASE-NOTES.md --rm-dist - key: ${{ secrets.GPG_KEY }} + args: release --release-notes RELEASE-NOTES.md --clean diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 00000000..b19d0e7d --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,47 @@ +name: Test +on: pull_request + +jobs: + go_mod: + name: go mod + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 + - uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0 + with: + go-version-file: 'go.mod' + - name: go mod + run: | + echo "==> Checking source code with go mod vendor..." + go mod tidy + git diff --exit-code -- go.mod go.sum || \ + (echo; echo "Unexpected difference in go.mod/go.sum files. Run 'go mod tidy' command or revert any go.mod/go.sum changes and commit."; exit 1) + echo "==> Checking source code with go mod vendor..." + go mod vendor + git diff --compact-summary --exit-code -- vendor || \ + (echo; echo "Unexpected difference in vendor/ directory. Run 'go mod vendor' command or revert any go.mod/go.sum/vendor changes and commit."; exit 1) + go_test: + name: go test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 + - uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0 + with: + go-version-file: 'go.mod' + - run: go test ./... + goreleaser: + name: goreleaser + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 + - uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0 + with: + go-version-file: 'go.mod' + - name: goreleaser check + uses: goreleaser/goreleaser-action@f82d6c1c344bcacabba2c841718984797f664a6b # v4.2.0 + with: + args: check + - name: goreleaser build + uses: goreleaser/goreleaser-action@f82d6c1c344bcacabba2c841718984797f664a6b # v4.2.0 + with: + args: build --snapshot diff --git a/.goreleaser.yml b/.goreleaser.yml index 88fa9ef3..9e60ee94 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -69,3 +69,11 @@ milestones: signs: - artifacts: checksum + args: + - "--batch" + - "--local-user" + - "{{ .Env.GPG_FINGERPRINT }}" + - "--output" + - "${signature}" + - "--detach-sign" + - "${artifact}"