Skip to content

Add CI workflow

Add CI workflow #1

Workflow file for this run

name: ci
on:
pull_request:
paths-ignore:
- "README.md"
push:
branches:
- main
paths-ignore:
- "README.md"
permissions:
contents: read
jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: "go.mod"
cache: true
- name: Ensure go modules are tidy
run: |
go mod tidy
if [[ -n $(git status -s) ]] ; then
echo
echo -e "\e[31mRunning 'go mod tidy' changes the current setting"
echo -e "\e[31mEnsure to include updated go.mod and go.sum in this PR."
echo -e "\e[31mThis is usually done by running 'go mod tidy'\e[0m"
git status -s
git diff --color
exit 1
fi
- name: Ensure go fmt is clean
run: |
go fmt ./...
if [[ -n $(git status -s) ]] ; then
echo
echo -e "\e[31mRunning 'go fmt' changes the current codebase"
echo -e "\e[31mEnsure to include updated codebase in this PR."
echo -e "\e[31mThis is usually done by running 'go fmt'\e[0m"
git status -s
git diff --color
exit 1
fi
- name: Ensure go vet is clean
run: |
go vet ./...
if [[ $? -ne 0 ]] ; then
echo
echo -e "\e[31mRunning 'go vet' changes the current codebase"
echo -e "\e[31mEnsure to include updated codebase in this PR."
echo -e "\e[31mThis is usually done by running 'go vet'\e[0m"
exit 1
fi
- name: Run linters
uses: golangci/golangci-lint-action@3cfe3a4abbb849e10058ce4af15d205b6da42804 # v4.0.0
with:
version: latest
build:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: "go.mod"
cache: true
- run: go mod download
- run: go build -v .