| 1 |
# Copyright (c) HashiCorp, Inc. |
| 2 |
# SPDX-License-Identifier: MPL-2.0 |
| 3 |
|
| 4 |
name: Per-commit Checks |
| 5 |
|
| 6 |
on: |
| 7 |
push: |
| 8 |
workflow_dispatch: |
| 9 |
pull_request: |
| 10 |
|
| 11 |
permissions: |
| 12 |
contents: read |
| 13 |
|
| 14 |
jobs: |
| 15 |
unit_tests: |
| 16 |
name: "unit tests" |
| 17 |
runs-on: ubuntu-latest |
| 18 |
|
| 19 |
steps: |
| 20 |
- name: "Fetch source code" |
| 21 |
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 |
| 22 |
- name: Install Go |
| 23 |
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1 |
| 24 |
with: |
| 25 |
go-version: 1.18 |
| 26 |
- name: Go test |
| 27 |
run: | |
| 28 |
go test ./... |
| 29 |
|
| 30 |
fmt_and_vet: |
| 31 |
name: "fmt and lint" |
| 32 |
runs-on: ubuntu-latest |
| 33 |
|
| 34 |
steps: |
| 35 |
- name: "Fetch source code" |
| 36 |
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 |
| 37 |
- name: Install Go |
| 38 |
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1 |
| 39 |
with: |
| 40 |
go-version: 1.18 |
| 41 |
- name: "Check vet" |
| 42 |
run: | |
| 43 |
go vet ./... |
| 44 |
- name: "Check fmt" |
| 45 |
run: | |
| 46 |
go fmt ./... |
| 47 |
if [[ -z "$(git status --porcelain)" ]]; then |
| 48 |
echo "Formatting is consistent with 'go fmt'." |
| 49 |
else |
| 50 |
echo "Run 'go fmt ./...' to automatically apply standard Go style to all packages." |
| 51 |
git status --porcelain |
| 52 |
exit 1 |
| 53 |
fi |