From 1cb6a1491c55d49a2cf2cefd00d68f5e92199e79 Mon Sep 17 00:00:00 2001 From: Mary McGrath Date: Fri, 11 Oct 2024 12:22:37 -0400 Subject: [PATCH 01/11] ci: add pre-commit --- .github/workflows/go.yml | 5 ----- .github/workflows/pre-commit.yml | 14 ++++++++++++++ .pre-commit-config.yaml | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/pre-commit.yml create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0a4d5d5..3484556 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -26,11 +26,6 @@ jobs: - name: generate templ files run: templ generate - - name: golangci-lint - uses: golangci/golangci-lint-action@v6 - with: - version: latest - - name: Build run: go build -v ./... diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..71b396c --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,14 @@ +name: pre-commit + +on: + push: + branches: [ "main" ] + pull_request: + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - uses: pre-commit/action@v3.0.1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..5b53058 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,17 @@ +repos: + - repo: https://github.com/golangci/golangci-lint + rev: v1.61.0 + hooks: + - id: golangci-lint-full + - id: golangci-lint-config-verify + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: check-illegal-windows-names + - id: check-merge-conflict + - id: check-yaml + - id: detect-private-key + - id: end-of-file-fixer + - id: trailing-whitespace From 259612f5edbfb84817fcaed7bcab9c4b11dfcb23 Mon Sep 17 00:00:00 2001 From: Mary McGrath Date: Fri, 11 Oct 2024 12:31:34 -0400 Subject: [PATCH 02/11] ci: ignore svgs --- .pre-commit-config.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5b53058..67f7638 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,4 +14,8 @@ repos: - id: check-yaml - id: detect-private-key - id: end-of-file-fixer + exclude_types: + - "svg" - id: trailing-whitespace + exclude_types: + - "svg" From 984b9188fbd5841ec1dd42b730272cbaac4f0b61 Mon Sep 17 00:00:00 2001 From: Mary McGrath Date: Fri, 11 Oct 2024 12:32:45 -0400 Subject: [PATCH 03/11] fix: linting fixes --- .envrc | 2 +- README.md | 4 ++-- docker-compose.yml | 2 +- makefile | 2 +- remote/production/phinvads-go.service | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.envrc b/.envrc index 40448e6..fe7c01a 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -dotenv \ No newline at end of file +dotenv diff --git a/README.md b/README.md index 92196a9..844957c 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ In order to run the app you'll need to have completed the following steps: ``` 1. Install [mkcert](https://github.com/FiloSottile/mkcert) -1. Create your own self-signed certs for local development: +1. Create your own self-signed certs for local development: ```bash cd tls @@ -113,7 +113,7 @@ If you'd prefer to not rely on Docker and instead run PostgreSQL locally, you wi ```bash pg_restore -d phinvads --no-owner --role=$(whoami) phinvads.dump ``` - + ### Linting Pull requests to the `main` branch are required to pass linting checks. To run these locally, [install `golangci-lint`](https://golangci-lint.run/welcome/install/#local-installation). Then you can `golangci-lint run` from the project directory. diff --git a/docker-compose.yml b/docker-compose.yml index b482cc8..2401e8c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,4 +12,4 @@ services: - db-data:/var/lib/postgresql/data - ./:/app volumes: - db-data: \ No newline at end of file + db-data: diff --git a/makefile b/makefile index e8a2546..bda33e3 100644 --- a/makefile +++ b/makefile @@ -29,4 +29,4 @@ refreshdb: @echo "Running database refresh..." docker compose exec -T $(DB_SERVICE) psql -U $(DB_USER) -c "DROP DATABASE IF EXISTS $(DB_NAME) WITH (FORCE)" docker compose exec -T $(DB_SERVICE) psql -U $(DB_USER) -c 'CREATE DATABASE $(DB_NAME)' - $(MAKE) load \ No newline at end of file + $(MAKE) load diff --git a/remote/production/phinvads-go.service b/remote/production/phinvads-go.service index e4d105c..6ab73b8 100644 --- a/remote/production/phinvads-go.service +++ b/remote/production/phinvads-go.service @@ -6,7 +6,7 @@ After=postgresql.service After=network-online.target Wants=network-online.target -# Configure service start rate limiting. If the service is (re)started more than 5 times +# Configure service start rate limiting. If the service is (re)started more than 5 times # in 600 seconds then don't permit it to start anymore. StartLimitIntervalSec=600 StartLimitBurst=5 @@ -16,7 +16,7 @@ Type=exec WorkingDirectory=/home/azureuser ExecStart=/home/azureuser/phinvads-go -# Automatically restart the service after a 5-second wait if it exits with a non-zero +# Automatically restart the service after a 5-second wait if it exits with a non-zero # exit code. If it restarts more than 5 times in 600 seconds, then the rate limit we # configured above will be hit and it won't be restarted anymore. Restart=on-failure From 11eccc92453c005c3ece84f89878f753881e7511 Mon Sep 17 00:00:00 2001 From: Mary McGrath Date: Fri, 11 Oct 2024 12:35:58 -0400 Subject: [PATCH 04/11] ci: ignore assets --- .pre-commit-config.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 67f7638..c7f10d5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,8 +14,10 @@ repos: - id: check-yaml - id: detect-private-key - id: end-of-file-fixer + exclude: "internal/ui/assets/.*" exclude_types: - - "svg" + - svg - id: trailing-whitespace + exclude: "internal/ui/assets/.*" exclude_types: - - "svg" + - svg From 54469ed757e1956cfebfb4bfd4307e4a4949f87d Mon Sep 17 00:00:00 2001 From: Mary McGrath Date: Fri, 11 Oct 2024 12:36:05 -0400 Subject: [PATCH 05/11] fix: whitespace --- internal/ui/components/breadcrumb.templ | 6 +++--- internal/ui/components/code_system_result.templ | 6 +++--- internal/ui/components/code_system_result_row.templ | 8 ++++---- internal/ui/components/code_system_table_header.templ | 4 ++-- internal/ui/components/error.templ | 4 ++-- internal/ui/components/footer.templ | 6 +++--- internal/ui/components/home.templ | 4 ++-- internal/ui/components/hot-topic.templ | 2 +- internal/ui/components/navbar.templ | 8 ++++---- internal/ui/components/results-count.templ | 10 ++++------ internal/ui/components/search_bar.templ | 6 +++--- internal/ui/components/search_result_row.templ | 8 ++++---- internal/ui/components/search_results.templ | 2 +- internal/ui/components/usa-banner.templ | 8 ++++---- 14 files changed, 40 insertions(+), 42 deletions(-) diff --git a/internal/ui/components/breadcrumb.templ b/internal/ui/components/breadcrumb.templ index 55533ef..0fd3067 100644 --- a/internal/ui/components/breadcrumb.templ +++ b/internal/ui/components/breadcrumb.templ @@ -4,12 +4,12 @@ templ Breadcrumb(currentPage string) {
if currentPage == "Home" {
- } else { + } else {
PHIN VADS Home {currentPage}
- } + }
-} \ No newline at end of file +} diff --git a/internal/ui/components/code_system_result.templ b/internal/ui/components/code_system_result.templ index f14c6ac..443a0bc 100644 --- a/internal/ui/components/code_system_result.templ +++ b/internal/ui/components/code_system_result.templ @@ -12,7 +12,7 @@ templ CodeSystemResult(searchTerm string, searchResults *models.CodeSystemResult
Showing {strconv.Itoa(searchResults.PageCount)} of {searchResults.CodeSystemsCount} Code Systems
-
=5 { class="pagination" } else { @@ -36,7 +36,7 @@ templ CodeSystemResult(searchTerm string, searchResults *models.CodeSystemResult + } else {
-} \ No newline at end of file +} diff --git a/internal/ui/components/code_system_result_row.templ b/internal/ui/components/code_system_result_row.templ index 552e4bd..1a1058c 100644 --- a/internal/ui/components/code_system_result_row.templ +++ b/internal/ui/components/code_system_result_row.templ @@ -3,7 +3,7 @@ package components import "github.com/CDCgov/phinvads-go/internal/database/models/xo" templ CodeSystemResultRow(alternate bool, result *xo.CodeSystem) { -
-
@@ -34,4 +34,4 @@ templ CodeSystemResultRow(alternate bool, result *xo.CodeSystem) {
-} \ No newline at end of file +} diff --git a/internal/ui/components/code_system_table_header.templ b/internal/ui/components/code_system_table_header.templ index 48143a2..ea3aea4 100644 --- a/internal/ui/components/code_system_table_header.templ +++ b/internal/ui/components/code_system_table_header.templ @@ -8,7 +8,7 @@ templ CodeSystemTableHeader() {
-
+

Code System Code

@@ -23,4 +23,4 @@ templ CodeSystemTableHeader() {
-} \ No newline at end of file +} diff --git a/internal/ui/components/error.templ b/internal/ui/components/error.templ index 4bad42f..348db9e 100644 --- a/internal/ui/components/error.templ +++ b/internal/ui/components/error.templ @@ -1,4 +1,4 @@ -package components +package components templ Error(currentPage, errorText string) { @Base(currentPage) { @@ -9,4 +9,4 @@ templ Error(currentPage, errorText string) {

{errorText}


} -} \ No newline at end of file +} diff --git a/internal/ui/components/footer.templ b/internal/ui/components/footer.templ index a718fd1..a2212f4 100644 --- a/internal/ui/components/footer.templ +++ b/internal/ui/components/footer.templ @@ -52,7 +52,7 @@ templ Footer() { diff --git a/internal/ui/components/home.templ b/internal/ui/components/home.templ index 87f1188..c6e838d 100644 --- a/internal/ui/components/home.templ +++ b/internal/ui/components/home.templ @@ -5,10 +5,10 @@ templ Home() {

PHIN VADS Home

@SearchBar()

Hot Topics

-
diff --git a/internal/ui/components/hot-topic.templ b/internal/ui/components/hot-topic.templ index 9076c47..f91a1a8 100644 --- a/internal/ui/components/hot-topic.templ +++ b/internal/ui/components/hot-topic.templ @@ -7,4 +7,4 @@ templ HotTopic(topic_name string, topic_description, sequence, topic_id string ) -} \ No newline at end of file +} diff --git a/internal/ui/components/navbar.templ b/internal/ui/components/navbar.templ index 55ef891..614030a 100644 --- a/internal/ui/components/navbar.templ +++ b/internal/ui/components/navbar.templ @@ -16,13 +16,13 @@ templ NavBar(currentPage string) { -} \ No newline at end of file +} diff --git a/internal/ui/components/search_result_row.templ b/internal/ui/components/search_result_row.templ index 81201fd..bb6d629 100644 --- a/internal/ui/components/search_result_row.templ +++ b/internal/ui/components/search_result_row.templ @@ -1,7 +1,7 @@ package components templ ResultRow(conceptCode, conceptName, prefName, codeSystem, valueSet string, alternate bool) { -
-
@@ -42,4 +42,4 @@ templ ResultRow(conceptCode, conceptName, prefName, codeSystem, valueSet string,
-} \ No newline at end of file +} diff --git a/internal/ui/components/search_results.templ b/internal/ui/components/search_results.templ index 1739b76..d50b4c9 100644 --- a/internal/ui/components/search_results.templ +++ b/internal/ui/components/search_results.templ @@ -15,4 +15,4 @@ templ SearchResults(isDirect bool, currentPage, searchTerm string, searchResults @CodeSystemResult(searchTerm, searchResults)

} -} \ No newline at end of file +} diff --git a/internal/ui/components/usa-banner.templ b/internal/ui/components/usa-banner.templ index 79ee4be..4d0eab5 100644 --- a/internal/ui/components/usa-banner.templ +++ b/internal/ui/components/usa-banner.templ @@ -22,7 +22,7 @@ templ UsaBanner(action string) { class="usa-banner__toggle usa-banner__header-action" aria-controls="usa-accordion__content" > - Here's how you know + Here's how you know @@ -47,12 +47,12 @@ templ UsaBanner(action string) {
Secure .gov websites use HTTPS

- A + A lock - () - or + () + or https:// From bc3fb06ad0540789651152766e350e638173b167 Mon Sep 17 00:00:00 2001 From: Mary McGrath Date: Fri, 11 Oct 2024 12:44:56 -0400 Subject: [PATCH 06/11] ci: try to get more debug info --- .github/workflows/pre-commit.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 71b396c..8d5832f 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -12,3 +12,5 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v3 - uses: pre-commit/action@v3.0.1 + with: + extra_args: -v From a8fc7f6abc8b0bfad122de709551b312aabea46f Mon Sep 17 00:00:00 2001 From: Mary McGrath Date: Fri, 11 Oct 2024 12:52:07 -0400 Subject: [PATCH 07/11] ci: hmmm --- .github/workflows/pre-commit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 8d5832f..43c848c 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -13,4 +13,4 @@ jobs: - uses: actions/setup-python@v3 - uses: pre-commit/action@v3.0.1 with: - extra_args: -v + extra_args: -v --all-files From 3edbd16a81a3ef80d955184990782206b6b40265 Mon Sep 17 00:00:00 2001 From: Mary McGrath Date: Fri, 11 Oct 2024 13:32:51 -0400 Subject: [PATCH 08/11] ci: set up go --- .github/workflows/pre-commit.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 43c848c..1582c91 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -10,7 +10,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.23.1' + - uses: actions/setup-python@v3 + - uses: pre-commit/action@v3.0.1 - with: - extra_args: -v --all-files From 1ed7b7c239076376a4f65b1a6e13526f74b0e24c Mon Sep 17 00:00:00 2001 From: Mary McGrath Date: Fri, 11 Oct 2024 13:38:09 -0400 Subject: [PATCH 09/11] ci: force breaking python cache --- .github/workflows/pre-commit.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 1582c91..8fb703f 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -17,5 +17,7 @@ jobs: go-version: '1.23.1' - uses: actions/setup-python@v3 + with: + python-version: '3.12.1' - uses: pre-commit/action@v3.0.1 From ecdc9a634bae4f9d3ae43eaf8ebf58f377fa4b71 Mon Sep 17 00:00:00 2001 From: Mary McGrath Date: Fri, 11 Oct 2024 13:38:27 -0400 Subject: [PATCH 10/11] docs: update readme with pre-commit instructions --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 844957c..97c9f94 100644 --- a/README.md +++ b/README.md @@ -116,4 +116,11 @@ If you'd prefer to not rely on Docker and instead run PostgreSQL locally, you wi ### Linting -Pull requests to the `main` branch are required to pass linting checks. To run these locally, [install `golangci-lint`](https://golangci-lint.run/welcome/install/#local-installation). Then you can `golangci-lint run` from the project directory. +Pull requests to the `main` branch are required to pass linting checks. We use [`pre-commit`](https://pre-commit.com/) to run these checks. To run them locally, install `pre-commit` and then install the hooks to run before every commit. + +```bash +pip install pre-commit +pre-commit install +``` + +You can also run the checks on demand using `pre-commit run` (staged files) or `pre-commit run --all-files` (entire repo). From 4026e57ebec1a726c5c58307495f6ab287b2a573 Mon Sep 17 00:00:00 2001 From: Mary McGrath Date: Fri, 11 Oct 2024 13:40:48 -0400 Subject: [PATCH 11/11] ci: install templ and generate --- .github/workflows/pre-commit.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 8fb703f..33efecc 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -16,8 +16,12 @@ jobs: with: go-version: '1.23.1' + - name: Install templ + run: go install github.com/a-h/templ/cmd/templ@latest + + - name: generate templ files + run: templ generate + - uses: actions/setup-python@v3 - with: - python-version: '3.12.1' - uses: pre-commit/action@v3.0.1