From adb9923f11e57040224189b43c673f3eb8ee2935 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Wed, 15 Nov 2023 07:50:48 -0500 Subject: [PATCH 01/25] Support for dynamic golangci-lint matrix --- .github/workflows/golangci-lint.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 41e66a23..6ec9770d 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -20,8 +20,23 @@ on: - ".github/dependabot.yml" jobs: + prepare-matrix: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - name: Fetch Repository + uses: actions/checkout@v4 + - id: set-matrix + run: | + echo "::set-output name=matrix::$(find . -type d -not -path '*/\.*' | jq -R -s -c 'split("\n")[:-1]')" + golangci-lint: + needs: prepare-matrix runs-on: ubuntu-latest + strategy: + matrix: + directory: ${{fromJson(needs.prepare-matrix.outputs.matrix)}} steps: - name: Fetch Repository uses: actions/checkout@v4 @@ -29,3 +44,4 @@ jobs: uses: reviewdog/action-golangci-lint@v2 with: golangci_lint_flags: "--tests=false" + working-directory: ${{ matrix.directory }} From 947d230e2003c42b89ba075f0295f741f52fa696 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Wed, 15 Nov 2023 08:00:02 -0500 Subject: [PATCH 02/25] Update set-output, fix keyvalue error with reviewdog --- .github/workflows/golangci-lint.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 6ec9770d..766566c8 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -20,7 +20,7 @@ on: - ".github/dependabot.yml" jobs: - prepare-matrix: + generate-matrix: runs-on: ubuntu-latest outputs: matrix: ${{ steps.set-matrix.outputs.matrix }} @@ -29,14 +29,15 @@ jobs: uses: actions/checkout@v4 - id: set-matrix run: | - echo "::set-output name=matrix::$(find . -type d -not -path '*/\.*' | jq -R -s -c 'split("\n")[:-1]')" + # Get all directories, skip hidden + echo "$(find . -type d -not -path '*/\.*' | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT golangci-lint: - needs: prepare-matrix + needs: generate-matrix runs-on: ubuntu-latest strategy: matrix: - directory: ${{fromJson(needs.prepare-matrix.outputs.matrix)}} + modules: ${{fromJson(needs.generate-matrix.outputs.matrix)}} steps: - name: Fetch Repository uses: actions/checkout@v4 @@ -44,4 +45,6 @@ jobs: uses: reviewdog/action-golangci-lint@v2 with: golangci_lint_flags: "--tests=false" - working-directory: ${{ matrix.directory }} + workdir: ${{ matrix.modules }} + fail_on_error: true + cache: false From daaf02865ee1b1038c4b4f9ef6e53e3ced5f8c79 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Wed, 15 Nov 2023 08:02:47 -0500 Subject: [PATCH 03/25] Fix issue with matrix format --- .github/workflows/golangci-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 766566c8..ea7e2a95 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -30,7 +30,7 @@ jobs: - id: set-matrix run: | # Get all directories, skip hidden - echo "$(find . -type d -not -path '*/\.*' | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT + echo "matrix=$(find . -type d -not -path '*/\.*' | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_ENV golangci-lint: needs: generate-matrix From 05d962c0042b4d61f522d035fdae2f5699e3d6da Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Wed, 15 Nov 2023 08:06:44 -0500 Subject: [PATCH 04/25] Print matrix directly to env --- .github/workflows/golangci-lint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index ea7e2a95..99f733b7 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -29,8 +29,8 @@ jobs: uses: actions/checkout@v4 - id: set-matrix run: | - # Get all directories, skip hidden - echo "matrix=$(find . -type d -not -path '*/\.*' | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_ENV + DIRECTORIES=$(find . -type d -not -path '*/\.*' | jq -R -s -c 'split("\n")[:-1]') + echo "matrix=${DIRECTORIES}" >> $GITHUB_OUTPUT golangci-lint: needs: generate-matrix From 43a6e9526e21815358bafece81844118b6534509 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Wed, 15 Nov 2023 08:10:21 -0500 Subject: [PATCH 05/25] Enable verbose for golangci-lint --- .github/workflows/golangci-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 99f733b7..402b85f4 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -44,7 +44,7 @@ jobs: - name: Run golangci-lint uses: reviewdog/action-golangci-lint@v2 with: - golangci_lint_flags: "--tests=false" + golangci_lint_flags: "--tests=false --verbose" workdir: ${{ matrix.modules }} fail_on_error: true cache: false From 748df3e75ae531a34389619d7b8ebd0ef3848c9a Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Wed, 15 Nov 2023 08:16:42 -0500 Subject: [PATCH 06/25] Add timeout and enable all linters --- .github/workflows/golangci-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 402b85f4..95c44b39 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -44,7 +44,7 @@ jobs: - name: Run golangci-lint uses: reviewdog/action-golangci-lint@v2 with: - golangci_lint_flags: "--tests=false --verbose" + golangci_lint_flags: "--tests=false --verbose --timeout=5m --enable-all" workdir: ${{ matrix.modules }} fail_on_error: true cache: false From 5bcfa0af15778231e0b8fd7b45b5837e93c3f987 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Wed, 15 Nov 2023 08:34:46 -0500 Subject: [PATCH 07/25] Remove verbose --- .github/workflows/golangci-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 95c44b39..ae4e3149 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -44,7 +44,7 @@ jobs: - name: Run golangci-lint uses: reviewdog/action-golangci-lint@v2 with: - golangci_lint_flags: "--tests=false --verbose --timeout=5m --enable-all" + golangci_lint_flags: "--tests=false --timeout=5m --enable-all" workdir: ${{ matrix.modules }} fail_on_error: true cache: false From dcc5fa94518915c72d3af719c4f9475352447847 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Wed, 15 Nov 2023 08:37:49 -0500 Subject: [PATCH 08/25] Disable filters from reviewdog --- .github/workflows/golangci-lint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index ae4e3149..4d149062 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -47,4 +47,5 @@ jobs: golangci_lint_flags: "--tests=false --timeout=5m --enable-all" workdir: ${{ matrix.modules }} fail_on_error: true + filter_mode: nofilter cache: false From 69c06f820ef65cef99d74d4d6cf6697fd692c5f7 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Wed, 15 Nov 2023 08:40:38 -0500 Subject: [PATCH 09/25] Disable enable-all --- .github/workflows/golangci-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 4d149062..e62eb8d0 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -44,7 +44,7 @@ jobs: - name: Run golangci-lint uses: reviewdog/action-golangci-lint@v2 with: - golangci_lint_flags: "--tests=false --timeout=5m --enable-all" + golangci_lint_flags: "--tests=false --timeout=5m" workdir: ${{ matrix.modules }} fail_on_error: true filter_mode: nofilter From 44604ef0ee2a480b3441aab5975142087ee01a24 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Wed, 15 Nov 2023 08:44:39 -0500 Subject: [PATCH 10/25] Fix golangci-lint issue for AzureBlob --- azureblob/azureblob.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azureblob/azureblob.go b/azureblob/azureblob.go index 47e36bee..20073152 100644 --- a/azureblob/azureblob.go +++ b/azureblob/azureblob.go @@ -108,7 +108,7 @@ func (s *Storage) Reset() error { } } if errCounter > 0 { - return errors.New(fmt.Sprintf("%d errors occured while resetting", errCounter)) + return fmt.Errorf("%d errors occured while resetting", errCounter) } return nil } From fc7438bcda35c472eb4da15b1a00bca886747946 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Wed, 15 Nov 2023 08:45:39 -0500 Subject: [PATCH 11/25] Remove errors import --- azureblob/azureblob.go | 1 - 1 file changed, 1 deletion(-) diff --git a/azureblob/azureblob.go b/azureblob/azureblob.go index 20073152..cae22a61 100644 --- a/azureblob/azureblob.go +++ b/azureblob/azureblob.go @@ -2,7 +2,6 @@ package azureblob import ( "context" - "errors" "fmt" "io" "time" From 4b89c873365e71282052149604afb8b620b911b8 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Wed, 15 Nov 2023 08:48:21 -0500 Subject: [PATCH 12/25] Fix golangci issues with MySQL --- mysql/mysql.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/mysql/mysql.go b/mysql/mysql.go index b2d86fcf..06509e64 100644 --- a/mysql/mysql.go +++ b/mysql/mysql.go @@ -105,8 +105,6 @@ func New(config ...Config) *Storage { return store } -var noRows = "sql: no rows in result set" - // Get value by key func (s *Storage) Get(key string) ([]byte, error) { if len(key) <= 0 { @@ -136,7 +134,6 @@ func (s *Storage) Get(key string) ([]byte, error) { return data, nil } -// Set key with value // Set key with value func (s *Storage) Set(key string, val []byte, exp time.Duration) error { // Ain't Nobody Got Time For That From 9190b12c2eefc055be15c464aae9b00433d90ac2 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Thu, 16 Nov 2023 08:22:40 -0500 Subject: [PATCH 13/25] Replace NewClient with mongo.Connect --- .github/workflows/golangci-lint.yml | 4 ++-- mongodb/mongodb.go | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index e62eb8d0..c759321f 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -1,4 +1,4 @@ -name: Golangci Lint Check +name: Golangci-Lint Check on: push: @@ -32,7 +32,7 @@ jobs: DIRECTORIES=$(find . -type d -not -path '*/\.*' | jq -R -s -c 'split("\n")[:-1]') echo "matrix=${DIRECTORIES}" >> $GITHUB_OUTPUT - golangci-lint: + lint: needs: generate-matrix runs-on: ubuntu-latest strategy: diff --git a/mongodb/mongodb.go b/mongodb/mongodb.go index d4c359bb..a42fbbe9 100644 --- a/mongodb/mongodb.go +++ b/mongodb/mongodb.go @@ -53,11 +53,13 @@ func New(config ...Config) *Storage { } // Set mongo options - opt := options.Client() - opt.ApplyURI(dsn) + opt := options.Client().ApplyURI(dsn) - // Create mongo client - client, err := mongo.NewClient(opt) + // Create and connect the mongo client in one step + ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) + defer cancel() + + client, err := mongo.Connect(ctx, opt) if err != nil { panic(err) } From 748f85b33fedbc5fa3d3a34aa32a316f77916c0a Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Thu, 16 Nov 2023 08:26:13 -0500 Subject: [PATCH 14/25] Fix duplicated code --- mongodb/mongodb.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/mongodb/mongodb.go b/mongodb/mongodb.go index a42fbbe9..4164551f 100644 --- a/mongodb/mongodb.go +++ b/mongodb/mongodb.go @@ -64,12 +64,6 @@ func New(config ...Config) *Storage { panic(err) } - ctx, cancel := context.WithTimeout(context.TODO(), 20*time.Second) - defer cancel() - if err = client.Connect(ctx); err != nil { - panic(err) - } - // verify that the client can connect if err = client.Ping(context.Background(), nil); err != nil { panic(err) From 30da7363a038bf48518d1890d821c67d9f3e2b63 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Thu, 16 Nov 2023 08:44:21 -0500 Subject: [PATCH 15/25] Fix lint issues with pebble and sqlite3 --- pebble/pebble.go | 9 ++------- sqlite3/sqlite3.go | 2 -- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/pebble/pebble.go b/pebble/pebble.go index e59e6e73..e0573199 100644 --- a/pebble/pebble.go +++ b/pebble/pebble.go @@ -130,11 +130,6 @@ func isValid(fp string) bool { return false } - err = os.Remove(fp) // And delete it - - if err != nil { - return false - } - - return true + err = os.Remove(fp) + return err == nil } diff --git a/sqlite3/sqlite3.go b/sqlite3/sqlite3.go index 7070a3b8..0e5f7733 100644 --- a/sqlite3/sqlite3.go +++ b/sqlite3/sqlite3.go @@ -22,8 +22,6 @@ type Storage struct { } var ( - checkSchemaMsg = "The `v` row has an incorrect data type. " + - "It should be BLOB but is instead %s. This will cause encoding-related panics if the DB is not migrated (see https://github.com/gofiber/storage/blob/main/MIGRATE.md)." dropQuery = `DROP TABLE IF EXISTS %s;` initQuery = []string{ `CREATE TABLE IF NOT EXISTS %s ( From da12c5512d585367544cb8487b554ba8cb4a97d4 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Thu, 16 Nov 2023 08:54:14 -0500 Subject: [PATCH 16/25] Only process folders that have changes --- .github/workflows/golangci-lint.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index c759321f..d325b3b7 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -29,8 +29,17 @@ jobs: uses: actions/checkout@v4 - id: set-matrix run: | - DIRECTORIES=$(find . -type d -not -path '*/\.*' | jq -R -s -c 'split("\n")[:-1]') - echo "matrix=${DIRECTORIES}" >> $GITHUB_OUTPUT + # Get list of changed files + if [[ ${{ github.event_name }} == 'pull_request' ]]; then + FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }}) + else + FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }}) + fi + + # Extract directories from changed files, convert to JSON and export + DIRECTORIES=$(echo "$FILES" | xargs -L1 dirname | sort -u) + JSON_ARRAY=$(echo "$DIRECTORIES" | jq -R -s -c 'split("\n")[:-1]') + echo "matrix=${JSON_ARRAY}" >> $GITHUB_OUTPUT lint: needs: generate-matrix From 7685bbbdf4890ce6de9e6a4d7e17850611194fd2 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Thu, 16 Nov 2023 08:58:08 -0500 Subject: [PATCH 17/25] Increase git fetch, compare hashes --- .github/workflows/golangci-lint.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index d325b3b7..8a18b7a9 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -27,13 +27,19 @@ jobs: steps: - name: Fetch Repository uses: actions/checkout@v4 + with: + fetch-depth: 0 - id: set-matrix run: | # Get list of changed files if [[ ${{ github.event_name }} == 'pull_request' ]]; then - FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }}) + BASE_SHA=${{ github.event.pull_request.base.sha }} + HEAD_SHA=${{ github.event.pull_request.head.sha }} + FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA) else - FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }}) + BEFORE_SHA=${{ github.event.before }} + AFTER_SHA=${{ github.event.after }} + FILES=$(git diff --name-only $BEFORE_SHA $AFTER_SHA) fi # Extract directories from changed files, convert to JSON and export @@ -57,4 +63,3 @@ jobs: workdir: ${{ matrix.modules }} fail_on_error: true filter_mode: nofilter - cache: false From 2a09efbde35a27ab8a2cacd1e250ddae9868eccd Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Thu, 16 Nov 2023 09:04:27 -0500 Subject: [PATCH 18/25] Simplified and add comments --- .github/workflows/golangci-lint.yml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 8a18b7a9..bae200ef 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -31,19 +31,18 @@ jobs: fetch-depth: 0 - id: set-matrix run: | - # Get list of changed files + # Determine the base and head commits for diff based on the event type if [[ ${{ github.event_name }} == 'pull_request' ]]; then - BASE_SHA=${{ github.event.pull_request.base.sha }} - HEAD_SHA=${{ github.event.pull_request.head.sha }} - FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA) + BASE_SHA="${{ github.event.pull_request.base.sha }}" + HEAD_SHA="${{ github.event.pull_request.head.sha }}" else - BEFORE_SHA=${{ github.event.before }} - AFTER_SHA=${{ github.event.after }} - FILES=$(git diff --name-only $BEFORE_SHA $AFTER_SHA) + BASE_SHA="${{ github.event.before }}" + HEAD_SHA="${{ github.event.after }}" fi - # Extract directories from changed files, convert to JSON and export - DIRECTORIES=$(echo "$FILES" | xargs -L1 dirname | sort -u) + # Extract directories from changed files, exclude hidden directories, convert to JSON and export + FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA) + DIRECTORIES=$(echo "$FILES" | xargs -L1 dirname | sort -u | grep -vE '/\.') JSON_ARRAY=$(echo "$DIRECTORIES" | jq -R -s -c 'split("\n")[:-1]') echo "matrix=${JSON_ARRAY}" >> $GITHUB_OUTPUT From 42afe64eb3fac0ca00d24bfd510192f52d806343 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Thu, 16 Nov 2023 09:06:48 -0500 Subject: [PATCH 19/25] Skip hidden directories --- .github/workflows/golangci-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index bae200ef..4c34f4a0 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -42,7 +42,7 @@ jobs: # Extract directories from changed files, exclude hidden directories, convert to JSON and export FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA) - DIRECTORIES=$(echo "$FILES" | xargs -L1 dirname | sort -u | grep -vE '/\.') + DIRECTORIES=$(echo "$FILES" | xargs -L1 dirname | grep -vE '^\./\.' | sort -u | grep -vE '^\./') JSON_ARRAY=$(echo "$DIRECTORIES" | jq -R -s -c 'split("\n")[:-1]') echo "matrix=${JSON_ARRAY}" >> $GITHUB_OUTPUT From 38f87f38c24795b99dba1efbc4f9c7fda63d8490 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Thu, 16 Nov 2023 09:08:58 -0500 Subject: [PATCH 20/25] Try to skip hidden folders this way --- .github/workflows/golangci-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 4c34f4a0..1282c6dd 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -42,7 +42,7 @@ jobs: # Extract directories from changed files, exclude hidden directories, convert to JSON and export FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA) - DIRECTORIES=$(echo "$FILES" | xargs -L1 dirname | grep -vE '^\./\.' | sort -u | grep -vE '^\./') + DIRECTORIES=$(echo "$FILES" | xargs -L1 dirname | grep -vE '^\./\.' | sort -u) JSON_ARRAY=$(echo "$DIRECTORIES" | jq -R -s -c 'split("\n")[:-1]') echo "matrix=${JSON_ARRAY}" >> $GITHUB_OUTPUT From 58fa2881580b2ac4d31b78cdef5271019218a910 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Thu, 16 Nov 2023 09:15:35 -0500 Subject: [PATCH 21/25] Filter for dirs that contain go.mod --- .github/workflows/golangci-lint.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 1282c6dd..5835140f 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -40,10 +40,11 @@ jobs: HEAD_SHA="${{ github.event.after }}" fi - # Extract directories from changed files, exclude hidden directories, convert to JSON and export - FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA) - DIRECTORIES=$(echo "$FILES" | xargs -L1 dirname | grep -vE '^\./\.' | sort -u) - JSON_ARRAY=$(echo "$DIRECTORIES" | jq -R -s -c 'split("\n")[:-1]') + # Find changed directories that contain go.mod, convert to JSON and export + GO_MOD_DIRECTORIES=$(find . -name 'go.mod' | xargs -L1 dirname | sort -u) + CHANGED_DIRECTORIES=$(echo "$FILES" | xargs -L1 dirname | sort -u) + MATCHED_DIRECTORIES=$(echo "${GO_MOD_DIRECTORIES}" "${CHANGED_DIRECTORIES}" | tr ' ' '\n' | sort | uniq -d) + JSON_ARRAY=$(echo "$MATCHED_DIRECTORIES" | jq -R -s -c 'split("\n")[:-1]') echo "matrix=${JSON_ARRAY}" >> $GITHUB_OUTPUT lint: From 9ca3516d3930fb1ca70a3f30f59c3e829307b4cc Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Thu, 16 Nov 2023 09:18:27 -0500 Subject: [PATCH 22/25] Add missing FILES variable --- .github/workflows/golangci-lint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 5835140f..158af3b4 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -41,6 +41,7 @@ jobs: fi # Find changed directories that contain go.mod, convert to JSON and export + FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA) GO_MOD_DIRECTORIES=$(find . -name 'go.mod' | xargs -L1 dirname | sort -u) CHANGED_DIRECTORIES=$(echo "$FILES" | xargs -L1 dirname | sort -u) MATCHED_DIRECTORIES=$(echo "${GO_MOD_DIRECTORIES}" "${CHANGED_DIRECTORIES}" | tr ' ' '\n' | sort | uniq -d) From b904c404bb571b95189a3e82af86409a26a4d0d7 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Fri, 17 Nov 2023 08:13:23 -0500 Subject: [PATCH 23/25] Check if go.mod exists --- .github/workflows/golangci-lint.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 158af3b4..23f833f1 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -40,12 +40,20 @@ jobs: HEAD_SHA="${{ github.event.after }}" fi - # Find changed directories that contain go.mod, convert to JSON and export + # Extract directories from changed files FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA) - GO_MOD_DIRECTORIES=$(find . -name 'go.mod' | xargs -L1 dirname | sort -u) - CHANGED_DIRECTORIES=$(echo "$FILES" | xargs -L1 dirname | sort -u) - MATCHED_DIRECTORIES=$(echo "${GO_MOD_DIRECTORIES}" "${CHANGED_DIRECTORIES}" | tr ' ' '\n' | sort | uniq -d) - JSON_ARRAY=$(echo "$MATCHED_DIRECTORIES" | jq -R -s -c 'split("\n")[:-1]') + DIRECTORIES=$(echo "$FILES" | xargs -L1 dirname | sort -u | grep -vE '/\.') + + # Check each directory for a go.mod file and prepare JSON array + GO_MOD_DIRECTORIES=() + for dir in $DIRECTORIES; do + if [[ -f "$dir/go.mod" ]]; then + GO_MOD_DIRECTORIES+=("$dir") + fi + done + JSON_ARRAY=$(printf '%s\n' "${GO_MOD_DIRECTORIES[@]}" | jq -R -s -c 'split("\n")[:-1]') + + # Export the JSON array echo "matrix=${JSON_ARRAY}" >> $GITHUB_OUTPUT lint: From a707767170823a13336df42725b27e3d55f92645 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Fri, 17 Nov 2023 08:16:33 -0500 Subject: [PATCH 24/25] Simplify the generate-matrix step --- .github/workflows/golangci-lint.yml | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 23f833f1..c3978575 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -32,28 +32,14 @@ jobs: - id: set-matrix run: | # Determine the base and head commits for diff based on the event type - if [[ ${{ github.event_name }} == 'pull_request' ]]; then - BASE_SHA="${{ github.event.pull_request.base.sha }}" - HEAD_SHA="${{ github.event.pull_request.head.sha }}" - else - BASE_SHA="${{ github.event.before }}" - HEAD_SHA="${{ github.event.after }}" - fi + BASE_SHA="${{ github.event.pull_request.base.sha || github.event.before }}" + HEAD_SHA="${{ github.event.pull_request.head.sha || github.event.after }}" - # Extract directories from changed files - FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA) - DIRECTORIES=$(echo "$FILES" | xargs -L1 dirname | sort -u | grep -vE '/\.') + # Extract changed directories that contain a go.mod file + GO_MOD_DIRECTORIES=$(git diff --name-only $BASE_SHA $HEAD_SHA | grep '/go.mod$' | xargs -L1 dirname | sort -u) - # Check each directory for a go.mod file and prepare JSON array - GO_MOD_DIRECTORIES=() - for dir in $DIRECTORIES; do - if [[ -f "$dir/go.mod" ]]; then - GO_MOD_DIRECTORIES+=("$dir") - fi - done - JSON_ARRAY=$(printf '%s\n' "${GO_MOD_DIRECTORIES[@]}" | jq -R -s -c 'split("\n")[:-1]') - - # Export the JSON array + # Convert to JSON and export + JSON_ARRAY=$(echo "$GO_MOD_DIRECTORIES" | jq -R -s -c 'split("\n")[:-1]') echo "matrix=${JSON_ARRAY}" >> $GITHUB_OUTPUT lint: From d8c4365480bcdbf0eb82e85404c821a56dc1fd6c Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Fri, 17 Nov 2023 08:22:30 -0500 Subject: [PATCH 25/25] Cleanup --- .github/workflows/golangci-lint.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index c3978575..375d7326 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -35,11 +35,19 @@ jobs: BASE_SHA="${{ github.event.pull_request.base.sha || github.event.before }}" HEAD_SHA="${{ github.event.pull_request.head.sha || github.event.after }}" - # Extract changed directories that contain a go.mod file - GO_MOD_DIRECTORIES=$(git diff --name-only $BASE_SHA $HEAD_SHA | grep '/go.mod$' | xargs -L1 dirname | sort -u) + # Extract directories from changed files, only include those with go.mod files + GO_MOD_DIRECTORIES=() + FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA | grep -vE '/\.') + DIRECTORIES=$(echo "$FILES" | xargs -L1 dirname | sort -u) - # Convert to JSON and export - JSON_ARRAY=$(echo "$GO_MOD_DIRECTORIES" | jq -R -s -c 'split("\n")[:-1]') + for dir in $DIRECTORIES; do + if [[ -f "$dir/go.mod" ]]; then + GO_MOD_DIRECTORIES+=("$dir") + fi + done + + # Export the JSON array + JSON_ARRAY=$(printf '%s\n' "${GO_MOD_DIRECTORIES[@]}" | jq -R -s -c 'split("\n")[:-1]') echo "matrix=${JSON_ARRAY}" >> $GITHUB_OUTPUT lint: