Add Build and Update on production
workflow
#1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build | |
on: | |
push: | |
branches: ["!main"] | |
pull_request: | |
workflow_call: | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install Nix packages | |
id: nix-install | |
uses: diamondburned/cache-install@352b0de529729f8a52485442ae9a0b54c95f8f78 | |
with: | |
shell-file: shell.nix | |
nix-path: nixpkgs=channel:nixos-unstable | |
- name: Cache Go Modules | |
uses: actions/cache@v3 | |
with: | |
path: ~/go/pkg/mod | |
key: go-${{ runner.os }}-${{ hashFiles('**/go.sum') }} | |
restore-keys: go-${{ runner.os }}- | |
- name: Go Modules check | |
run: | | |
go get | |
go mod tidy | |
# Check if there has been any git changes. | |
if [[ "$(git status --porcelain)" ]]; then | |
echo "::error::go mod tidy changed code. Make sure you re-run it." | |
git diff | colordiff 2> /dev/null | |
exit 1 | |
fi | |
- name: Generate | |
run: | | |
go generate ./... | |
# Check if there has been any git changes. | |
if [[ "$(git status --porcelain)" ]]; then | |
echo "::error::go generate changed code. Make sure you re-run it." | |
git diff | colordiff 2> /dev/null | |
exit 1 | |
fi | |
- name: Build | |
run: | | |
go build -v ./... | |
- name: Format | |
run: | | |
diff=$(gofmt -e -d .) | |
if [[ "$diff" != "" ]]; then | |
colordiff 2> /dev/null <<< "$diff" | |
exit 1 | |
fi | |
- name: Vet | |
run: | | |
go vet ./... | |
staticcheck ./... | |
- name: Test | |
run: | | |
go test ./... |