Skip to content
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
142 changes: 110 additions & 32 deletions .github/workflows/all-test-and-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
- 'go.sum'
- '**/*.go'

env:
LicenseHeaderPath: "./LicenseHeader"

jobs:
lint:
if: github.actor != 'dependabot[bot]'
Expand All @@ -30,24 +33,25 @@ jobs:
if: github.actor != 'dependabot[bot]'
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.unique-directories.outputs.directories }}
go_files_changed: ${{ steps.changed-go-files.outputs.any_changed }}
go_mod_changed: ${{ steps.check-go-mod.outputs.any_changed }}
should_test: ${{steps.concat_paths.outputs.RunTests}}
paths: ${{steps.concat_paths.outputs.path}}
mod_test: ${{steps.changed_mod_files.outputs.any_changed}}
go_test: ${{steps.changed_go_files.outputs.any_changed}}
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0

- name: Check for go.mod/go.sum changes
id: check-go-mod
- name: Changed mod files
id: changed_mod_files
uses: tj-actions/changed-files@v46
with:
files: |
go.mod
go.sum

- name: Get changed .go files
id: changed-go-files
- name: Changed go files
id: changed_go_files
uses: tj-actions/changed-files@v46
with:
files: |
Expand All @@ -57,35 +61,109 @@ jobs:
vendor/**

- name: Get unique directories for changed .go files
id: unique-directories
id: concat_paths

env:
modChanged: ${{ steps.changed_mod_files.outputs.any_changed }}
modChangedFiles: "./cmd/... ./internal/..."
goChanged: ${{ steps.changed_go_files.outputs.any_changed }}
goChangedFiles: ${{ steps.changed_go_files.outputs.all_changed_files }}
run: |
DIRS=$(echo '${{ steps.changed-go-files.outputs.all_changed_files }}' | jq -r '.[]' | xargs -I {} dirname {} | sort -u | jq -R -s -c 'split("\n")[:-1]')
echo "unique directories: $DIRS"
echo "directories=$DIRS" >> $GITHUB_OUTPUT
path=""
RunTests=false
if [[ $modChanged == "true" ]]; then
path=$modChangedFiles
RunTests=true
elif [[ $goChanged == "true" ]]; then
path=$(echo "$goChangedFiles" | tr ' ' '\n' | sed 's|.*|./&|' | xargs)
RunTests=true
fi
echo "path=$path" >> $GITHUB_OUTPUT
echo "RunTests=$RunTests" >> $GITHUB_OUTPUT

# only run if go.mod or go.sum changed..
full-test:
# all paths should be set as a single string, separated by space. this wall all tests tests all files in a single pass
# limits any ci to a single "run" compared to the matrix strategy. saves alot of time and resources
test:
needs: [changed-packages]
if: github.actor != 'dependabot[bot]' && needs.changed-packages.outputs.go_mod_changed == 'true'
if: needs.changed-packages.outputs.should_test == 'true'
runs-on: ubuntu-latest
steps:
- name: full test
uses: ./.github/workflows/shared/test.yaml
- uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v5
with:
full_test: true
go-version-file: "go.mod"
cache: true
- name: install tools
run: |
go install golang.org/x/vuln/cmd/govulncheck@latest
go install honnef.co/go/tools/cmd/staticcheck@latest

- name: Prepare Package Paths
id: prep_packages
shell: bash
run: |
FILE_PATHS="${{ needs.changed-packages.outputs.paths }}"
PACKAGE_PATHS=""
# If go.mod changed, the paths are already package patterns, so use them directly.
if [[ "${{ needs.changed-packages.outputs.mod_test }}" == "true" ]]; then
PACKAGE_PATHS=$FILE_PATHS
else
# Convert file list to a unique directory list, excluding the root directory './.'
PACKAGE_PATHS=$(echo "$FILE_PATHS" | tr ' ' '\n' | xargs -I {} dirname {} | sort -u | grep -v -x "\." | sed 's|.*|./&|' | xargs)
fi
echo "Prepared Package Paths: $PACKAGE_PATHS"
echo "package_paths=$PACKAGE_PATHS" >> "$GITHUB_OUTPUT"
- name: Run staticcheck
id: staticcheck
run: |
staticcheck ${{ steps.prep_packages.outputs.package_paths}}
- name: Run tests
id : test
run: |
go test -race ${{ steps.prep_packages.outputs.package_paths}}
- name: Run govulncheck
id : check-vuln
run: |
govulncheck -show verbose ${{ steps.prep_packages.outputs.package_paths}}

- name: Check File Header for License
id : check-license
run: |
# 1. Validate that the path variable is set and the file exists
if [ -z "$LicenseHeaderPath" ]; then
echo "::error::Required 'LicenseHeaderPath' environment variable is not set."
exit 1
fi
if [ ! -f "$LicenseHeaderPath" ]; then
echo "::error::License header file not found at '$LicenseHeaderPath'."
exit 1
fi

# 2. Read the expected license string from the file
LICENSE_STRING=$(cat "$LicenseHeaderPath")

# 3. Get the space-delimited list of files to check
path="${{ needs.changed-packages.outputs.paths }}"

echo "Checking for license header in the following files:"
echo "$path"
echo "---"

# 4. Loop through files and check the first 20 lines for the license string
for file in $path; do
if [[ "$file" != *.go ]]; then
echo "Skipping non-Go file: $file"
continue
fi

echo "Checking: $file"
if ! head -n 20 "$file" | grep -q -F -i "$LICENSE_STRING"; then
echo "::error file=$file::File does not contain the required license header in its first 20 lines."
exit 1
fi
done

echo "---"
echo "Success! All checked files contain the license header."

# only run if mod has not changed and *.go files have changed
run_tests:
needs: [changed-packages]
if: github.actor != 'dependabot[bot]' && (needs.changed-packages.outputs.go_files_changed == 'true' || needs.changed-packages.outputs.go_mod_changed == 'false')
runs-on: ubuntu-latest
strategy:
matrix:
packages: ${{ fromJSON(needs.changed-packages.outputs.matrix) }}
fail-fast: false
steps:
- name: Package test
uses: ./.github/workflows/shared/test.yaml
with:
path: ${{ matrix.packages }}
20 changes: 3 additions & 17 deletions .github/workflows/dev-changelog-on-pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,12 @@ env:
title : ${{ github.event.pull_request.title }}
header: "## Changes"


jobs:
check_if_changelog_exists:
if: ${{github.actor != 'dependabot[bot]'}}
runs-on: ubuntu-latest
outputs:
changelog_exists: ${{ steps.check_changelog.outputs.changelog_exists }}
steps:
- name: Check if changelog fragment exists
id: check_changelog
uses: ./.github/workflows/shared/check_changelog-file.yaml
with:
pr-number: ${{ github.event.pull_request.number }}
repo: ${{ github.event.pull_request.head.repo.full_name }}
commit-ref: ${{ github.event.pull_request.head.ref }}
check_changelog_exist: true
changelog-text: ""
create-changelog-fragment:
runs-on: ubuntu-latest
needs: check_if_changelog_exists
if: needs.check_if_changelog_exists.outputs.changelog_exists == 'false'
# needs: check_if_changelog_exists
# if: needs.check_if_changelog_exists.outputs.changelog_exists == 'false'
permissions:
contents: write
steps:
Expand Down
2 changes: 2 additions & 0 deletions LicenseHeader
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
5 changes: 5 additions & 0 deletions changelog/current/86.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@WithHolm

- update license
- add license to all files
- add test for license on new files
3 changes: 3 additions & 0 deletions cmd/credits.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

// Package cmd contains the polyenv cli components
package cmd

Expand Down
3 changes: 3 additions & 0 deletions cmd/current-add.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

package cmd

import (
Expand Down
3 changes: 3 additions & 0 deletions cmd/current-edit.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

package cmd

// import (
Expand Down
3 changes: 3 additions & 0 deletions cmd/current-export.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

package cmd

import (
Expand Down
3 changes: 3 additions & 0 deletions cmd/current-pull.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

package cmd

import (
Expand Down
3 changes: 3 additions & 0 deletions cmd/current-push.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

package cmd

// import (
Expand Down
3 changes: 3 additions & 0 deletions cmd/current.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

package cmd

import (
Expand Down
6 changes: 5 additions & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

package cmd

import (
Expand All @@ -16,7 +19,8 @@ import (

var vaultType string
var initargs []string
var acceptPolyenvDefaults bool

// var acceptPolyenvDefaults bool
var vaultTypes []string

// var checkgitignore bool
Expand Down
3 changes: 3 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

package cmd

import (
Expand Down
3 changes: 3 additions & 0 deletions cmd/status.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

package cmd

import (
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/withholm/polyenv

go 1.24.0

toolchain go1.24.1
go 1.24.6

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.19.0
Expand Down
3 changes: 3 additions & 0 deletions internal/model/plugins.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

package model

type Source interface {
Expand Down
3 changes: 3 additions & 0 deletions internal/model/secret.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

package model

import (
Expand Down
3 changes: 3 additions & 0 deletions internal/model/secret_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

package model

import (
Expand Down
3 changes: 3 additions & 0 deletions internal/model/vault.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

// Package model contains all models for polyenv
package model

Expand Down
3 changes: 3 additions & 0 deletions internal/plugin/a_main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

// Package plugin contains the polyenv plugin
package plugin

Expand Down
3 changes: 3 additions & 0 deletions internal/plugin/f_azdevops.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

package plugin

import (
Expand Down
3 changes: 3 additions & 0 deletions internal/plugin/f_dotenv.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

package plugin

import (
Expand Down
3 changes: 3 additions & 0 deletions internal/plugin/f_json.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

package plugin

import (
Expand Down
3 changes: 3 additions & 0 deletions internal/plugin/f_passthrough.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

package plugin

import (
Expand Down
3 changes: 3 additions & 0 deletions internal/plugin/f_pick.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

package plugin

import (
Expand Down
3 changes: 3 additions & 0 deletions internal/plugin/f_posix.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

package plugin

import (
Expand Down
3 changes: 3 additions & 0 deletions internal/plugin/f_pwsh.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

package plugin

import (
Expand Down
3 changes: 3 additions & 0 deletions internal/plugin/f_stats.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

package plugin

import (
Expand Down
Loading