Merge pull request #25 from mcataford/ci/format-and-build

refactor(ci): define single go version
This commit is contained in:
Marc 2024-02-01 01:02:07 -05:00 committed by GitHub
commit 29425b6179
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 61 additions and 13 deletions

View file

@ -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/**/*

15
script/build.sh Normal file
View file

@ -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

7
script/format.sh Normal file
View file

@ -0,0 +1,7 @@
#!/usr/bin/bash
if [[ -z "$FIX" ]]; then
[ -z "$(gofmt -s -l ./)" ] || exit 1
else
gofmt -s -l -w ./
fi

View file

@ -1,3 +0,0 @@
#!/usr/bin/bash
go build .

View file

@ -1,3 +0,0 @@
#!/usr/bin/bash
go fmt ./...