From 1ede0bef10ac6dd98179afbdc53ef05dba3381e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20T=C3=B6lle?= Date: Sun, 25 Aug 2024 13:47:55 +0200 Subject: [PATCH 1/3] feat(cli): add --version flag (#29) --- cmd/rp/cmd/root.go | 51 +++++++++++++++++++++++++--------------------- cmd/rp/cmd/run.go | 3 --- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/cmd/rp/cmd/root.go b/cmd/rp/cmd/root.go index c43b75a..be92187 100644 --- a/cmd/rp/cmd/root.go +++ b/cmd/rp/cmd/root.go @@ -1,31 +1,45 @@ package cmd import ( + "fmt" "log/slog" "os" + "runtime/debug" "github.com/spf13/cobra" ) var logger *slog.Logger -// rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ - Use: "releaser-pleaser", - Short: "A brief description of your application", - Long: `A longer description that spans multiple lines and likely contains -examples and usage of using your application. 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.`, - // Uncomment the following line if your bare application - // has an action associated with it: - // Run: func(cmd *cobra.Command, args []string) { }, + Use: "releaser-pleaser", + Short: "", + Long: ``, + Version: version(), +} + +func version() string { + vcsrevision := "unknown" + vcsdirty := "" + + buildInfo, ok := debug.ReadBuildInfo() + if ok { + fmt.Println(buildInfo.String()) + for _, setting := range buildInfo.Settings { + switch setting.Key { + case "vcs.revision": + vcsrevision = setting.Value + case "vcs.modified": + if setting.Value == "true" { + vcsdirty = " (dirty)" + } + } + } + } + + return vcsrevision + vcsdirty } -// Execute adds all child commands to the root command and sets flags appropriately. -// This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { err := rootCmd.Execute() if err != nil { @@ -38,13 +52,4 @@ func init() { Level: slog.LevelDebug, })) - // Here you will define your flags and configuration settings. - // Cobra supports persistent flags, which, if defined here, - // will be global for your application. - - // rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.releaser-pleaser.yaml)") - - // Cobra also supports local flags, which will only run - // when this action is called directly. - rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } diff --git a/cmd/rp/cmd/run.go b/cmd/rp/cmd/run.go index 7661af5..7d5862b 100644 --- a/cmd/rp/cmd/run.go +++ b/cmd/rp/cmd/run.go @@ -8,7 +8,6 @@ import ( rp "github.com/apricote/releaser-pleaser" ) -// runCmd represents the run command var runCmd = &cobra.Command{ Use: "run", RunE: run, @@ -25,8 +24,6 @@ var ( func init() { rootCmd.AddCommand(runCmd) - // Here you will define your flags and configuration settings. - runCmd.PersistentFlags().StringVar(&flagForge, "forge", "", "") runCmd.PersistentFlags().StringVar(&flagBranch, "branch", "main", "") runCmd.PersistentFlags().StringVar(&flagOwner, "owner", "", "") From 2cd73a8679b1a39730746c4d8690d00889311236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20T=C3=B6lle?= Date: Sun, 25 Aug 2024 13:54:21 +0200 Subject: [PATCH 2/3] ci: use current code for releaser-pleaser action (#28) The previous job always used the last release version of releaser-pleaser. This caused two issues: - if new flags were added to `action.yml` since the last release, the program errored because the flags are unknown. - right after merging a release pr, the image reference was already updated, but no new container image was built yet. This fixes both issues, by using a locally built version of releaser-pleaser, which is always up-to-date and available. --- .github/workflows/releaser-pleaser.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/releaser-pleaser.yaml b/.github/workflows/releaser-pleaser.yaml index 7fb4b81..0406d41 100644 --- a/.github/workflows/releaser-pleaser.yaml +++ b/.github/workflows/releaser-pleaser.yaml @@ -3,6 +3,7 @@ name: releaser-pleaser on: push: branches: [main] + # TODO: use pull_request_target to avoid tainting the actual release PR with code from open feature pull requests pull_request: types: - edited @@ -18,6 +19,21 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + # Build container image from current commit and replace image ref in `action.yml` + # Without this, any new flags in `action.yml` would break the job in this repository until the new + # version is released. But a new version can only be released if this job works. + - uses: ko-build/setup-ko@v0.7 + - run: ko build --bare --local --tags ci github.com/apricote/releaser-pleaser/cmd/rp + + - run: mkdir -p .github/actions/releaser-pleaser + - run: "sed -i 's|image: .*$|image: ghcr.io/apricote/releaser-pleaser:ci|g' action.yml" + + # Dogfood the action to make sure it works for users. - name: releaser-pleaser uses: ./ with: From 1767fbba903a5e7e5c007111902a780b5df49930 Mon Sep 17 00:00:00 2001 From: releaser-pleaser <> Date: Sun, 25 Aug 2024 11:55:30 +0000 Subject: [PATCH 3/3] chore(main): release v0.2.0 --- CHANGELOG.md | 12 ++++++++++++ action.yml | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3e7084..e26396b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## [v0.2.0](https://github.com/apricote/releaser-pleaser/releases/tag/v0.2.0) +### Features + +- update version references in any files (#14) +- **cli**: add --version flag (#29) + +### Bug Fixes + +- **ci**: building release image fails (#21) +- **ci**: ko pipeline permissions (#23) +- **action**: invalid quoting for extra-files arg (#25) + ## [v0.2.0-beta.2](https://github.com/apricote/releaser-pleaser/releases/tag/v0.2.0-beta.2) ### Features diff --git a/action.yml b/action.yml index 2033394..cbba8d5 100644 --- a/action.yml +++ b/action.yml @@ -19,7 +19,7 @@ inputs: outputs: {} runs: using: 'docker' - image: ghcr.io/apricote/releaser-pleaser:v0.2.0-beta.2 # x-releaser-pleaser-version + image: ghcr.io/apricote/releaser-pleaser:v0.2.0 # x-releaser-pleaser-version args: - run - --forge=github