diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 62fab19..215e4a1 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,4 +1,4 @@ -name: Lint +name: 🧪 Lint on: push: @@ -11,17 +11,16 @@ permissions: jobs: lint: - name: lint runs-on: ubuntu-latest steps: - - name: Checkout Code + - name: ⬇️ Checkout Code uses: actions/checkout@v5 - - name: Install Mise + - name: 📦 Install Mise run: | curl https://mise.run | sh mise install - - name: Lint + - name: 🧪 Lint run: | mise run lint diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..3fe7801 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,29 @@ +name: ☁️ Release + +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+[0-9A-Za-z]?' + +env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + +jobs: + release: + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + - name: ⬇️ Checkout Code + uses: actions/checkout@v5 + + - name: 📦 Install Mise + run: | + curl https://mise.run | sh + mise install + + - name: ☁️ Release + run: | + mise release diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ad3d513..b3b8987 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Test +name: 🧪 Test on: push: @@ -8,17 +8,16 @@ on: jobs: test: - name: test runs-on: ubuntu-latest steps: - - name: Checkout Code + - name: ⬇️ Checkout Code uses: actions/checkout@v5 - - name: Install Mise + - name: 📦 Install Mise run: | curl https://mise.run | sh mise install - - name: Test + - name: 🧪 Test run: | mise run test diff --git a/.gitignore b/.gitignore index 07a074a..054c18b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.idea /vendor /bin +/dist diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..cef0fa7 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,60 @@ +project_name: skpr + +version: 2 + +builds: + - id: skpr-cli + main: ./cmd/skpr + binary: skpr + ldflags: + - -extldflags '-static' -X github.com/skpr/cli/cmd/skpr/version.GitVersion={{.Version}} -X github.com/skpr/cli/cmd/skpr/version.BuildDate={{time "2006-01-02"}} + env: + - CGO_ENABLED=0 + goos: [ linux, darwin ] + goarch: [ amd64, arm64 ] + + - id: skpr-rsh + main: ./cmd/skpr-rsh + binary: skpr-rsh + ldflags: + - -extldflags '-static' + env: + - CGO_ENABLED=0 + goos: [ linux, darwin ] + goarch: [ amd64, arm64 ] + +archives: + - id: nix + builds: [ skpr-cli, skpr-rsh ] + name_template: '{{ .ProjectName }}_{{ .Version }}_{{ if eq .Os "darwin" }}macOS{{ else }}{{ .Os }}{{ end }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' + wrap_in_directory: true + format: tar.gz + files: + - ./share/man/man1/skpr*.1 + +release: + prerelease: auto + name_template: "Skpr CLI {{.Version}}" + github: + owner: skpr + name: cli + +dockers: + - ids: + - skpr-cli + - skpr-rsh + image_templates: + - ghcr.io/skpr/cli:latest + - ghcr.io/skpr/cli:{{ .Tag }} + dockerfile: Dockerfile + build_flag_templates: + - "--pull" + +nfpms: + - license: Proprietary + maintainer: Skpr + homepage: https://www.skpr.io + recommends: [ rsync, docker.io ] + description: CLI for the Skpr Hosting Platform + builds: [ skpr-cli, skpr-rsh ] + formats: [ deb, rpm ] diff --git a/.mise.toml b/.mise.toml index 8778eb3..f3a3ecb 100644 --- a/.mise.toml +++ b/.mise.toml @@ -34,3 +34,8 @@ run = "golangci-lint run" description = "Checks to verify code correctness" run = "go test -cover ./..." depends = ["vendor"] + +[tasks.release] +description = "Release the command line interface" +run = "goreleaser" +depends = ["vendor"] diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e7a8ab7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM alpine:3.21 + +RUN apk --no-cache add bash ca-certificates git openssh-client curl rsync docker-cli jq yq +COPY skpr skpr-rsh /usr/local/bin/ + +CMD ["skpr"] diff --git a/cmd/skpr/version/command.go b/cmd/skpr/version/command.go index 4e1bb04..edf0a70 100644 --- a/cmd/skpr/version/command.go +++ b/cmd/skpr/version/command.go @@ -1,8 +1,9 @@ package version import ( - v1version "github.com/skpr/cli/internal/command/version" "github.com/spf13/cobra" + + v1version "github.com/skpr/cli/internal/command/version" ) var ( @@ -38,7 +39,7 @@ func NewCommand() *cobra.Command { Long: cmdLong, Example: cmdExample, RunE: func(cmd *cobra.Command, args []string) error { - return command.Run(cmd.Context()) + return command.Run(cmd.Context(), GitVersion, BuildDate) }, } diff --git a/internal/command/version/command.go b/internal/command/version/command.go index 9f10c69..c8c2a4f 100644 --- a/internal/command/version/command.go +++ b/internal/command/version/command.go @@ -11,25 +11,16 @@ import ( "github.com/skpr/cli/internal/version" ) -var ( - // GitVersion overridden at build time by: - // -ldflags="-X github.com/skpr/cli/cmd/skpr/version.GitVersion=${VERSION}" - GitVersion string - // BuildDate overridden at build time by: - // -ldflags="-X github.com/skpr/cli/cmd/skpr/version.BuildDate=${BUILD_DATE}" - BuildDate string -) - // Command that print the client and server versions. type Command struct { Debug bool } // Run the command. -func (cmd *Command) Run(ctx context.Context) error { +func (cmd *Command) Run(ctx context.Context, gitVersion, buildDate string) error { params := version.PrintParams{ - ClientVersion: GitVersion, - ClientBuildDate: BuildDate, + ClientVersion: gitVersion, + ClientBuildDate: buildDate, } // Get server version if we are in a project directory.