1
0
mirror of https://github.com/go-task/task.git synced 2024-12-04 10:24:45 +02:00

feat: release tool improvements (#1096)

This commit is contained in:
Pete Davison 2023-03-31 01:10:11 +01:00 committed by GitHub
parent 4d4acc72f0
commit 22983bcdd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 13 deletions

View File

@ -1,5 +1,9 @@
# Changelog
## Unreleased
- More improvements to the release tool (#1096 by @pd93)
## v3.23.0 - 2023-03-26
Task now has an [official extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=task.vscode-task) contributed by @pd93! :tada: The extension is maintained in a [new repository](https://github.com/go-task/vscode-task) under the `go-task` organization. We're looking to gather feedback from the community so please give it a go and let us know what you think via a [discussion](https://github.com/go-task/vscode-task/discussions), [issue](https://github.com/go-task/vscode-task/issues) or on our [Discord](https://discord.gg/6TY36E39UK)!

View File

@ -107,14 +107,6 @@ tasks:
cmds:
- go run ./cmd/release {{.CLI_ARGS}}
npm:bump:
desc: Bump version in package.json. Requires `jq`.
vars:
VERSION: '{{coalesce .CLI_ARGS .VERSION}}'
cmds:
- cat package.json | jq '.version = "{{.VERSION}}"' > temp.json; mv temp.json package.json
- cat package-lock.json | jq '.version = "{{.VERSION}}" | .packages."".version = "{{.VERSION}}"' > temp.json; mv temp.json package-lock.json
npm:publish:
desc: Publish release to npm
cmds:

View File

@ -26,6 +26,7 @@ var (
changelogReleaseRegex = regexp.MustCompile(`## Unreleased`)
changelogUserRegex = regexp.MustCompile(`@(\w+)`)
changelogIssueRegex = regexp.MustCompile(`#(\d+)`)
versionRegex = regexp.MustCompile(`(?m)^ "version": "\d+\.\d+\.\d+",$`)
)
func main() {
@ -55,6 +56,14 @@ func release() error {
return err
}
if err := setJSONVersion("package.json", version); err != nil {
return err
}
if err := setJSONVersion("package-lock.json", version); err != nil {
return err
}
return nil
}
@ -86,7 +95,7 @@ func changelog(version *semver.Version) error {
// Open changelog source file
b, err := os.ReadFile(changelogSource)
if err != nil {
panic(err)
return err
}
changelog := string(b)
date := time.Now().Format("2006-01-02")
@ -96,7 +105,7 @@ func changelog(version *semver.Version) error {
// Write the changelog to the source file
if err := os.WriteFile(changelogSource, []byte(changelog), 0644); err != nil {
panic(err)
return err
}
// Add the frontmatter to the changelog
@ -107,9 +116,19 @@ func changelog(version *semver.Version) error {
changelog = changelogIssueRegex.ReplaceAllString(changelog, "[#$1](https://github.com/go-task/task/issues/$1)")
// Write the changelog to the target file
if err := os.WriteFile(changelogTarget, []byte(changelog), 0644); err != nil {
panic(err)
return os.WriteFile(changelogTarget, []byte(changelog), 0644)
}
func setJSONVersion(fileName string, version *semver.Version) error {
// Read the JSON file
b, err := os.ReadFile(fileName)
if err != nil {
return err
}
return nil
// Replace the version
new := versionRegex.ReplaceAllString(string(b), fmt.Sprintf(` "version": "%s",`, version.String()))
// Write the JSON file
return os.WriteFile(fileName, []byte(new), 0644)
}