Feat: Adding test to auth #1
Workflow file for this run
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 CI/CD | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
jobs: | |
lint-test-build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: "1.22" | |
- name: Verify workspace | |
run: go work sync | |
- name: Run go fmt | |
run: | | |
all_formatted=true | |
for dir in $(go work edit -json | jq -r '.Use[].DiskPath'); do | |
if [ -n "$(gofmt -s -l $dir)" ]; then | |
echo "Formatting issues in $dir" | |
all_formatted=false | |
fi | |
done | |
if [ "$all_formatted" = false ]; then | |
exit 1 | |
fi | |
- name: Run go vet | |
run: | | |
for dir in $(go work edit -json | jq -r '.Use[].DiskPath'); do | |
echo "Running go vet in $dir" | |
go vet ./$dir/... | |
done | |
- name: Install staticcheck | |
run: go install honnef.co/go/tools/cmd/staticcheck@latest | |
- name: Run staticcheck | |
run: | | |
for dir in $(go work edit -json | jq -r '.Use[].DiskPath'); do | |
echo "Running staticcheck in $dir" | |
staticcheck ./$dir/... | |
done | |
- name: Run tests | |
run: | | |
go work use . | |
for dir in $(go work edit -json | jq -r '.Use[].DiskPath'); do | |
echo "Running tests in $dir" | |
go test -v -race -coverprofile=$dir/coverage.txt -covermode=atomic ./$dir/... | |
done | |
- name: Combine coverage | |
run: | | |
echo "mode: atomic" > coverage.txt | |
for dir in $(go work edit -json | jq -r '.Use[].DiskPath'); do | |
if [ -f $dir/coverage.txt ]; then | |
tail -n +2 $dir/coverage.txt >> coverage.txt | |
fi | |
done | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v3 | |
with: | |
file: ./coverage.txt | |
- name: Build | |
run: | | |
for dir in $(go work edit -json | jq -r '.Use[].DiskPath'); do | |
echo "Building in $dir" | |
go build -v ./$dir/... | |
done | |
deploy-coverage: | |
needs: lint-test-build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: "1.22" | |
- name: Run tests and generate coverage | |
run: | | |
go work use . | |
echo "mode: atomic" > coverage.txt | |
for dir in $(go work edit -json | jq -r '.Use[].DiskPath'); do | |
echo "Running tests in $dir" | |
go test -v -coverprofile=$dir/coverage.tmp -covermode=atomic ./$dir/... | |
if [ -f $dir/coverage.tmp ]; then | |
tail -n +2 $dir/coverage.tmp >> coverage.txt | |
rm $dir/coverage.tmp | |
fi | |
done | |
- name: Generate coverage HTML | |
run: go tool cover -html=coverage.txt -o coverage.html | |
- name: Deploy to GitHub Pages | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: . | |
publish_branch: gh-pages | |
keep_files: true | |
user_name: "github-actions[bot]" | |
user_email: "github-actions[bot]@users.noreply.github.com" | |
commit_message: "Deploy coverage report to GitHub Pages" |