|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "os" |
| 5 | + "strconv" |
| 6 | + "strings" |
| 7 | + "time" |
| 8 | + |
| 9 | + "github.com/wailsapp/wails/v3/internal/s" |
| 10 | +) |
| 11 | + |
| 12 | +const versionFile = "../../internal/version/version.txt" |
| 13 | + |
| 14 | +func checkError(err error) { |
| 15 | + if err != nil { |
| 16 | + println(err.Error()) |
| 17 | + os.Exit(1) |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +// TODO:This can be replaced with "https://github.com/coreos/go-semver/blob/main/semver/semver.go" |
| 22 | +func updateVersion() string { |
| 23 | + currentVersionData, err := os.ReadFile(versionFile) |
| 24 | + checkError(err) |
| 25 | + currentVersion := string(currentVersionData) |
| 26 | + vsplit := strings.Split(currentVersion, ".") |
| 27 | + minorVersion, err := strconv.Atoi(vsplit[len(vsplit)-1]) |
| 28 | + checkError(err) |
| 29 | + minorVersion++ |
| 30 | + vsplit[len(vsplit)-1] = strconv.Itoa(minorVersion) |
| 31 | + newVersion := strings.Join(vsplit, ".") |
| 32 | + err = os.WriteFile(versionFile, []byte(newVersion), 0o755) |
| 33 | + checkError(err) |
| 34 | + return newVersion |
| 35 | +} |
| 36 | + |
| 37 | +//func runCommand(name string, arg ...string) { |
| 38 | +// cmd := exec.Command(name, arg...) |
| 39 | +// cmd.Stdout = os.Stdout |
| 40 | +// cmd.Stderr = os.Stderr |
| 41 | +// err := cmd.Run() |
| 42 | +// checkError(err) |
| 43 | +//} |
| 44 | + |
| 45 | +//func IsPointRelease(currentVersion string, newVersion string) bool { |
| 46 | +// // The first n-1 parts of the version should be the same |
| 47 | +// if currentVersion[:len(currentVersion)-2] != newVersion[:len(newVersion)-2] { |
| 48 | +// return false |
| 49 | +// } |
| 50 | +// // split on the last dot in the string |
| 51 | +// currentVersionSplit := strings.Split(currentVersion, ".") |
| 52 | +// newVersionSplit := strings.Split(newVersion, ".") |
| 53 | +// // if the last part of the version is the same, it's a point release |
| 54 | +// currentMinor := lo.Must(strconv.Atoi(currentVersionSplit[len(currentVersionSplit)-1])) |
| 55 | +// newMinor := lo.Must(strconv.Atoi(newVersionSplit[len(newVersionSplit)-1])) |
| 56 | +// return newMinor == currentMinor+1 |
| 57 | +//} |
| 58 | + |
| 59 | +func main() { |
| 60 | + var newVersion string |
| 61 | + if len(os.Args) > 1 { |
| 62 | + newVersion = os.Args[1] |
| 63 | + //currentVersion, err := os.ReadFile(versionFile) |
| 64 | + //checkError(err) |
| 65 | + err := os.WriteFile(versionFile, []byte(newVersion), 0o755) |
| 66 | + checkError(err) |
| 67 | + //isPointRelease = IsPointRelease(string(currentVersion), newVersion) |
| 68 | + } else { |
| 69 | + newVersion = updateVersion() |
| 70 | + } |
| 71 | + |
| 72 | + // Update ChangeLog |
| 73 | + s.CD("../../../mkdocs-website") |
| 74 | + |
| 75 | + // Read in `src/pages/changelog.mdx` |
| 76 | + changelogData, err := os.ReadFile("docs/en/changelog.md") |
| 77 | + checkError(err) |
| 78 | + changelog := string(changelogData) |
| 79 | + // Split on the line that has `## [Unreleased]` |
| 80 | + changelogSplit := strings.Split(changelog, "## [Unreleased]") |
| 81 | + // Get today's date in YYYY-MM-DD format |
| 82 | + today := time.Now().Format("2006-01-02") |
| 83 | + // Add the new version to the top of the changelog |
| 84 | + newChangelog := changelogSplit[0] + "## [Unreleased]\n\n## " + newVersion + " - " + today + changelogSplit[1] |
| 85 | + // Write the changelog back |
| 86 | + err = os.WriteFile("docs/en/changelog.md", []byte(newChangelog), 0o755) |
| 87 | + checkError(err) |
| 88 | + |
| 89 | + // TODO: Documentation Versioning and Translations |
| 90 | + |
| 91 | + //if !isPointRelease { |
| 92 | + // runCommand("npx", "-y", "pnpm", "install") |
| 93 | + // |
| 94 | + // s.ECHO("Generating new Docs for version: " + newVersion) |
| 95 | + // |
| 96 | + // runCommand("npx", "pnpm", "run", "docusaurus", "docs:version", newVersion) |
| 97 | + // |
| 98 | + // runCommand("npx", "pnpm", "run", "write-translations") |
| 99 | + // |
| 100 | + // // Load the version list/* |
| 101 | + // versionsData, err := os.ReadFile("versions.json") |
| 102 | + // checkError(err) |
| 103 | + // var versions []string |
| 104 | + // err = json.Unmarshal(versionsData, &versions) |
| 105 | + // checkError(err) |
| 106 | + // oldestVersion := versions[len(versions)-1] |
| 107 | + // s.ECHO(oldestVersion) |
| 108 | + // versions = versions[0 : len(versions)-1] |
| 109 | + // newVersions, err := json.Marshal(&versions) |
| 110 | + // checkError(err) |
| 111 | + // err = os.WriteFile("versions.json", newVersions, 0o755) |
| 112 | + // checkError(err) |
| 113 | + // |
| 114 | + // s.ECHO("Removing old version: " + oldestVersion) |
| 115 | + // s.CD("versioned_docs") |
| 116 | + // s.RMDIR("version-" + oldestVersion) |
| 117 | + // s.CD("../versioned_sidebars") |
| 118 | + // s.RM("version-" + oldestVersion + "-sidebars.json") |
| 119 | + // s.CD("..") |
| 120 | + // |
| 121 | + // runCommand("npx", "pnpm", "run", "build") |
| 122 | + //} |
| 123 | +} |
0 commit comments