This repository has been archived by the owner on Dec 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: all release and publish commands
- Loading branch information
Showing
12 changed files
with
236 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,7 @@ jobs: | |
uses: dagger/[email protected] | ||
with: | ||
verb: run | ||
args: --silent go run main.go publish artifact | ||
args: --silent go run main.go publish all | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
Copyright © 2024 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
// "github.com/flabatut/bitwarden-cli/pkg/publish/image" | ||
// "github.com/flabatut/bitwarden-cli/pkg/publish/artifact" | ||
"github.com/spf13/cobra" | ||
// "github.com/spf13/viper" | ||
) | ||
|
||
// imageCmd represents the image command | ||
var publishAllCmd = &cobra.Command{ | ||
Use: "all", | ||
Short: "A brief description of your command", | ||
Long: `A longer description that spans multiple lines and likely contains examples | ||
and usage of using your command. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
fmt.Println("publish all called") | ||
if err := runPublishAllCmd(cmd); err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
publishCmd.AddCommand(publishAllCmd) | ||
err := markReleaseVersionRequired(publishAllCmd) | ||
cobra.CheckErr(err) | ||
} | ||
|
||
func runPublishAllCmd(cmd *cobra.Command) error { | ||
if err := runPublishArtifactCmd(cmd); err != nil { | ||
return err | ||
} | ||
if err := runPublishImageCmd(cmd); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
Copyright © 2024 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"dagger.io/dagger" | ||
"github.com/flabatut/bitwarden-cli/pkg/release" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// releaseCmd represents the release command | ||
var releaseCmd = &cobra.Command{ | ||
Use: "release", | ||
Short: "A brief description of your command", | ||
Long: `A longer description that spans multiple lines and likely contains examples | ||
and usage of using your command. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
fmt.Println("publish artifact called") | ||
if _, err := runReleaseCmd(cmd); err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(releaseCmd) | ||
err := markReleaseVersionRequired(releaseCmd) | ||
cobra.CheckErr(err) | ||
} | ||
|
||
func runReleaseCmd(cmd *cobra.Command) (*dagger.Container, error) { | ||
fmt.Println("release called") | ||
password, err := getRegistryPassword() | ||
if err != nil { | ||
return nil, err | ||
} | ||
w := &release.Workflow{ | ||
Client: daggerClient, | ||
ProjectNamespace: viper.GetString("projectNamespace"), | ||
RegistryPassword: password, | ||
} | ||
if !viper.IsSet("releaseVersion") { | ||
return nil, fmt.Errorf("required flag(s) releaseVersion not set") | ||
} | ||
releaser, err := w.Release(cmd.Context(), viper.GetString("releaseVersion")) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return releaser, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package release | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
"dagger.io/dagger" | ||
) | ||
|
||
type Workflow struct { | ||
Client *dagger.Client | ||
ProjectNamespace string | ||
RegistryPassword *dagger.Secret | ||
} | ||
|
||
func (w *Workflow) Release(ctx context.Context, releaseVersion string) (*dagger.Container, error) { | ||
fmt.Println("Releasing with Dagger") | ||
|
||
var ghRepo = fmt.Sprintf("github.com/%s", w.ProjectNamespace) | ||
|
||
releaser := w.Client.Container(). | ||
From("alpine:latest"). | ||
// WithEnvVariable("GH_DEBUG", "api"). | ||
WithEnvVariable("GH_REPO", ghRepo). | ||
WithSecretVariable("GH_TOKEN", w.RegistryPassword). | ||
WithExec([]string{"apk", "add", "github-cli"}) | ||
|
||
// https://docs.dagger.io/cookbook/#invalidate-cache | ||
_, err := releaser.WithEnvVariable("CACHEBUSTER", time.Now().String()). | ||
WithExec([]string{ | ||
"gh", "release", "view", releaseVersion, | ||
}).Stdout(ctx) | ||
if err != nil { | ||
if strings.HasSuffix(err.Error(), "release not found") { | ||
_, err = releaser.WithEnvVariable("CACHEBUSTER", time.Now().String()). | ||
WithExec([]string{ | ||
"gh", "release", "create", releaseVersion, "-t", releaseVersion, "--generate-notes", | ||
}).Stdout(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} else { | ||
return nil, err | ||
} | ||
} | ||
return releaser, nil | ||
} |