From c3e7ad323f6d87bf4f6567595c6632513776e429 Mon Sep 17 00:00:00 2001 From: DeveloperC286 Date: Fri, 29 Dec 2023 15:25:30 +0000 Subject: [PATCH] build: GoReleaser for compiling Converting to using GoReleaser for compiling to easily support and simply the supporting numerous target architectures for the binaries. * https://github.com/goreleaser/goreleaser --- .github/workflows/continuous-integration.yml | 18 +++----------- .gitignore | 3 +++ .goreleaser.yaml | 11 +++++++++ Earthfile | 26 +++++++++----------- ci/check-yaml-formatting.sh | 2 +- ci/compile.sh | 2 +- ci/fix-yaml-formatting.sh | 2 +- 7 files changed, 32 insertions(+), 32 deletions(-) create mode 100644 .goreleaser.yaml diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 7f5b00c..e69c3c6 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -67,26 +67,16 @@ jobs: uses: actions/checkout@v3 - name: Check modules. run: earthly --ci +check-modules - compile-darwin-amd64: - name: Compile Darwin AMD64 + compile: + name: Compile runs-on: ubuntu-latest steps: - name: Download Earthly v0.7.17. run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.7.17/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'" - name: Checkout code. uses: actions/checkout@v3 - - name: Compile Darwin AMD64. - run: earthly --ci +compile-darwin-amd64 - compile-linux-amd64: - name: Compile Linux AMD64 - runs-on: ubuntu-latest - steps: - - name: Download Earthly v0.7.17. - run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.7.17/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'" - - name: Checkout code. - uses: actions/checkout@v3 - - name: Compile Linux AMD64. - run: earthly --ci +compile-linux-amd64 + - name: Compile. + run: earthly --ci +compile unit-test: name: Unit Test runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 8ab4af6..8810971 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ # Generated by Go coverage. *.out + +# Generated by GoReleaser. +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..f56b9fc --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,11 @@ +version: 1 + +builds: + - id: starling-bank-technical-challenge + main: ./cmd/starling-bank-technical-challenge + env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin diff --git a/Earthfile b/Earthfile index 82416bc..1f73ebb 100644 --- a/Earthfile +++ b/Earthfile @@ -5,6 +5,7 @@ COPY_CI_DATA: COMMAND COPY "./ci" "./ci" COPY ".github" ".github" + COPY ".goreleaser.yaml" ".goreleaser.yaml" COPY_METADATA: @@ -47,12 +48,6 @@ COPY_SOURCECODE: COPY "./api" "./api" -SAVE_OUTPUT: - COMMAND - SAVE ARTIFACT "starling-bank-technical-challenge" AS LOCAL "starling-bank-technical-challenge" - SAVE ARTIFACT "go.sum" AS LOCAL "go.sum" - - golang-base: FROM golang:1.20.4 WORKDIR /tmp/starling-bank-technical-challenge @@ -174,21 +169,22 @@ fix-modules: SAVE ARTIFACT "go.sum" AS LOCAL "go.sum" -compile-linux-amd64: - FROM +golang-base - DO +INSTALL_DEPENDENCIES - DO +COPY_SOURCECODE - RUN ./ci/compile.sh - DO +SAVE_OUTPUT +INSTALL_GORELEASER: + COMMAND + ENV GORELEASER_VERSION=1.22.1 + RUN wget "https://github.com/goreleaser/goreleaser/releases/download/v${GORELEASER_VERSION}/goreleaser_Linux_x86_64.tar.gz" + RUN tar -xzvf "goreleaser_Linux_x86_64.tar.gz" + RUN cp "goreleaser" /bin/goreleaser -compile-darwin-amd64: +compile: FROM +golang-base - ENV GOOS=darwin + DO +INSTALL_GORELEASER DO +INSTALL_DEPENDENCIES DO +COPY_SOURCECODE RUN ./ci/compile.sh - DO +SAVE_OUTPUT + SAVE ARTIFACT "dist" AS LOCAL "dist" + SAVE ARTIFACT "go.sum" AS LOCAL "go.sum" unit-test: diff --git a/ci/check-yaml-formatting.sh b/ci/check-yaml-formatting.sh index d39cb5a..98a4dc0 100755 --- a/ci/check-yaml-formatting.sh +++ b/ci/check-yaml-formatting.sh @@ -3,4 +3,4 @@ set -o errexit set -o xtrace -yamlfmt -lint -dstar .github/**/* +yamlfmt -lint -dstar .github/**/* .goreleaser.yaml diff --git a/ci/compile.sh b/ci/compile.sh index 5815fba..50d0287 100755 --- a/ci/compile.sh +++ b/ci/compile.sh @@ -3,4 +3,4 @@ set -o errexit set -o xtrace -go build "./cmd/starling-bank-technical-challenge" +goreleaser build --snapshot --clean diff --git a/ci/fix-yaml-formatting.sh b/ci/fix-yaml-formatting.sh index 7f5c712..ab0eeb9 100755 --- a/ci/fix-yaml-formatting.sh +++ b/ci/fix-yaml-formatting.sh @@ -3,4 +3,4 @@ set -o errexit set -o xtrace -yamlfmt -dstar ./github/**/* +yamlfmt -dstar ./github/**/* .goreleaser.yaml