diff --git a/.mega-linter.yml b/.mega-linter.yml index 123f16d0ed0..c17e218646d 100644 --- a/.mega-linter.yml +++ b/.mega-linter.yml @@ -14,7 +14,7 @@ DISABLE_LINTERS: - MARKDOWN_MARKDOWN_LINK_CHECK - REPOSITORY_CHECKOV - REPOSITORY_TRIVY -FILTER_REGEX_EXCLUDE: (.*testdata/*|install.sh|pkg/container/docker_cli.go|pkg/container/DOCKER_LICENSE) +FILTER_REGEX_EXCLUDE: (.*testdata/*|install.sh|pkg/container/docker_cli.go|pkg/container/DOCKER_LICENSE|VERSION) MARKDOWN_MARKDOWNLINT_CONFIG_FILE: .markdownlint.yml PARALLEL: false PRINT_ALPACA: false diff --git a/Makefile b/Makefile index bdf93850d7a..fd1a8a69eb3 100644 --- a/Makefile +++ b/Makefile @@ -96,6 +96,9 @@ ifneq ($(shell git status -s),) @echo "Unable to promote a dirty workspace" @exit 1 endif + echo -n $(NEW_VERSION) > VERSION + git add VERSION + git commit -m "chore: bump VERSION" git tag -a -m "releasing v$(NEW_VERSION)" v$(NEW_VERSION) git push origin v$(NEW_VERSION) @@ -105,3 +108,5 @@ snapshot: --rm-dist \ --single-target \ --snapshot + +.PHONY: clean all diff --git a/VERSION b/VERSION new file mode 100644 index 00000000000..26eca0cc854 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.2.35 \ No newline at end of file diff --git a/cmd/notices.go b/cmd/notices.go new file mode 100644 index 00000000000..4ad32d7345a --- /dev/null +++ b/cmd/notices.go @@ -0,0 +1,90 @@ +package cmd + +import ( + "encoding/json" + "fmt" + "net/http" + "net/url" + "os" + "runtime" + "time" + + log "github.com/sirupsen/logrus" +) + +type Notice struct { + Level string `json:"level"` + Message string `json:"message"` +} + +func displayNotices(input *Input) { + select { + case notices := <-noticesLoaded: + if len(notices) > 0 { + noticeLogger := log.New() + if input.jsonLogger { + noticeLogger.SetFormatter(&log.JSONFormatter{}) + } else { + noticeLogger.SetFormatter(&log.TextFormatter{ + DisableQuote: true, + DisableTimestamp: true, + PadLevelText: true, + }) + } + + fmt.Printf("\n") + for _, notice := range notices { + level, err := log.ParseLevel(notice.Level) + if err != nil { + level = log.InfoLevel + } + noticeLogger.Log(level, notice.Message) + } + } + case <-time.After(time.Second * 1): + log.Debugf("Timeout waiting for notices") + } +} + +var noticesLoaded = make(chan []Notice) + +func loadVersionNotices(version string) { + go func() { + noticesLoaded <- getVersionNotices(version) + }() +} + +const NoticeURL = "https://api.nektosact.com/notices" + +func getVersionNotices(version string) []Notice { + if os.Getenv("ACT_DISABLE_VERSION_CHECK") == "1" { + return nil + } + + noticeURL, err := url.Parse(NoticeURL) + if err != nil { + log.Error(err) + return nil + } + query := noticeURL.Query() + query.Add("os", runtime.GOOS) + query.Add("arch", runtime.GOARCH) + query.Add("version", version) + + noticeURL.RawQuery = query.Encode() + + resp, err := http.Get(noticeURL.String()) + if err != nil { + log.Debug(err) + return nil + } + + defer resp.Body.Close() + notices := []Notice{} + if err := json.NewDecoder(resp.Body).Decode(¬ices); err != nil { + log.Debug(err) + return nil + } + + return notices +} diff --git a/cmd/root.go b/cmd/root.go index 0aa56e782b8..1d153abb318 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -30,13 +30,14 @@ import ( func Execute(ctx context.Context, version string) { input := new(Input) var rootCmd = &cobra.Command{ - Use: "act [event name to run] [flags]\n\nIf no event name passed, will default to \"on: push\"\nIf actions handles only one event it will be used as default instead of \"on: push\"", - Short: "Run GitHub actions locally by specifying the event name (e.g. `push`) or an action name directly.", - Args: cobra.MaximumNArgs(1), - RunE: newRunCommand(ctx, input), - PersistentPreRun: setupLogging, - Version: version, - SilenceUsage: true, + Use: "act [event name to run] [flags]\n\nIf no event name passed, will default to \"on: push\"\nIf actions handles only one event it will be used as default instead of \"on: push\"", + Short: "Run GitHub actions locally by specifying the event name (e.g. `push`) or an action name directly.", + Args: cobra.MaximumNArgs(1), + RunE: newRunCommand(ctx, input), + PersistentPreRun: setup(input), + PersistentPostRun: cleanup(input), + Version: version, + SilenceUsage: true, } rootCmd.Flags().BoolP("watch", "w", false, "watch the contents of the local repo and run when files change") rootCmd.Flags().BoolP("list", "l", false, "list workflows") @@ -244,10 +245,19 @@ func readArgsFile(file string, split bool) []string { return args } -func setupLogging(cmd *cobra.Command, _ []string) { - verbose, _ := cmd.Flags().GetBool("verbose") - if verbose { - log.SetLevel(log.DebugLevel) +func setup(inputs *Input) func(*cobra.Command, []string) { + return func(cmd *cobra.Command, _ []string) { + verbose, _ := cmd.Flags().GetBool("verbose") + if verbose { + log.SetLevel(log.DebugLevel) + } + loadVersionNotices(cmd.Version) + } +} + +func cleanup(inputs *Input) func(*cobra.Command, []string) { + return func(cmd *cobra.Command, _ []string) { + displayNotices(inputs) } } diff --git a/main.go b/main.go index 41cf7c47580..37b0fece768 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "context" + _ "embed" "os" "os/signal" "syscall" @@ -9,7 +10,8 @@ import ( "github.com/nektos/act/cmd" ) -var version = "v0.2.27-dev" // Manually bump after tagging next release +//go:embed VERSION +var version string func main() { ctx := context.Background()