From c3b42c1d321555e878e60df5a491fec3b705f8d7 Mon Sep 17 00:00:00 2001 From: Ijas Mohamad Date: Mon, 21 Aug 2023 01:29:54 +0530 Subject: [PATCH] fix(pre-commit): Fix support for pre0-commit --- .github/workflows/ci.yml | 23 +++++-- .github/workflows/product-release.yml | 12 ++-- .gitignore | 2 +- .pre-commit-config.yaml | 17 +++++- README.md | 4 +- pickyhelpers/convert_queries.go | 66 ++++++++++----------- pickyhelpers/create_dockercompose.go | 6 +- pickyhelpers/sources/create_cd_source.go | 2 +- pickyhelpers/sources/create_infra_source.go | 6 +- 9 files changed, 82 insertions(+), 56 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4870371..b01a55f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,13 +9,16 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 with: python-version: "3.x" + - name: Set up Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 with: - go-version: 1.19 + go-version: "1.21" + cache: false - name: Install pre-commit dependencies run: | @@ -25,7 +28,9 @@ jobs: go install golang.org/x/lint/golint@latest go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest - - uses: pre-commit/action@v3.0.0 + - name: Run pre-commit + uses: pre-commit/action@v3.0.0 + - name: Build run: go build ./... @@ -36,8 +41,14 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - name: Install Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 + with: + go-version: "1.21" + cache: false + + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 with: - go-version: 1.19 - - uses: golangci/golangci-lint-action@v3.3.1 + version: 1.54 diff --git a/.github/workflows/product-release.yml b/.github/workflows/product-release.yml index 07b3f18..e5033eb 100644 --- a/.github/workflows/product-release.yml +++ b/.github/workflows/product-release.yml @@ -32,7 +32,7 @@ jobs: declare -A categoryTitle=( [fix]="
Bug Fixes
" [chore]="
Changes to build process or aux tools
" [revert]="
Revert Commits
" [build]="
Build
" [docs]="
Documentation
" [feat]="
New Features
" [perf]="
Performace Enhancements
" [refactor]="
Refactored
" [style]="
Changed Style
" [temp]="
Temporary Commit
" [test]="
Added Tests
" [ci]="
Changes to CI config
" [others]="
Others
") msg="#${{ steps.getMergedPR.outputs.number }} ${{ steps.getMergedPR.outputs.title }}" for i in $(git log --format=%h $(git merge-base HEAD^1 HEAD^2)..HEAD^2) - do + do IFS=":" read -r type cmmsg <<< $(git log --format=%B -n 1 $i) type="${type}" | xargs text_msg="    • $i - ${cmmsg}
" @@ -40,29 +40,29 @@ jobs: for i in "${!category[@]}" do if [ "${type}" == "$i" ] - then + then category[$i]+="${text_msg}" flag=0 break fi done if [ $flag -eq 1 ] - then + then category[others]+="${text_msg}" fi done for i in "${!category[@]}" do if [ ! -z "${category[$i]}" ] && [ "others" != "$i" ] - then + then msg+="${categoryTitle[$i]}${category[$i]}" fi done if [ ! -z "${category[others]}" ] - then + then msg+="${categoryTitle[others]}${category[others]}" fi - echo "New Release Note: $msg" + echo "New Release Note: $msg" echo "COMMIT_MESSAGE=${msg}" >> $GITHUB_ENV - name: Bump Version diff --git a/.gitignore b/.gitignore index def3412..5ad9fe4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ .DS_Store -coverage.out \ No newline at end of file +coverage.out diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 56a269b..50559f8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ fail_fast: true repos: - repo: https://github.com/tekwizely/pre-commit-golang - rev: v1.0.0-beta.5 + rev: v1.0.0-rc.1 hooks: - id: go-fmt - id: go-vet-mod @@ -10,3 +10,18 @@ repos: - id: go-build-repo-mod - id: go-mod-tidy - id: go-mod-tidy-repo + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - repo: https://github.com/dnephin/pre-commit-golang + rev: v0.5.1 + hooks: + - id: go-fmt + - id: go-imports + - id: no-go-testing + - id: golangci-lint + - id: go-unit-tests diff --git a/README.md b/README.md index e536b9c..8020c89 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ This tool will have support for production applications using the following tech AWS Access Key ID: MYACCESSKEYID AWS Secret Access Key: MYSECRETKEY Default region name [us-west-2]: MYAWSREGION -Default output format [None]: +Default output format [None]: ``` @@ -151,7 +151,7 @@ You can see `picky`'s home page if you initialized atleast one stack. You can ch Picky Home Preview Image -***Tips:*** +***Tips:*** - If you want to go back from the prompt, click `Ctrl + D` - If you want to exit from the prompt, click `Ctrl + C` diff --git a/pickyhelpers/convert_queries.go b/pickyhelpers/convert_queries.go index 1522f72..28c647d 100644 --- a/pickyhelpers/convert_queries.go +++ b/pickyhelpers/convert_queries.go @@ -21,10 +21,10 @@ func ConvertQueries(stack, dirName string) error { create type grant_type_enum as ENUM('CLIENT_CREDENTIALS'); create table oauth_clients ( - id INT NOT NULL PRIMARY KEY DEFAULT NEXTVAL ('oauth_clients_seq'), - client_id VARCHAR(320) NOT NULL, - client_secret VARCHAR(36) NOT NULL, - grant_type grant_type_enum, + id INT NOT NULL PRIMARY KEY DEFAULT NEXTVAL ('oauth_clients_seq'), + client_id VARCHAR(320) NOT NULL, + client_secret VARCHAR(36) NOT NULL, + grant_type grant_type_enum, created_at TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP NOT NULL, updated_at TIMESTAMP(0) NULL, CONSTRAINT oauth_clients_client_id UNIQUE (client_id) @@ -35,16 +35,16 @@ CREATE INDEX oauth_clients_client_secret_idx ON oauth_clients(client_secret);` users := `CREATE SEQUENCE users_seq; -CREATE TABLE users - ( - id INT NOT NULL DEFAULT NEXTVAL ('users_seq') PRIMARY KEY, - oauth_client_id INT NOT NULL, - first_name VARCHAR (32) NOT NULL, - last_name VARCHAR(32) NOT NULL, - email VARCHAR(32) NOT NULL, - created_at TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP NOT NULL, - CONSTRAINT users_oauth_clients_id_fk FOREIGN KEY (oauth_client_id) - REFERENCES oauth_clients (id) ON UPDATE CASCADE +CREATE TABLE users + ( + id INT NOT NULL DEFAULT NEXTVAL ('users_seq') PRIMARY KEY, + oauth_client_id INT NOT NULL, + first_name VARCHAR (32) NOT NULL, + last_name VARCHAR(32) NOT NULL, + email VARCHAR(32) NOT NULL, + created_at TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP NOT NULL, + CONSTRAINT users_oauth_clients_id_fk FOREIGN KEY (oauth_client_id) + REFERENCES oauth_clients (id) ON UPDATE CASCADE );` oauthAccessTokens := `create sequence oauth_access_tokens_seq; @@ -67,15 +67,15 @@ END; $function$; create table oauth_access_tokens ( - id INT NOT NULL PRIMARY KEY DEFAULT NEXTVAL ('oauth_access_tokens_seq'), - oauth_client_id INT NOT NULL, - access_token VARCHAR(64) NOT NULL, - expires_in INTEGER CHECK (expires_in > 0) NOT NULL, - expires_on TIMESTAMP(0) NOT NULL, - metadata JSON NOT NULL, + id INT NOT NULL PRIMARY KEY DEFAULT NEXTVAL ('oauth_access_tokens_seq'), + oauth_client_id INT NOT NULL, + access_token VARCHAR(64) NOT NULL, + expires_in INTEGER CHECK (expires_in > 0) NOT NULL, + expires_on TIMESTAMP(0) NOT NULL, + metadata JSON NOT NULL, created_at TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP NOT NULL, - updated_at TIMESTAMP(0) NULL, - CONSTRAINT oauth_access_tokens_access_token_uindex UNIQUE (access_token), + updated_at TIMESTAMP(0) NULL, + CONSTRAINT oauth_access_tokens_access_token_uindex UNIQUE (access_token), CONSTRAINT oauth_access_tokens_oauth_clients_id_fk FOREIGN KEY (oauth_client_id) REFERENCES oauth_clients (id) ON UPDATE CASCADE, CONSTRAINT oauth_access_tokens_check_metadata CHECK(is_json_valid(metadata)) );` @@ -83,15 +83,15 @@ create table oauth_access_tokens ( oauthClientResources := `create sequence oauth_client_resources_seq; create table oauth_client_resources ( - id INT NOT NULL PRIMARY KEY DEFAULT NEXTVAL ('oauth_client_resources_seq'), - oauth_client_id INT NOT NULL, - resource_type VARCHAR(36) NOT NULL, - resource_id VARCHAR(36) NOT NULL, + id INT NOT NULL PRIMARY KEY DEFAULT NEXTVAL ('oauth_client_resources_seq'), + oauth_client_id INT NOT NULL, + resource_type VARCHAR(36) NOT NULL, + resource_id VARCHAR(36) NOT NULL, created_at TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP NOT NULL, - updated_at TIMESTAMP(0) NULL, + updated_at TIMESTAMP(0) NULL, CONSTRAINT oauth_client_resources_oauth_client_id_resource_uindex UNIQUE ( oauth_client_id, resource_type, resource_id - ), + ), CONSTRAINT oauth_client_resources_oauth_clients_id_fk FOREIGN KEY (oauth_client_id) REFERENCES oauth_clients (id) ON UPDATE CASCADE ); @@ -101,11 +101,11 @@ CREATE INDEX oauth_client_resources_resource_id ON oauth_client_resources(resour oauthClientScopes := `create sequence oauth_client_scopes_seq; create table oauth_client_scopes ( - id INT NOT NULL DEFAULT NEXTVAL ('oauth_client_scopes_seq') PRIMARY KEY, - oauth_client_id INT NOT NULL, - scope VARCHAR (36) NOT NULL, - created_at TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP NOT NULL, - updated_at TIMESTAMP(0) NULL, + id INT NOT NULL DEFAULT NEXTVAL ('oauth_client_scopes_seq') PRIMARY KEY, + oauth_client_id INT NOT NULL, + scope VARCHAR (36) NOT NULL, + created_at TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP NOT NULL, + updated_at TIMESTAMP(0) NULL, constraint oauth_client_scopes_uindex UNIQUE (oauth_client_id), constraint oauth_client_scopes_oauth_clients_id_fk FOREIGN KEY (oauth_client_id) REFERENCES oauth_clients (id) ON UPDATE CASCADE );` diff --git a/pickyhelpers/create_dockercompose.go b/pickyhelpers/create_dockercompose.go index 0824d40..445ba51 100644 --- a/pickyhelpers/create_dockercompose.go +++ b/pickyhelpers/create_dockercompose.go @@ -50,7 +50,7 @@ services:` source = fmt.Sprintf(`%s # Setup {{PostgreSQL}} %s_db: - image: '{{dbVersion PostgreSQL}}' + image: '{{dbVersion PostgreSQL}}' ports: - %s:%d restart: always # This will make sure that the container comes up post unexpected shutdowns @@ -96,7 +96,7 @@ services:` source = fmt.Sprintf(`%s # Setup {{MySQL}} %s_db: - image: '{{dbVersion MySQL}}' + image: '{{dbVersion MySQL}}' ports: - %s:%d restart: always # This will make sure that the container comes up post unexpected shutdowns @@ -146,7 +146,7 @@ services:` command: ['redis-server'] {{/if}} -{{#each webDirectories}} +{{#each webDirectories}} # Setup {{this}} web {{this}}: build: diff --git a/pickyhelpers/sources/create_cd_source.go b/pickyhelpers/sources/create_cd_source.go index 2e461c1..f6ced4d 100644 --- a/pickyhelpers/sources/create_cd_source.go +++ b/pickyhelpers/sources/create_cd_source.go @@ -28,7 +28,7 @@ jobs: name: Docker build image and push runs-on: ubuntu-latest defaults: - run: + run: working-directory: ./%s strategy: matrix: diff --git a/pickyhelpers/sources/create_infra_source.go b/pickyhelpers/sources/create_infra_source.go index edb92ef..34cd4b4 100644 --- a/pickyhelpers/sources/create_infra_source.go +++ b/pickyhelpers/sources/create_infra_source.go @@ -408,7 +408,7 @@ export function %s({ stack }) { const taskDefinition = new ecs.TaskDefinition( stack, - %s${clientName}-task-${environment}%s, + %s${clientName}-task-${environment}%s, { family: %s${clientName}-task-definition-${environment}%s, compatibility: ecs.Compatibility.EC2_AND_FARGATE, @@ -439,7 +439,7 @@ export function %s({ stack }) { }); const container = taskDefinition.addContainer( - %s${clientName}-container-${environment}%s, + %s${clientName}-container-${environment}%s, { image, cpu: 512, @@ -637,7 +637,7 @@ function parseOutputs() { fileContent = JSON.stringify(fileContent, null, 2); fs.writeFileSync(outputFile, fileContent); } -parseOutputs(); +parseOutputs(); ` return source }