Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: adds linting and formatting jobs to on pull request workflow #93

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
needs: run-test-workflow
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down
37 changes: 29 additions & 8 deletions .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,41 @@ env:
PASSAGE_AUTH_TOKEN: ${{ secrets.PASSAGE_AUTH_TOKEN }}

jobs:
build:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.20.14'
- name: Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60
format:
name: Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.20.14'
- name: Format
run: |
if [[ $(gofmt -s -d .) ]]; then
echo "Run 'gofmt -s -w .' to format code."
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

considered posting a PR comment for this and the linter failure results as a convenience for contributors, but didn't want to overcomplicate the workflow

exit 1
fi
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.20.14'

- name: Checkout code
uses: actions/checkout@v2

- name: Test
run: go test ./...

- name: Test with race detector
run: go test -race -run TestAppJWKSCacheWriteConcurrency
34 changes: 34 additions & 0 deletions .github/workflows/pr-title-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: PR Title Check

on:
pull_request:
types:
- edited

jobs:
lint-pr-title:
name: Lint PR Title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
id: lint_pr_title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: marocchino/sticky-pull-request-comment@v2
# When the previous steps fails, the workflow would stop. By adding this
# condition you can continue the execution with the populated error message.
if: always() && (steps.lint_pr_title.outputs.error_message != null)
with:
header: pr-title-lint-error
message: |
Please update the pull request title to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/).
Details:
```
${{ steps.lint_pr_title.outputs.error_message }}
```
# Delete a previous comment when the issue has been resolved
- if: ${{ steps.lint_pr_title.outputs.error_message == null }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-title-lint-error
delete: true
19 changes: 19 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
linters:
disable-all: true
enable:
- errcheck
- errname
- errorlint
- gci
- gocritic
- gofmt
- gosimple
- ineffassign
- staticcheck
- typecheck
- unparam
- unused
issues:
fix: true
max-issues-per-linter: 0
max-same-issues: 0
4 changes: 3 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ func New(appID string, config *Config) (*App, error) {
}

app.jwksCache = jwk.NewCache(context.Background())
app.jwksCache.Register(fmt.Sprintf(jwksUrl, appID))
if err := app.jwksCache.Register(fmt.Sprintf(jwksUrl, appID)); err != nil {
return nil, err
}

if err := app.refreshJWKSCache(); err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion passage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func generateRandomEmail(prefixLength int) string {
}

func TestMain(m *testing.M) {
godotenv.Load(".env")
_ = godotenv.Load(".env")

PassageAppID = os.Getenv("PASSAGE_APP_ID")
PassageApiKey = os.Getenv("PASSAGE_API_KEY")
Expand Down
Loading