diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 13355a7..297891c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,23 +1,45 @@ name: Build on: - - push - - pull_request + push: + branches: + - main + - master + pull_request: + +permissions: + contents: read jobs: build: runs-on: ubuntu-latest + permissions: + contents: read strategy: matrix: - go-version: ["1.18.x", "1.19.x", "1.20.x", "1.21.x"] + go-version: + [ + "1.18.x", + "1.19.x", + "1.20.x", + "1.21.x", + "1.22.x", + "1.23.x", + "1.24.x", + "1.25.x", + ] steps: - name: Checkout - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + fetch-depth: 0 + persist-credentials: false + - name: Set up Go + uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0 with: go-version: ${{ matrix.go-version }} - name: Cache mods - uses: actions/cache@v3 + uses: actions/cache@6f8efc29b200d32929f49075959781ed54ec270c # v3.4.2 with: path: | ~/.cache/go-build @@ -27,3 +49,46 @@ jobs: run: go mod download - name: Build run: go build + + zizmor: + runs-on: ubuntu-latest + permissions: + contents: read + security-events: write + steps: + - name: Checkout + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + - name: Run zizmor + uses: zizmorcore/zizmor-action@e639db99335bc9038abc0e066dfcd72e23d26fb4 # v0.3.0 + with: + inputs: .github/workflows/ + + goreleaser-snapshot: + runs-on: ubuntu-latest + permissions: + contents: read + if: github.event_name == 'pull_request' + steps: + - name: Checkout + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + fetch-depth: 0 + persist-credentials: false + - name: Set up Go + uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0 + with: + go-version: "1.24.x" + cache: false + - name: Run GoReleaser (snapshot) + uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0 + with: + distribution: goreleaser + version: latest + args: release --snapshot --clean + - name: Upload artifacts + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 + with: + name: dist + path: dist/ diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8554257..9afa884 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,20 +4,28 @@ on: - push - pull_request +permissions: + contents: read + jobs: lint: runs-on: ubuntu-latest + permissions: + contents: read strategy: matrix: - go-version: ["1.21.x"] + go-version: ["1.24.x"] steps: - name: Checkout - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + - name: Set up Go + uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0 with: go-version: ${{ matrix.go-version }} - name: Cache mods - uses: actions/cache@v3 + uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1 with: path: | ~/.cache/go-build @@ -26,8 +34,8 @@ jobs: - name: Download mods run: go mod download - name: Lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0 with: - version: v1.54.1 + version: v2.7.2 args: --timeout 5m0s skip-cache: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..62e4e87 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,32 @@ +name: Release + +on: + push: + tags: + - "v*" + +permissions: + contents: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + fetch-depth: 0 + persist-credentials: false + - name: Set up Go + uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0 + with: + go-version: "1.24.x" + cache: false + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0 + with: + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.golangci.yml b/.golangci.yml index 37030a8..ce2c009 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,29 +1,26 @@ -run: - skip-dirs: - - .tmp - - vendor +version: "2" linters: - disable-all: true + default: none enable: - # - errcheck - gocritic - goconst - - goimports - - gosimple - govet - ineffassign - staticcheck - - stylecheck - - typecheck - unused + disable: + - errcheck + exclusions: + rules: + # Suppress ST1005 - error strings capitalization + - linters: [staticcheck] + text: "error strings should not be capitalized" + settings: + govet: + enable: + - shadow -linters-settings: - govet: - # report about shadowed variables - check-shadowing: true - -issues: - exclude-rules: - - linters: [stylecheck] - text: "ST1005:" +formatters: + enable: + - goimports diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..cd2ce5a --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,55 @@ +version: 2 + +before: + hooks: + - go mod tidy + +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + - freebsd + goarch: + - amd64 + - arm64 + - arm + - "386" + ignore: + # macOS doesn't support 32-bit architectures + - goos: darwin + goarch: "386" + - goos: darwin + goarch: arm + ldflags: + - -s -w + - -X main.version={{.Version}} + +archives: + - name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}" + files: + - LICENSE* + - README* + - CHANGELOG* + +checksum: + name_template: "checksums.txt" + algorithm: sha256 + +snapshot: + version_template: "{{ incpatch .Version }}-next" + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + - "^chore:" + - "^ci:" + +release: + draft: false + prerelease: auto + name_template: "{{.ProjectName}} {{.Version}}" diff --git a/build-all.sh b/build-all.sh deleted file mode 100755 index def3ebe..0000000 --- a/build-all.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh -version=$(/bin/sh -c 'git describe --always --tags --abbrev=0') -rm -rf ./dist - -env CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags "-s -w" -a -o dist/overmind . -gzip -9 -S "-$version-linux-arm.gz" dist/overmind - -env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w" -a -o dist/overmind . -gzip -9 -S "-$version-linux-arm64.gz" dist/overmind - -env CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags "-s -w" -a -o dist/overmind . -gzip -9 -S "-$version-linux-386.gz" dist/overmind - -env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -a -o dist/overmind . -gzip -9 -S "-$version-linux-amd64.gz" dist/overmind - -env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w" -a -o dist/overmind . -gzip -9 -S "-$version-macos-amd64.gz" dist/overmind - -env CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w" -a -o dist/overmind . -gzip -9 -S "-$version-macos-arm64.gz" dist/overmind - -env CGO_ENABLED=0 GOOS=freebsd GOARCH=arm go build -ldflags "-s -w" -a -o dist/overmind . -gzip -9 -S "-$version-freebsd-arm.gz" dist/overmind - -env CGO_ENABLED=0 GOOS=freebsd GOARCH=386 go build -ldflags "-s -w" -a -o dist/overmind . -gzip -9 -S "-$version-freebsd-386.gz" dist/overmind - -env CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags "-s -w" -a -o dist/overmind . -gzip -9 -S "-$version-freebsd-amd64.gz" dist/overmind - -for filename in dist/*.gz; do - sha256sum -bz $filename | awk '{printf "%s",$1}' > "$filename.sha256sum" -done diff --git a/go.mod b/go.mod index d5ed7be..241fca0 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/DarthSim/overmind/v2 go 1.21 require ( + github.com/Envek/godotenv v0.0.0-20240326021258-e36c8a003587 github.com/matoous/go-nanoid v1.5.0 github.com/sevlyar/go-daemon v0.1.6 github.com/urfave/cli v1.22.12 @@ -10,7 +11,6 @@ require ( ) require ( - github.com/Envek/godotenv v0.0.0-20240326021258-e36c8a003587 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect diff --git a/justfile b/justfile new file mode 100644 index 0000000..0c7240a --- /dev/null +++ b/justfile @@ -0,0 +1,36 @@ +# Build a local development version +build: + go build -ldflags "-X main.version=dev" -o overmind . + +# Run tests +test: + go test -v ./... + +# Run linter +lint: + golangci-lint run --timeout 5m0s + +# Build a snapshot release (useful for testing) +snapshot: + goreleaser release --snapshot --clean + +# Check if the goreleaser config is valid +check-config: + goreleaser check + +# Clean build artifacts +clean: + rm -rf ./dist + rm -f overmind + +# Show current version from git tags +version: + @git describe --always --tags --abbrev=0 2>/dev/null || echo "no tags found" + +# Install goreleaser (if not already installed) +install-goreleaser: + @which goreleaser > /dev/null || (echo "Installing goreleaser..." && go install github.com/goreleaser/goreleaser/v2@latest) + +# Local release (requires goreleaser to be installed) +release: install-goreleaser + goreleaser release --clean diff --git a/main.go b/main.go index 8ad8f56..8a59ea9 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,8 @@ import ( "github.com/urfave/cli" ) -const version = "2.5.1" +// version will be set by goreleaser via ldflags +var version = "dev" func socketFlags(s, n *string) []cli.Flag { return []cli.Flag{