Feature/update test workflow #23
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: Run Tests | |
on: | |
pull_request: | |
branches: ["main"] | |
jobs: | |
test: | |
name: Run Tests | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgres:16 | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres | |
POSTGRES_PORT: 5432 | |
POSTGRES_DB: postgres | |
options: >- | |
--health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | |
ports: | |
- 5432:5432 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.23' | |
cache: true | |
- name: Install dependencies | |
run: go mod download | |
- name: Install Goose | |
run: go install github.com/pressly/goose/v3/cmd/[email protected] | |
- name: Run migrations | |
run: goose -dir .sqlc/migrations postgres "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable" up | |
- name: Run tests | |
run: go test -v -coverprofile=coverage.out ./... | |
- name: Generate coverage report | |
run: go tool cover -html=coverage.out -o coverage.html | |
- name: Upload coverage report | |
if: ${{ !env.ACT && github.event_name == 'pull_request' }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-report | |
path: coverage.html | |
- name: Comment PR | |
if: ${{ !env.ACT && github.event_name == 'pull_request' && always() }} | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const fs = require('fs'); | |
const coverage = fs.readFileSync('coverage.out', 'utf8') | |
.split('\n') | |
.find(line => line.includes('total:')) | |
?.split('\t')[1] || 'N/A'; | |
const testStatus = '${{ job.status }}'; | |
const color = testStatus === 'success' ? '✅' : '❌'; | |
const output = `### Test Results ${color} | |
**Status**: ${testStatus} | |
**Coverage**: ${coverage} | |
**OS**: \`${{ runner.os }}\` | |
<details> | |
<summary>Test Details</summary> | |
* Triggered by: @${{ github.actor }} | |
* Commit: ${{ github.sha }} | |
* Branch: ${{ github.ref }} | |
* Workflow: ${{ github.workflow }} | |
</details>`; | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: output | |
}) | |
- uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cache/go-build | |
~/go/pkg/mod | |
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
restore-keys: | | |
${{ runner.os }}-go- |