From b1495650b86f25c872119e0b749420195a321572 Mon Sep 17 00:00:00 2001 From: John McBride Date: Thu, 13 Jul 2023 17:41:02 -0600 Subject: [PATCH] GitHub actions: fixes broken actions workflows and adds PR tests (#15) --- .github/workflows/test.yaml | 51 +++++++++++++++++++++++++++++++------ .gitignore | 5 ++++ Makefile | 5 ++++ 3 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 .gitignore diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7e37f18..0a9c29e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,17 +1,52 @@ -name: Test and build +name: Lint, test, and build -on: [push] +on: + push: + branches: + - main + pull_request: + types: + - opened + - edited + - synchronize + - reopened + +permissions: + # So golangci-lint can read the contents of the lint yaml file + contents: read jobs: - build: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Go + uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1 + with: + go-version: 1.20.x + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.53 + + test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Set up Go - uses: actions/setup-go@v3 + uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1 with: - go-version: 1.20 - - name: Build - run: go build -v ./... + go-version: 1.20.x - name: Test - run: go test -v ./... + run: make test + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Go + uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1 + with: + go-version: 1.20.x + - name: Build go binary + run: make build diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..46447c5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +# This is where the "make local" target drops build artifacts +build/ + +# explicitly ignore env files to ensure secrets aren't being accidentally committed +.env diff --git a/Makefile b/Makefile index e4ad150..1251f91 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +.PHONY: all lint test run local build setup-test-env teardown-test-env + ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) all: lint test build @@ -17,6 +19,9 @@ test: run: go run main.go +local: + go build -o build/pizza-oven main.go + build: docker build . -t pizza-oven:latest