From 0a6880822b7d01762f59749200d3feb75d8378b8 Mon Sep 17 00:00:00 2001 From: Trayan Azarov Date: Sat, 2 Mar 2024 19:08:06 +0200 Subject: [PATCH 1/4] GH Actions --- .github/workflows/lint.yaml | 28 ++++++++++++++++++++++++ .github/workflows/package.yaml | 40 ++++++++++++++++++++++++++++++++++ go.mod | 2 +- 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/lint.yaml create mode 100644 .github/workflows/package.yaml diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..2d8d58d --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,28 @@ +name: Go Lint + +on: + pull_request: {} + +jobs: + lint: + runs-on: ubuntu-latest + permissions: + # Required: allow read access to the content for analysis. + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + pull-requests: read + # Optional: Allow write access to checks to allow the action to annotate code in the PR. + checks: write + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version-file: 'go.mod' + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: latest \ No newline at end of file diff --git a/.github/workflows/package.yaml b/.github/workflows/package.yaml new file mode 100644 index 0000000..d55dfe4 --- /dev/null +++ b/.github/workflows/package.yaml @@ -0,0 +1,40 @@ +name: package +on: + release: + types: [published] +jobs: + xgo: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Build + uses: crazy-max/ghaction-xgo@v3 + with: + go_version: 1.22 + dest: build + prefix: chroma + targets: windows/amd64,linux/amd64,linux/arm64,darwin/arm64 + ldflags: -s -w + release_assets: + needs: xgo + runs-on: ${{ matrix.config.os }} + strategy: + matrix: + config: + - os: ubuntu-latest + - os: macos-latest + - os: windows-latest + steps: + - name: Checkout code + uses: actions/checkout@v1 + # Build steps for your application + - name: Upload release assets + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.create_release.outputs.upload_url }} + asset_name: program-name-${{ matrix.config.os }} + asset_path: ./path/to/your/file + asset_content_type: application/octet-stream diff --git a/go.mod b/go.mod index b9da9c8..f9cb6b7 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module chroma -go 1.22 +go 1.20 require ( github.com/go-playground/validator/v10 v10.19.0 From 31982c5ba92344ba0cd702b039b4b6d82c275958 Mon Sep 17 00:00:00 2001 From: Trayan Azarov Date: Sun, 3 Mar 2024 17:55:56 +0200 Subject: [PATCH 2/4] feat: Added go-releaser --- .github/workflows/package.yaml | 40 --------------------- .github/workflows/release.yaml | 63 ++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 40 deletions(-) delete mode 100644 .github/workflows/package.yaml create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/package.yaml b/.github/workflows/package.yaml deleted file mode 100644 index d55dfe4..0000000 --- a/.github/workflows/package.yaml +++ /dev/null @@ -1,40 +0,0 @@ -name: package -on: - release: - types: [published] -jobs: - xgo: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Build - uses: crazy-max/ghaction-xgo@v3 - with: - go_version: 1.22 - dest: build - prefix: chroma - targets: windows/amd64,linux/amd64,linux/arm64,darwin/arm64 - ldflags: -s -w - release_assets: - needs: xgo - runs-on: ${{ matrix.config.os }} - strategy: - matrix: - config: - - os: ubuntu-latest - - os: macos-latest - - os: windows-latest - steps: - - name: Checkout code - uses: actions/checkout@v1 - # Build steps for your application - - name: Upload release assets - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ needs.create_release.outputs.upload_url }} - asset_name: program-name-${{ matrix.config.os }} - asset_path: ./path/to/your/file - asset_content_type: application/octet-stream diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..2d90f28 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,63 @@ +name: package +on: + release: + types: [published] +jobs: + release: + runs-on: ubuntu-latest + permissions: + contents: write + id-token: write + packages: write + env: + DOCKER_CLI_EXPERIMENTAL: enabled + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-go@v5 + with: + go-version: 1.20 + cache: true + check-latest: true + - uses: sigstore/cosign-installer@v3.4.0 + - uses: cachix/install-nix-action@v25 + with: + github_access_token: ${{ secrets.GITHUB_TOKEN }} + - uses: anchore/sbom-action/download-syft@v0.15.8 + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v3 + name: ghcr.io login + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: docker/login-action@v3 + name: docker.io login + with: + username: ${{ secrets.docker_username }} + password: ${{ secrets.docker_token }} + - run: | + echo "$NFPM_GPG_KEY" > ${{ runner.temp }}/gpg.key + env: + NFPM_GPG_KEY: ${{ secrets.AMIKOS_OSS_GPG_SECRET_KEY }} + - uses: goreleaser/goreleaser-action@v5 + with: + version: latest + distribution: goreleaser + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.gh_pat }} + GPG_KEY_PATH: ${{ runner.temp }}/gpg.key + NFPM_DEFAULT_PASSPHRASE: ${{ secrets.AMIKOS_OSS_GPG_SECRET_KEY_PASSWORD }} + - uses: actions/upload-artifact@v4 + if: ${{ inputs.upload_artifact == true && always() }} + with: + retention-days: 30 + name: dist + path: | + dist + + From 71e10ef884ba6c49520d6911685738136ad35473 Mon Sep 17 00:00:00 2001 From: Trayan Azarov Date: Sun, 3 Mar 2024 18:02:29 +0200 Subject: [PATCH 3/4] fix: Updating upload artifact is now mandatory --- .github/workflows/release.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 2d90f28..133d5b9 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -53,7 +53,6 @@ jobs: GPG_KEY_PATH: ${{ runner.temp }}/gpg.key NFPM_DEFAULT_PASSPHRASE: ${{ secrets.AMIKOS_OSS_GPG_SECRET_KEY_PASSWORD }} - uses: actions/upload-artifact@v4 - if: ${{ inputs.upload_artifact == true && always() }} with: retention-days: 30 name: dist From 98f3a358f671fd9090836f4d87eddb88dbafdedf Mon Sep 17 00:00:00 2001 From: Trayan Azarov Date: Sun, 3 Mar 2024 22:46:42 +0200 Subject: [PATCH 4/4] chore: Lint fix --- cmd/root.go | 10 ++++------ cmd/server/server.go | 31 ++++++++++--------------------- cmd/server/server_test.go | 3 ++- types/server.go | 2 +- 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 25cf5b3..63764d7 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -3,12 +3,12 @@ package cmd import ( "errors" "fmt" - "github.com/mitchellh/go-homedir" - "github.com/spf13/viper" "log" "os" + "github.com/mitchellh/go-homedir" "github.com/spf13/cobra" + "github.com/spf13/viper" ) // rootCmd represents the base command when called without any subcommands @@ -37,7 +37,6 @@ func initConfig() { if err != nil { fmt.Println(err) os.Exit(1) - } viper.SetConfigName("config") viper.SetConfigType("yaml") @@ -45,7 +44,7 @@ func initConfig() { if err := viper.ReadInConfig(); err != nil { var configFileNotFoundError viper.ConfigFileNotFoundError if errors.As(err, &configFileNotFoundError) { - //create config file + // create config file err := os.MkdirAll(home+"/.chroma", 0700) if err != nil { // Unable to create directory @@ -53,7 +52,7 @@ func initConfig() { } _, err = os.Create(home + "/.chroma" + "/config.yaml") if err != nil { - //Unable to create file + // Unable to create file log.Fatal(err) } err = viper.WriteConfig() @@ -62,6 +61,5 @@ func initConfig() { os.Exit(1) } } - } } diff --git a/cmd/server/server.go b/cmd/server/server.go index 951851a..ac4ff5d 100644 --- a/cmd/server/server.go +++ b/cmd/server/server.go @@ -2,12 +2,13 @@ package server import ( "fmt" + "os" + "strconv" + "github.com/charmbracelet/huh" "github.com/go-playground/validator/v10" "github.com/spf13/cobra" "github.com/spf13/viper" - "os" - "strconv" ) const ( @@ -38,7 +39,7 @@ func getPort(changed bool) (int, error) { port = DefaultPort } var actualPort int - //if port == "" { + // if port == "" { // iPort := huh.NewInput().Value(&port).Title("Port").Placeholder(DefaultPort) // err := iPort.Run() // if err != nil { @@ -68,13 +69,13 @@ func getHost(changed bool) (string, error) { return "", fmt.Errorf("invalid host: %v", err) } - //if host == "" { + // if host == "" { // iHost := huh.NewInput().Value(&host).Title("Host").Placeholder(DefaultHost) // err := iHost.Run() // if err != nil { // return "", fmt.Errorf("unable to get host: %v", err) // } - //if host == "" { + // if host == "" { // host = DefaultHost // } //} @@ -82,18 +83,6 @@ func getHost(changed bool) (string, error) { return host, nil } -// getSecure is used for Interactive shell mode -func getSecure(changed bool) (bool, error) { - secure := Secure - - //err := huh.NewConfirm().Title("Use secure connection (https)?").Affirmative("Yes!").Negative("No.").Value - //if err != nil { - // return false, fmt.Errorf("unable to get confirmation: %v", err) - //} - return secure, nil -} - -// chroma server add -h localhost -p 8080 var Host string var Port string var Overwrite bool @@ -104,7 +93,7 @@ var AddCommand = &cobra.Command{ Short: "Add new or Update existing Chroma server", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - //get the first argument tht is our alias + // get the first argument tht is our alias alias := args[0] hostChanged := cmd.Flags().Changed("host") host, hostErr := getHost(hostChanged) @@ -128,8 +117,8 @@ var AddCommand = &cobra.Command{ if !portChanged { fmt.Printf("Using default port: %v\n", DefaultPort) } - //confirm := false - //if Host != "" || Port != "" { + // confirm := false + // if Host != "" || Port != "" { // confirm = true //} else { // err := huh.NewConfirm(). @@ -230,7 +219,7 @@ func init() { AddCommand.Flags().StringVarP(&Port, "port", "p", "", "Chroma server port") AddCommand.Flags().BoolVarP(&Overwrite, "overwrite", "o", false, "Overwrite existing server with the same alias") AddCommand.Flags().BoolVarP(&Secure, "secure", "s", false, "Use secure connection (https).") - //AddCommand.MarkFlagsRequiredTogether("host", "port") + // AddCommand.MarkFlagsRequiredTogether("host", "port") AddCommand.ValidArgs = []string{"alias"} RmCommand.ValidArgs = []string{"alias"} RmCommand.Flags().BoolVarP(&ForceDelete, "force", "f", false, "Force remove server without confirmation") diff --git a/cmd/server/server_test.go b/cmd/server/server_test.go index 75e51bf..4aecffa 100644 --- a/cmd/server/server_test.go +++ b/cmd/server/server_test.go @@ -1,8 +1,9 @@ package server import ( - "github.com/stretchr/testify/require" "testing" + + "github.com/stretchr/testify/require" ) func TestValidateHost(t *testing.T) { diff --git a/types/server.go b/types/server.go index e1b580b..c8fb0bb 100644 --- a/types/server.go +++ b/types/server.go @@ -1,6 +1,6 @@ package types -//connect to local Chroma +// connect to local Chroma type ServerConfig struct { Host string