From 6c97a10e8de9f65fb7e8642d83398e2f3e797619 Mon Sep 17 00:00:00 2001 From: DeveloperC Date: Wed, 20 Dec 2023 00:35:45 +0000 Subject: [PATCH] BUILD: WORKING COMMIT - DELETE * https://goreleaser.com/ * https://cli.github.com/manual/gh_release_upload --- .github/workflows/continuous-integration.yml | 18 ++---- .gitignore | 3 + .goreleaser.yaml | 11 ++++ Earthfile | 65 ++++++++++++-------- ci/check-yaml-formatting.sh | 4 +- ci/compile.sh | 2 +- ci/fix-yaml-formatting.sh | 2 +- ci/release-artifacts.sh | 11 ++++ 8 files changed, 72 insertions(+), 44 deletions(-) create mode 100644 .goreleaser.yaml create mode 100755 ci/release-artifacts.sh 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 71ef8dd..a55eb62 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: @@ -56,12 +57,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 @@ -80,7 +75,7 @@ check-go-formatting: sh-formatting-base: FROM golang - RUN go install mvdan.cc/sh/v3/cmd/shfmt@v3.6.0 + RUN go install mvdan.cc/sh/v3/cmd/shfmt@v3.6.0 DO +COPY_CI_DATA @@ -91,7 +86,7 @@ check-shell-formatting: yaml-formatting-base: FROM golang - RUN go install github.com/google/yamlfmt/cmd/yamlfmt@v0.9.0 + RUN go install github.com/google/yamlfmt/cmd/yamlfmt@v0.9.0 COPY ".yamlfmt" ".yamlfmt" DO +COPY_CI_DATA @@ -183,21 +178,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: @@ -207,18 +203,35 @@ unit-test: RUN ./ci/unit-test.sh -release: - FROM +ubuntu-base - RUN apt-get install wget git -y - # Install GitHub CLI. - ENV GH_VERSION=2.30.0 - RUN wget "https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_linux_amd64.tar.gz" - RUN tar -xzvf "gh_${GH_VERSION}_linux_amd64.tar.gz" - RUN cp "./gh_${GH_VERSION}_linux_amd64/bin/gh" /bin/gh - # Install Git Cliff. +INSTALL_GITHUB_CLI: + COMMAND + ENV GITHUB_CLI_VERSION=2.30.0 + RUN wget "https://github.com/cli/cli/releases/download/v${GITHUB_CLI_VERSION}/gh_${GITHUB_CLI_VERSION}_linux_amd64.tar.gz" + RUN tar -xzvf "gh_${GITHUB_CLI_VERSION}_linux_amd64.tar.gz" + RUN cp "./gh_${GITHUB_CLI_VERSION}_linux_amd64/bin/gh" /bin/gh + + +INSTALL_GIT_CLIFF: + COMMAND ENV GIT_CLIFF_VERSION=1.2.0 RUN wget "https://github.com/orhun/git-cliff/releases/download/v${GIT_CLIFF_VERSION}/git-cliff-${GIT_CLIFF_VERSION}-x86_64-unknown-linux-gnu.tar.gz" RUN tar -xzvf "git-cliff-${GIT_CLIFF_VERSION}-x86_64-unknown-linux-gnu.tar.gz" RUN cp "./git-cliff-${GIT_CLIFF_VERSION}/git-cliff" /bin/git-cliff + + +release: + FROM +ubuntu-base + RUN apt-get install wget git -y + DO +INSTALL_GITHUB_CLI + DO +INSTALL_GIT_CLIFF DO +COPY_METADATA RUN --secret GH_TOKEN ./ci/release.sh + + +release-artifacts: + FROM +ubuntu-base + RUN apt-get install wget jq -y + DO +INSTALL_GITHUB_CLI + COPY +compile/dist ./dist + DO +COPY_CI_DATA + RUN --secret GH_TOKEN ./ci/release-artifacts.sh diff --git a/ci/check-yaml-formatting.sh b/ci/check-yaml-formatting.sh index d39cb5a..40405f3 100755 --- a/ci/check-yaml-formatting.sh +++ b/ci/check-yaml-formatting.sh @@ -1,6 +1,6 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh 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 diff --git a/ci/release-artifacts.sh b/ci/release-artifacts.sh new file mode 100755 index 0000000..40649b4 --- /dev/null +++ b/ci/release-artifacts.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env sh + +set -o errexit +set -o xtrace + +for row in $(jq -c '.[]' "dist/artifacts.json"); do + path=$(echo "${row}" | jq -r '.path') + name=$(echo "${path}" | cut -d '/' -f 2) + + echo "gh release upload TAG ${path}%#%${name}" +done