Merge pull request #147 from MintzyG/production #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: Go Lint, Format, and Test | |
on: | |
push: | |
pull_request: | |
jobs: | |
lint-format-and-test: | |
name: Lint, Format, and Test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.22' | |
- name: Install tools | |
run: | | |
go install golang.org/x/tools/cmd/goimports@latest | |
go install honnef.co/go/tools/cmd/staticcheck@latest | |
- name: Run gofmt and check for changes | |
id: gofmt | |
run: | | |
gofmt -l -w . | |
if [ -n "$(git status --porcelain)" ]; then | |
echo "changes=true" >> $GITHUB_OUTPUT | |
echo "Changes detected by gofmt" | |
else | |
echo "changes=false" >> $GITHUB_OUTPUT | |
echo "No changes detected by gofmt" | |
fi | |
- name: Run goimports and check for changes | |
id: goimports | |
run: | | |
goimports -l -w . | |
if [ -n "$(git status --porcelain)" ]; then | |
echo "changes=true" >> $GITHUB_OUTPUT | |
echo "Changes detected by goimports" | |
else | |
echo "changes=false" >> $GITHUB_OUTPUT | |
echo "No changes detected by goimports" | |
fi | |
- name: Run staticcheck | |
run: | | |
cd src | |
staticcheck | |
- name: Run tests | |
run: | | |
cd src | |
go test -v | |
- name: Commit formatting changes | |
if: steps.gofmt.outputs.changes == 'true' || steps.goimports.outputs.changes == 'true' | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add . | |
git commit -m "Auto-format Go code" || echo "No changes to commit" | |
git push || echo "No changes to push" |