diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 87b0738f..a48854d5 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -35,6 +35,14 @@ jobs: if: github.event_name != 'workflow_dispatch' run: |- go run -v ./cmd/internal/read_tag --nightly + - name: Update version + if: github.event_name == 'workflow_dispatch' + run: |- + go run -v ./cmd/internal/read_tag --nightly + - name: Update nightly version + if: github.event_name != 'workflow_dispatch' + run: |- + go run -v ./cmd/internal/read_tag --nightly - name: Set outputs id: outputs run: |- diff --git a/cmd/internal/read_tag/main.go b/cmd/internal/read_tag/main.go index 2cebaf70..e082e130 100644 --- a/cmd/internal/read_tag/main.go +++ b/cmd/internal/read_tag/main.go @@ -2,43 +2,55 @@ package main import ( "flag" + "github.com/sagernet/sing-box/common/badversion" "os" "github.com/sagernet/sing-box/cmd/internal/build_shared" "github.com/sagernet/sing-box/log" ) -var nightly bool +var ( + flagRunInCI bool + flagRunNightly bool +) func init() { - flag.BoolVar(&nightly, "nightly", false, "Print nightly tag") + flag.BoolVar(&flagRunInCI, "ci", false, "Run in CI") + flag.BoolVar(&flagRunNightly, "nightly", false, "Run nightly") } func main() { flag.Parse() - if nightly { - version, err := build_shared.ReadTagVersionRev() + var ( + versionStr string + err error + ) + if flagRunNightly { + var version badversion.Version + version, err = build_shared.ReadTagVersionRev() + if err == nil { + if version.PreReleaseIdentifier == "" { + version.Patch++ + } + versionStr = version.String() + } + } else { + versionStr, err = build_shared.ReadTag() + } + if flagRunInCI { if err != nil { log.Fatal(err) } - var versionStr string - if version.PreReleaseIdentifier != "" { - versionStr = version.VersionString() + "-nightly" - } else { - version.Patch++ - versionStr = version.VersionString() + "-nightly" - } err = setGitHubEnv("version", versionStr) if err != nil { log.Fatal(err) } } else { - tag, err := build_shared.ReadTag() if err != nil { log.Error(err) os.Stdout.WriteString("unknown\n") } else { - os.Stdout.WriteString(tag + "\n") + os.Stdout.WriteString(versionStr + "\n") } } }