Merge pull request #25 from mcataford/ci/format-and-build
refactor(ci): define single go version
This commit is contained in:
commit
29425b6179
7 changed files with 61 additions and 13 deletions
46
.github/workflows/ci.yaml
vendored
46
.github/workflows/ci.yaml
vendored
|
@ -6,16 +6,28 @@ on:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
|
env:
|
||||||
|
GO_VERSION: '1.21'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
tests:
|
test:
|
||||||
name: "Tests"
|
name: "Tests"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-go@v4
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.21'
|
go-version: ${{ env.GO_VERSION }}
|
||||||
- run: . scripts/test
|
- 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:
|
integration-tests:
|
||||||
name: "Integration tests"
|
name: "Integration tests"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
@ -23,7 +35,27 @@ jobs:
|
||||||
V_ROOT: /tmp/v
|
V_ROOT: /tmp/v
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-go@v4
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.21'
|
go-version: ${{ env.GO_VERSION }}
|
||||||
- run: . integration/install_specific_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
15
script/build.sh
Normal 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
7
script/format.sh
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
if [[ -z "$FIX" ]]; then
|
||||||
|
[ -z "$(gofmt -s -l ./)" ] || exit 1
|
||||||
|
else
|
||||||
|
gofmt -s -l -w ./
|
||||||
|
fi
|
|
@ -1,3 +0,0 @@
|
||||||
#!/usr/bin/bash
|
|
||||||
|
|
||||||
go build .
|
|
|
@ -1,3 +0,0 @@
|
||||||
#!/usr/bin/bash
|
|
||||||
|
|
||||||
go fmt ./...
|
|
Loading…
Reference in a new issue