From 21547c74d1c49f8bd82455bb20124c6c361eceed Mon Sep 17 00:00:00 2001 From: Patrick Organ Date: Thu, 31 Aug 2023 18:19:25 -0400 Subject: [PATCH 1/9] update "update-checksums" task --- Taskfile.dist.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Taskfile.dist.yaml b/Taskfile.dist.yaml index cfe95b0..3880f1b 100644 --- a/Taskfile.dist.yaml +++ b/Taskfile.dist.yaml @@ -92,11 +92,9 @@ tasks: - cp -f ./.env {{.BUILD_OUTPUT_DIR}} update-checksums: - dir: templates/remote-includes cmds: - - sha256sum *.yaml > checksums.sha256.txt - - git add checksums.sha256.txt - - git commit -m "update checksum files" + - sha256sum ./templates/remote-includes/*.yaml > ./templates/remote-includes/checksums.sha256.txt + - sed 's/\.\/templates\/remote-includes\///g' ./templates/remote-includes/checksums.sha256.txt --in-place autobuild: interactive: true From 876c3ec7f6d75af4a806e94007d76673e989639b Mon Sep 17 00:00:00 2001 From: Patrick Organ Date: Sun, 7 Jan 2024 09:38:48 -0500 Subject: [PATCH 2/9] wip --- lib/support/helpers.go | 4 +++ lib/support/helpers_test.go | 54 +++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 lib/support/helpers_test.go diff --git a/lib/support/helpers.go b/lib/support/helpers.go index fb99fcd..da11426 100644 --- a/lib/support/helpers.go +++ b/lib/support/helpers.go @@ -61,6 +61,8 @@ func PrintXMarkLine() { fmt.Print(aurora.BrightRed(" ✗\n").String()) } +// The function `FindExistingFile` takes a list of filenames and a default filename, and returns the +// first existing filename in the list or the default filename if none of the filenames exist. func FindExistingFile(filenames []string, defaultFilename string) string { for _, filename := range filenames { if _, err := os.Stat(filename); err == nil { @@ -71,6 +73,8 @@ func FindExistingFile(filenames []string, defaultFilename string) string { return defaultFilename } +// The function `GetCommandOutput` takes a command as input, executes it, and returns the output as a +// string. func GetCommandOutput(command string) string { parts := strings.Split(command, " ") diff --git a/lib/support/helpers_test.go b/lib/support/helpers_test.go new file mode 100644 index 0000000..516777f --- /dev/null +++ b/lib/support/helpers_test.go @@ -0,0 +1,54 @@ +package support + +import ( + "testing" +) + +func TestFindExistingFile(t *testing.T) { + filenames := []string{"helpers.go", "file2.txt", "file3.txt"} + defaultFilename := "default.txt" + + // Positive test case: existing file found + existingFile := FindExistingFile(filenames, defaultFilename) + if existingFile != "helpers.go" { + t.Errorf("Expected 'file1.txt', but got '%s'", existingFile) + } + + // Negative test case: no existing file found, default filename used + noExistingFile := FindExistingFile([]string{}, defaultFilename) + if noExistingFile != defaultFilename { + t.Errorf("Expected '%s', but got '%s'", defaultFilename, noExistingFile) + } +} + +func TestFindExistingFileWithEmptyFilenames(t *testing.T) { + filenames := []string{} + defaultFilename := "default.txt" + + // Negative test case: empty filenames slice + emptyFilenames := FindExistingFile(filenames, defaultFilename) + if emptyFilenames != defaultFilename { + t.Errorf("Expected '%s', but got '%s'", defaultFilename, emptyFilenames) + } +} + +func TestFindExistingFileWithNoDefaultFilename(t *testing.T) { + filenames := []string{"file1.txt", "file2.txt", "file3.txt"} + + // Negative test case: no default filename provided + noDefaultFilename := FindExistingFile(filenames, "") + if noDefaultFilename != "" { + t.Errorf("Expected empty string, but got '%s'", noDefaultFilename) + } +} + +func TestFindExistingFileWithExistingDefaultFilename(t *testing.T) { + filenames := []string{"file1.txt", "file2.txt", "file3.txt"} + defaultFilename := "file2.txt" + + // Positive test case: existing default filename found + existingDefaultFile := FindExistingFile(filenames, defaultFilename) + if existingDefaultFile != defaultFilename { + t.Errorf("Expected '%s', but got '%s'", defaultFilename, existingDefaultFile) + } +} From 22025467c4927afeeb9a3c2137ed77e19871066e Mon Sep 17 00:00:00 2001 From: Patrick Organ Date: Mon, 18 Nov 2024 09:17:50 -0500 Subject: [PATCH 3/9] upgrade tooling to latest versions --- .custom-hooks/pre-commit | 34 +++++++++---- .github/workflows/build-and-test.yml | 2 +- .github/workflows/dependabot-auto-merge.yml | 10 +++- .github/workflows/run-goreleaser.yml | 23 ++++++--- .golangci.yaml | 45 +---------------- .goreleaser.yaml | 56 ++++++++------------- go.mod | 2 +- 7 files changed, 74 insertions(+), 98 deletions(-) diff --git a/.custom-hooks/pre-commit b/.custom-hooks/pre-commit index 3bda743..c313d1c 100755 --- a/.custom-hooks/pre-commit +++ b/.custom-hooks/pre-commit @@ -1,18 +1,34 @@ #!/usr/bin/env sh PROJECT_BASE_PATH=$(git rev-parse --show-toplevel) -cd "$PROJECT_BASE_PATH" || exit 0 +cd $PROJECT_BASE_PATH -GO_FILES_STAGED=$(git diff --name-only --cached | grep -c .go) +NPX_BIN=$(which bunx npx | grep -v 'not found' | head -n 1 || echo "") +GOLINT_BIN=$(which golangci-lint | grep -v 'not found' | head -n 1 || echo "") -if [ -n "$GO_FILES_STAGED" ] && [ "$GO_FILES_STAGED" != "0" ]; then - GOLINT_BIN=$(which golangci-lint) +GIT_STAGED_FILES=$(git diff --name-only --staged) +GO_STAGED_FILES_COUNT=$(printf "$GIT_STAGED_FILES" | grep -E '\.go$' | wc -l | grep -E '[1-9][0-9]*$' || echo "0") +MARKDOWN_STAGED_FILES=$(printf "$GIT_STAGED_FILES" | grep -E '\.md$' | tr '\n' ' ') +PRETTIER_STAGED_FILES=$(printf "$GIT_STAGED_FILES" | grep -E '\.(json|yaml|yml)$' | tr '\n' ' ') - if [ -n "$GOLINT_BIN" ]; then - LAST_COMMIT=$(git rev-parse HEAD) +runCommand() { + CMD=$1 + shift 1 + echo "[pre-commit] $CMD $@" + $CMD $@ +} - echo "[pre-commit] $GOLINT_BIN run -c ./.golangci.yaml --new-from-rev $LAST_COMMIT" +if [ "$GO_STAGED_FILES_COUNT" != "0" ] && [ "$GOLINT_BIN" != "" ]; then + LAST_COMMIT=$(git rev-parse HEAD) + runCommand "$GOLINT_BIN" run -c ./.golangci.yaml --new-from-rev $LAST_COMMIT . +fi + +if [ "$MARKDOWN_STAGED_FILES" != "" ] && [ "$NPX_BIN" != "" ]; then + runCommand "$NPX_BIN" markdownlint-cli --fix $MARKDOWN_STAGED_FILES + git add $MARKDOWN_STAGED_FILES +fi - $GOLINT_BIN run -c ./.golangci.yaml --new-from-rev "$LAST_COMMIT" - fi +if [ "$PRETTIER_STAGED_FILES" != "" ] && [ "$NPX_BIN" != "" ]; then + runCommand "$NPX_BIN" prettier --write $PRETTIER_STAGED_FILES + git add $PRETTIER_STAGED_FILES fi diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index b6d0984..4b7a93d 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -10,7 +10,7 @@ on: types: [opened, edited] env: - GO_VERSION: "~1.20" + GO_VERSION: "~1.23" GO111MODULE: "on" jobs: diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml index 3c855af..d9904c6 100644 --- a/.github/workflows/dependabot-auto-merge.yml +++ b/.github/workflows/dependabot-auto-merge.yml @@ -10,16 +10,22 @@ jobs: runs-on: ubuntu-latest if: ${{ github.actor == 'dependabot[bot]' }} steps: - - name: Dependabot metadata id: metadata uses: dependabot/fetch-metadata@v2.2.0 with: github-token: "${{ secrets.GITHUB_TOKEN }}" - - name: Auto-merge Dependabot PRs + - name: Dependabot auto-merge minor & patch updates if: ${{steps.metadata.outputs.update-type != 'version-update:semver-major'}} run: gh pr merge --auto --merge "$PR_URL" env: PR_URL: ${{github.event.pull_request.html_url}} GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + + - name: Dependabot auto-merge actions major updates (if compat >= 90%) + if: ${{steps.metadata.outputs.package-ecosystem == 'github_actions' && steps.metadata.outputs.update-type == 'version-update:semver-major' && steps.metadata.outputs.compatibility-score >= 90}} + run: gh pr merge --auto --merge "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/run-goreleaser.yml b/.github/workflows/run-goreleaser.yml index ad72b74..403e6ba 100644 --- a/.github/workflows/run-goreleaser.yml +++ b/.github/workflows/run-goreleaser.yml @@ -8,18 +8,15 @@ on: permissions: contents: write - id-token: write - packages: write jobs: - - build-and-release: - runs-on: ubuntu-latest + artifact-build: + runs-on: ${{ matrix.os }} strategy: + fail-fast: false matrix: os: [ubuntu-latest] - fail-fast: false steps: - name: Install Task @@ -27,7 +24,7 @@ jobs: - uses: actions/setup-go@v5 with: - go-version: '>=1.20.0' + go-version: ">=1.23.0" - name: Checkout uses: actions/checkout@v4 @@ -36,11 +33,21 @@ jobs: - run: git fetch --force --tags + # validate the configuration file + - uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser-pro + version: latest + args: check + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} + - uses: goreleaser/goreleaser-action@v6 with: distribution: goreleaser-pro version: latest - args: release --clean --skip-docker + args: release --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} diff --git a/.golangci.yaml b/.golangci.yaml index d665498..a70c21e 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,37 +1,10 @@ -# Options for analysis running. run: - # Timeout for analysis, e.g. 30s, 5m. Default: 1m timeout: 15s modules-download-mode: readonly # Include test files or not. Default: true tests: true - # Which dirs to skip: issues from them won't be reported. - # Can use regexp here: `generated.*`, regexp is applied on full path. - # Default value is empty list, - # but default dirs are skipped independently of this option's value (see skip-dirs-use-default). - # "/" will be replaced by current OS file path separator to properly work on Windows. - skip-dirs: - - .custom-hooks - - .github - - .task - - .trunk - - .vscode - - assets - - build - - dist - - templates - - tools - - # Which files to skip: they will be analyzed, but issues from them won't be reported. - # Default value is empty list, - # but there is no need to include all autogenerated files, - # we confidently recognize autogenerated files. - # If it's not please let us know. - # "/" will be replaced by current OS file path separator to properly work on Windows. - - # Allow multiple parallel golangci-lint instances running; If false (default) - golangci-lint acquires file lock on start. allow-parallel-runners: true concurrency: 8 @@ -45,19 +18,6 @@ linters: - misspell - unused - unparam - #- errcheck - #- funlen - #- gocritic - #- gocyclo - #- goimports - #- gosec - #- gosimple - #- ineffassign - #- nestif - #- revive - #- staticcheck - #- typecheck - #- unused severity: default-severity: warning @@ -65,7 +25,7 @@ severity: linters-settings: gocyclo: - min-complexity: 20 + min-complexity: 30 funlen: lines: 100 @@ -89,5 +49,4 @@ linters-settings: locale: US nestif: - max-nesting: 3 - min-complexity: 4 # Minimal complexity of if statements to report. - Default: 5 + min-complexity: 4 # Minimal complexity of if statements to report. - Default: 5 diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 77a30c9..bbfd0a4 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,25 +1,27 @@ +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json + +version: 2 + env: - GO111MODULE=on - CGO_ENABLED=0 -dist: build - before: hooks: - - task mod + - go mod tidy - task update-version-file +dist: build + archives: - - format: tar.gz - format_overrides: + - format_overrides: - goos: windows format: zip builds: - - id: stackup - main: ./app - binary: stackup - mod_timestamp: '{{ .CommitTimestamp }}' + - main: "./main.go" + binary: "stackup" + mod_timestamp: "{{ .CommitTimestamp }}" flags: - -trimpath ldflags: @@ -28,32 +30,18 @@ builds: - linux_amd64 - darwin_arm64 - darwin_amd64 - - - id: stackup-windows - main: ./app/main-windows.go - binary: stackup - mod_timestamp: '{{ .CommitTimestamp }}' - flags: - - -trimpath - - -tags=WINDOWS - ldflags: - - -s -w -X main.build={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} - targets: - windows_amd64 -# brews: -# - -# name: stackup -# homepage: 'https://github.com/permafrost-dev/homebrew-stackup' -# description: 'a single application to manage your entire dev stack' -# download_strategy: GitHubPrivateRepositoryReleaseDownloadStrategy -# custom_require: "lib/custom_download_strategy" -# license: MIT -# repository: -# owner: permafrost-dev -# name: homebrew-stackup -# branch: main - checksum: - name_template: checksums.txt + name_template: "checksums.txt" algorithm: sha256 + +snapshot: + version_template: "{{ incpatch .Version }}-next" + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" diff --git a/go.mod b/go.mod index 58f5500..a2e05f0 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/stackup-app/stackup -go 1.20 +go 1.22 require ( github.com/blang/semver v3.5.1+incompatible From c54629c81e20c32c55879cc6b6de40211056a161 Mon Sep 17 00:00:00 2001 From: Patrick Organ Date: Mon, 18 Nov 2024 09:19:59 -0500 Subject: [PATCH 4/9] add codecov config --- .github/codecov.yml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/codecov.yml diff --git a/.github/codecov.yml b/.github/codecov.yml new file mode 100644 index 0000000..2a958dc --- /dev/null +++ b/.github/codecov.yml @@ -0,0 +1,38 @@ +codecov: + require_ci_to_pass: true + +coverage: + status: + project: + default: + informational: true + target: auto + threshold: 30% + patch: + default: + informational: true + precision: 2 + round: nearest + range: "70...100" + +parsers: + javascript: + enable_partials: yes + gcov: + branch_detection: + conditional: yes + loop: yes + method: no + macro: no + +comment: + layout: "reach,diff,flags,files,footer" + behavior: default + require_changes: true + +ignore: + - "build/" + - "dist/" + - "coverage/" + - "tools/" + - "main.go" From 78374f0b6c41dcb64c6765af44f524e4b6d0352c Mon Sep 17 00:00:00 2001 From: Patrick Organ Date: Mon, 18 Nov 2024 09:21:45 -0500 Subject: [PATCH 5/9] add codeql config --- .github/workflows/codeql.yml | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..5ba3a0d --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,51 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL Advanced" + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + schedule: + - cron: "27 22 * * 5" + +jobs: + analyze: + name: Analyze Go + runs-on: "ubuntu-latest" + permissions: + security-events: write + packages: read + actions: read + contents: read + + strategy: + fail-fast: false + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: go + build-mode: autobuild + config-file: ./.github/codeql.yml + queries: security-and-quality + # packs: codeql/go-all + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:go" From bb2facb1123baf95a852ca2c56c60585c11b3fbb Mon Sep 17 00:00:00 2001 From: Patrick Organ Date: Mon, 18 Nov 2024 09:22:43 -0500 Subject: [PATCH 6/9] add codeql config --- .github/codeql.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .github/codeql.yml diff --git a/.github/codeql.yml b/.github/codeql.yml new file mode 100644 index 0000000..bac69f9 --- /dev/null +++ b/.github/codeql.yml @@ -0,0 +1,10 @@ +name: "CodeQL" + +disable-default-queries: false + +paths: + - app + - cmd + +paths-ignore: + - tools From 07b9737548f5b7b154e66e0d5dc33bf8a9dc31d2 Mon Sep 17 00:00:00 2001 From: Patrick Organ Date: Mon, 18 Nov 2024 09:25:55 -0500 Subject: [PATCH 7/9] wip --- .github/codeql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/codeql.yml b/.github/codeql.yml index bac69f9..ca1bf90 100644 --- a/.github/codeql.yml +++ b/.github/codeql.yml @@ -4,7 +4,7 @@ disable-default-queries: false paths: - app - - cmd + - lib paths-ignore: - tools From b1c25ba861d63674801790f64864050ea86ccf70 Mon Sep 17 00:00:00 2001 From: Patrick Organ Date: Mon, 18 Nov 2024 09:26:19 -0500 Subject: [PATCH 8/9] wip --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index a2e05f0..2ca5dfb 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/stackup-app/stackup -go 1.22 +go 1.21 require ( github.com/blang/semver v3.5.1+incompatible From 468892abf30a9dee8f60549a6ed4c304e3363d88 Mon Sep 17 00:00:00 2001 From: Patrick Organ Date: Mon, 18 Nov 2024 09:28:00 -0500 Subject: [PATCH 9/9] wip --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 2ca5dfb..e41a66e 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/stackup-app/stackup -go 1.21 +go 1.21.0 require ( github.com/blang/semver v3.5.1+incompatible