diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index eaae1a4..d0303ae 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -6,16 +6,28 @@ on: branches: - main +env: + GO_VERSION: '1.21' + jobs: - tests: + test: name: "Tests" runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: - go-version: '1.21' - - run: . scripts/test + 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@v5 + with: + go-version: ${{ env.GO_VERSION }} + - run: . script/format.sh integration-tests: name: "Integration tests" runs-on: ubuntu-latest @@ -23,7 +35,27 @@ jobs: V_ROOT: /tmp/v steps: - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: - go-version: '1.21' - - run: . integration/install_specific_version + 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@v5 + 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/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/script/build.sh b/script/build.sh new file mode 100644 index 0000000..7dfd857 --- /dev/null +++ b/script/build.sh @@ -0,0 +1,15 @@ +#!/usr/bin/bash + +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 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/build b/scripts/build deleted file mode 100644 index f7f1aad..0000000 --- a/scripts/build +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/bash - -go build . 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 ./...