From a5d68746a0c009e60cb288bb14b5936f647939c1 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Wed, 31 Jan 2024 23:00:38 -0500 Subject: [PATCH 1/5] refactor(ci): define single go version --- .github/workflows/ci.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index eaae1a4..e850cda 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -6,6 +6,9 @@ on: branches: - main +env: + GO_VERSION: '1.21' + jobs: tests: name: "Tests" @@ -14,7 +17,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: - go-version: '1.21' + go-version: ${{ env.GO_VERSION }} - run: . scripts/test integration-tests: name: "Integration tests" @@ -25,5 +28,5 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: - go-version: '1.21' + go-version: ${{ env.GO_VERSION }} - run: . integration/install_specific_version From 3ca2996e43b257c46aa1efc5c2b1b7c0199b8b4f Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Wed, 31 Jan 2024 23:12:08 -0500 Subject: [PATCH 2/5] refactor(ci): use gofmt directly, mark shell scripts clearly --- .github/workflows/ci.yaml | 4 ++-- ...nstall_specific_version => install_specific_version.sh} | 0 scripts/build => script/build.sh | 0 script/format.sh | 7 +++++++ scripts/test => script/test.sh | 0 scripts/format | 3 --- 6 files changed, 9 insertions(+), 5 deletions(-) rename integration/{install_specific_version => install_specific_version.sh} (100%) rename scripts/build => script/build.sh (100%) create mode 100644 script/format.sh rename scripts/test => script/test.sh (100%) delete mode 100644 scripts/format diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e850cda..1661ace 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,7 +18,7 @@ jobs: - uses: actions/setup-go@v4 with: go-version: ${{ env.GO_VERSION }} - - run: . scripts/test + - run: . script/test.sh integration-tests: name: "Integration tests" runs-on: ubuntu-latest @@ -29,4 +29,4 @@ jobs: - uses: actions/setup-go@v4 with: go-version: ${{ env.GO_VERSION }} - - run: . integration/install_specific_version + - run: . integration/install_specific_version.sh diff --git a/integration/install_specific_version b/integration/install_specific_version.sh similarity index 100% rename from integration/install_specific_version rename to integration/install_specific_version.sh diff --git a/scripts/build b/script/build.sh similarity index 100% rename from scripts/build rename to script/build.sh diff --git a/script/format.sh b/script/format.sh new file mode 100644 index 0000000..fac9ac0 --- /dev/null +++ b/script/format.sh @@ -0,0 +1,7 @@ +#!/usr/bin/bash + +if [[ -z "$FIX" ]]; then + [ -z "$(gofmt -s -l ./)" ] || exit 1 +else + gofmt -s -l -w ./ +fi diff --git a/scripts/test b/script/test.sh similarity index 100% rename from scripts/test rename to script/test.sh diff --git a/scripts/format b/scripts/format deleted file mode 100644 index bc2d5e5..0000000 --- a/scripts/format +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/bash - -go fmt ./... From 27df322a5042139f080dd2dc5bf800f420480f62 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Wed, 31 Jan 2024 23:13:33 -0500 Subject: [PATCH 3/5] ci: add formatting step --- .github/workflows/ci.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1661ace..c7096ef 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -19,6 +19,15 @@ jobs: with: go-version: ${{ env.GO_VERSION }} - run: . script/test.sh + format: + name: "Formatting check" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + - run: . script/format.sh integration-tests: name: "Integration tests" runs-on: ubuntu-latest From 4468a70870b2bfd4bce408c274662a8b755c1cfb Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Wed, 31 Jan 2024 23:53:09 -0500 Subject: [PATCH 4/5] ci: add multi-dist build step --- .github/workflows/ci.yaml | 22 +++++++++++++++++++++- script/build.sh | 14 +++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c7096ef..213c5e7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -10,7 +10,7 @@ env: GO_VERSION: '1.21' jobs: - tests: + test: name: "Tests" runs-on: ubuntu-latest steps: @@ -39,3 +39,23 @@ jobs: with: go-version: ${{ env.GO_VERSION }} - run: . integration/install_specific_version.sh + build: + name: "Build" + runs-on: ubuntu-latest + needs: [test,format,integration-tests] + strategy: + matrix: + dist: ["darwin_amd64", "darwin_arm64", "linux_amd64"] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + - run: PROD=$PROD GOOS=${DIST%_*} GOARCH=${DIST#*_} . script/build.sh + env: + DIST: ${{ matrix.dist }} + PROD: ${{ github.ref == 'refs/heads/main' && '1' || '' }} + - uses: actions/upload-artifact@v4 + with: + name: build-${{matrix.dist}} + path: ./build/**/* diff --git a/script/build.sh b/script/build.sh index f7f1aad..7dfd857 100644 --- a/script/build.sh +++ b/script/build.sh @@ -1,3 +1,15 @@ #!/usr/bin/bash -go build . +OS=$(GOOS=$GOOS go env GOOS) +ARCH=$(GOARCH=$GOARCH go env GOARCH) + +if [[ -z "$PROD" ]]; then + CURRENT_COMMIT=$(git rev-parse HEAD) + BUILD_PATH="build/$OS-$ARCH-$CURRENT_COMMIT" + mkdir -p $BUILD_PATH + GOOS=$OS GOARCH=$ARCH go build -o $BUILD_PATH -v -x . +else + BUILD_PATH="build/$OS-$ARCH" + mkdir -p $BUILD_PATH . + GOOS=$OS GOARCH=$ARCH go build -o $BUILD_PATH -ldflags "-w -s" . +fi From 096ff162e92c52c2fcc2c7a13fb94bb4808be0de Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Thu, 1 Feb 2024 00:57:30 -0500 Subject: [PATCH 5/5] ci: update setup-go to v5 --- .github/workflows/ci.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 213c5e7..d0303ae 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: go-version: ${{ env.GO_VERSION }} - run: . script/test.sh @@ -24,7 +24,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: go-version: ${{ env.GO_VERSION }} - run: . script/format.sh @@ -35,7 +35,7 @@ jobs: V_ROOT: /tmp/v steps: - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: go-version: ${{ env.GO_VERSION }} - run: . integration/install_specific_version.sh @@ -48,7 +48,7 @@ jobs: dist: ["darwin_amd64", "darwin_arm64", "linux_amd64"] steps: - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: go-version: ${{ env.GO_VERSION }} - run: PROD=$PROD GOOS=${DIST%_*} GOARCH=${DIST#*_} . script/build.sh