From a715b20365d05b617552ef05354e7f2a883e4249 Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Wed, 13 Mar 2024 15:14:06 -0500 Subject: [PATCH 1/5] Switch Release to GH Container Registry --- .github/workflows/build.yml | 58 ++++++++++++++++++++++++++ .github/workflows/docker-push.yml | 67 +++++++++++++++++++++++++++++++ .github/workflows/go.yml | 44 -------------------- .github/workflows/release.yml | 35 ++++------------ 4 files changed, 133 insertions(+), 71 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/docker-push.yml delete mode 100644 .github/workflows/go.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..fb61acf --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,58 @@ +name: Build + +on: + workflow_dispatch: + push: + branches: [master] + pull_request: + branches: [master] + workflow_call: + +jobs: + build: + name: build + runs-on: ubuntu-latest + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + + - uses: actions/cache@v3 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.18" + + - name: Get dependencies + run: | + go get -v -t -d ./... + if [ -f Gopkg.toml ]; then + curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh + dep ensure + fi + + - name: Verify dependencies + run: go mod verify + + - name: lint + uses: golangci/golangci-lint-action@v3 + with: + # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. + version: v1.52 + args: --skip-files .*_test.go --enable wsl --enable misspell --out-format=colored-line-number --timeout 180s + + - name: Build + run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v cmd/arcade/arcade.go + + - name: Test + run: go test -v ./... + + - uses: actions/upload-artifact@v3 + with: + name: build + path: arcade diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml new file mode 100644 index 0000000..0bc3c9f --- /dev/null +++ b/.github/workflows/docker-push.yml @@ -0,0 +1,67 @@ +name: Docker +on: + workflow_call: + +env: + CONTAINER_REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + push: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/download-artifact@v3 + with: + name: build + + - name: Add executable permissions + run: | + chmod +x arcade + + - name: Set release info + run: | + event_type=${{ github.event.action }} + release_version=$(echo ${{ github.ref_name }} | sed 's/v//g' | sed 's/+/-/g') + echo "RELEASE_VERSION=$release_version" >> $GITHUB_ENV + if [[ $event_type == "released" ]]; then + echo "TAGS=${{ env.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:$release_version,${{ env.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_ENV + else + echo "TAGS=${{ env.CONTAINER_REGISTRY }}/${{ env.IMAGE_NAME }}:$release_version" >> $GITHUB_ENV + fi + + - name: Login + uses: docker/login-action@v3 + with: + registry: ${{ env.CONTAINER_REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up docker context for buildx + id: buildx-context + run: | + docker context create builders + + - name: Set up docker buildx + uses: docker/setup-buildx-action@v2 + with: + endpoint: builders + driver-opts: | + image=moby/buildkit:master + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ env.TAGS }} + labels: | + org.opencontainers.image.source=https://github.com/${{ env.IMAGE_NAME }} + org.opencontainers.image.version=${{ env.RELEASE_VERSION }} diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml deleted file mode 100644 index 6d35c66..0000000 --- a/.github/workflows/go.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Go - -on: - workflow_dispatch: - push: - branches: [master] - pull_request: - branches: [master] - -jobs: - build: - name: Build - runs-on: ubuntu-latest - steps: - - name: Set up Go 1.x - uses: actions/setup-go@v4 - with: - go-version: ^1.21 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v4 - - - name: Get dependencies - run: make setup - - - name: Test - run: make test - - - name: Build - run: make build - - golangci: - name: Lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: golangci-lint - uses: golangci/golangci-lint-action@v2 - with: - # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.55 - - args: --skip-files .*_test.go --enable wsl --enable misspell --timeout 180s diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3d49f18..de36b91 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,32 +1,13 @@ name: Release -on: - workflow_dispatch: - inputs: - version: - type: string - description: version to tag image -jobs: +on: release: - runs-on: ubuntu-latest - env: - VERSION: ${{ github.event.inputs.version }} - steps: - - name: Setup - checkout - uses: actions/checkout@v4 + types: [prereleased, released] - - name: Set up Go 1.x - uses: actions/setup-go@v4 - with: - go-version: ^1.21 - id: go - - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} +jobs: + build: + uses: ./.github/workflows/build.yml - - name: docker - shell: bash - run: docker/docker-build.sh -v ${VERSION} + docker: + needs: build + uses: ./.github/workflows/docker-push.yml From 0bf4377120e08e5c1da9aa3d211c059db1cf1b32 Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Wed, 13 Mar 2024 15:32:40 -0500 Subject: [PATCH 2/5] Use Go version 1.21 --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fb61acf..8e3ce0b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,7 +26,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: "1.18" + go-version: "1.21" - name: Get dependencies run: | From d4b31774ff3d4b098b9b04cc0ae6d95a3071218d Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Wed, 13 Mar 2024 15:37:45 -0500 Subject: [PATCH 3/5] Use setup-go native cache --- .github/workflows/build.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8e3ce0b..fe2a3cc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,13 +16,6 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v4 - - uses: actions/cache@v3 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - name: Set up Go uses: actions/setup-go@v4 with: From 8519d614aca55e8e7ad6952ce016338bd206498e Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Wed, 13 Mar 2024 16:03:21 -0500 Subject: [PATCH 4/5] Add go mod tidy --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fe2a3cc..f10ae60 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,6 +28,7 @@ jobs: curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh dep ensure fi + go mod tidy - name: Verify dependencies run: go mod verify From b2c0ba83810c3b9e8c359a6b9c62eb99667d0777 Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Wed, 13 Mar 2024 16:06:05 -0500 Subject: [PATCH 5/5] Update linter --- .github/workflows/build.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f10ae60..f6861fe 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,9 +17,10 @@ jobs: uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: "1.21" + cache: false - name: Get dependencies run: | @@ -34,10 +35,10 @@ jobs: run: go mod verify - name: lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v4 with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.52 + version: v1.55 args: --skip-files .*_test.go --enable wsl --enable misspell --out-format=colored-line-number --timeout 180s - name: Build