release-tag 0.0.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ # If you prefer the allow list template instead of the deny list, see community template:
2
+ # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3
+ #
4
+ # Binaries for programs and plugins
5
+ *.exe
6
+ *.exe~
7
+ *.dll
8
+ *.so
9
+ *.dylib
10
+
11
+ # Test binary, built with `go test -c`
12
+ *.test
13
+
14
+ # Output of the go coverage tool, specifically when used with LiteIDE
15
+ *.out
16
+
17
+ # Dependency directories (remove the comment below to include it)
18
+ # vendor/
19
+
20
+ # Go workspace file
21
+ go.work
22
+ go.work.sum
23
+
24
+ # env file
25
+ .env
26
+
27
+ # python packaging
28
+ dist/
29
+ *.egg-info/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Jamison Lahman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,83 @@
1
+ Metadata-Version: 2.4
2
+ Name: release-tag
3
+ Version: 0.0.8
4
+ Summary: Automatically create semantic version git tags
5
+ Project-URL: Repository, https://github.com/jmelahman/tag
6
+ Author-email: Jamison Lahman <jamison@lahman.dev>
7
+ License: MIT License
8
+
9
+ Copyright (c) 2024 Jamison Lahman
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+ License-File: LICENSE
29
+ Keywords: git,git tags,release,releasing,semver,tagging
30
+ Classifier: License :: OSI Approved :: MIT License
31
+ Classifier: Operating System :: OS Independent
32
+ Classifier: Programming Language :: Go
33
+ Requires-Python: >=3.6
34
+ Description-Content-Type: text/markdown
35
+
36
+ # Tag Release
37
+
38
+ [![Test status](https://github.com/jmelahman/tag/actions/workflows/test.yml/badge.svg)](https://github.com/jmelahman/tag/actions)
39
+ [![Deploy Status](https://github.com/jmelahman/tag/actions/workflows/release.yml/badge.svg)](https://github.com/jmelahman/tag/actions)
40
+ [![Go Reference](https://pkg.go.dev/badge/github.com/jmelahman/tag.svg)](https://pkg.go.dev/github.com/jmelahman/tag)
41
+ [![PyPI](https://img.shields.io/pypi/v/release-tag.svg)]()
42
+ [![Go Report Card](https://goreportcard.com/badge/github.com/jmelahman/tag)](https://goreportcard.com/report/github.com/jmelahman/tag)
43
+
44
+ Automatically create [semantic version](https://semver.org/) git tags.
45
+
46
+ ```shell
47
+ $ tag --push
48
+ Next version: v1.0.1
49
+ Tag v1.0.1 created and pushed to remote.
50
+ ```
51
+
52
+ ### Autocomplete
53
+
54
+ `tag` provides autocomplete for `bash`, `fish`, `powershell` and `zsh` shells.
55
+ For example, to enable autocomplete for the `bash` shell,
56
+
57
+ ```shell
58
+ tag completion bash | sudo tee /etc/bash_completion.d/tag > /dev/null
59
+ ```
60
+
61
+ _Note: bash completion requires the [bash-completion](https://github.com/scop/bash-completion/) package be installed._
62
+
63
+ For more information, see `tag completion <shell> --help` for your respective `<shell>`.
64
+
65
+ ## Install
66
+
67
+ **pip:**
68
+
69
+ `tag` is available as a [pypi package](https://pypi.org/project/release-tag/).
70
+
71
+ ```shell
72
+ pip install release-tag
73
+ ```
74
+
75
+ **go:**
76
+
77
+ ```shell
78
+ go install github.com/jmelahman/tag@latest
79
+ ```
80
+
81
+ **github:**
82
+
83
+ Prebuilt packages are available from [Github Releases](https://github.com/jmelahman/tag/releases).
@@ -0,0 +1,48 @@
1
+ # Tag Release
2
+
3
+ [![Test status](https://github.com/jmelahman/tag/actions/workflows/test.yml/badge.svg)](https://github.com/jmelahman/tag/actions)
4
+ [![Deploy Status](https://github.com/jmelahman/tag/actions/workflows/release.yml/badge.svg)](https://github.com/jmelahman/tag/actions)
5
+ [![Go Reference](https://pkg.go.dev/badge/github.com/jmelahman/tag.svg)](https://pkg.go.dev/github.com/jmelahman/tag)
6
+ [![PyPI](https://img.shields.io/pypi/v/release-tag.svg)]()
7
+ [![Go Report Card](https://goreportcard.com/badge/github.com/jmelahman/tag)](https://goreportcard.com/report/github.com/jmelahman/tag)
8
+
9
+ Automatically create [semantic version](https://semver.org/) git tags.
10
+
11
+ ```shell
12
+ $ tag --push
13
+ Next version: v1.0.1
14
+ Tag v1.0.1 created and pushed to remote.
15
+ ```
16
+
17
+ ### Autocomplete
18
+
19
+ `tag` provides autocomplete for `bash`, `fish`, `powershell` and `zsh` shells.
20
+ For example, to enable autocomplete for the `bash` shell,
21
+
22
+ ```shell
23
+ tag completion bash | sudo tee /etc/bash_completion.d/tag > /dev/null
24
+ ```
25
+
26
+ _Note: bash completion requires the [bash-completion](https://github.com/scop/bash-completion/) package be installed._
27
+
28
+ For more information, see `tag completion <shell> --help` for your respective `<shell>`.
29
+
30
+ ## Install
31
+
32
+ **pip:**
33
+
34
+ `tag` is available as a [pypi package](https://pypi.org/project/release-tag/).
35
+
36
+ ```shell
37
+ pip install release-tag
38
+ ```
39
+
40
+ **go:**
41
+
42
+ ```shell
43
+ go install github.com/jmelahman/tag@latest
44
+ ```
45
+
46
+ **github:**
47
+
48
+ Prebuilt packages are available from [Github Releases](https://github.com/jmelahman/tag/releases).
@@ -0,0 +1,10 @@
1
+ module github.com/jmelahman/tag
2
+
3
+ go 1.23.4
4
+
5
+ require github.com/spf13/cobra v1.8.1
6
+
7
+ require (
8
+ github.com/inconshreveable/mousetrap v1.1.0 // indirect
9
+ github.com/spf13/pflag v1.0.5 // indirect
10
+ )
@@ -0,0 +1,10 @@
1
+ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
2
+ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
3
+ github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
4
+ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
5
+ github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
6
+ github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
7
+ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
8
+ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
9
+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
10
+ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
@@ -0,0 +1,22 @@
1
+ import os
2
+ import subprocess
3
+
4
+ from hatchling.builders.hooks.plugin.interface import BuildHookInterface
5
+
6
+
7
+ class GoBinaryBuildHook(BuildHookInterface):
8
+ def initialize(self, version, build_data):
9
+ build_data["pure_python"] = False
10
+ binary_name = self.config["binary_name"]
11
+ tag = os.getenv("GITHUB_REF_NAME", "dev")
12
+ commit = os.getenv("GITHUB_SHA", "none")
13
+
14
+ if not os.path.exists(binary_name):
15
+ print(f"Building Go binary '{binary_name}'...")
16
+ subprocess.check_call(
17
+ ["go", "build", f"-ldflags=-X main.version={tag} -X main.commit={commit} -s -w", "-o", binary_name],
18
+ env={"GOOS": "linux", "GOARCH": "amd64", **os.environ},
19
+ )
20
+
21
+ build_data["shared_scripts"] = {binary_name: binary_name}
22
+
@@ -0,0 +1,171 @@
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+ "os"
6
+ "os/exec"
7
+ "regexp"
8
+ "strconv"
9
+ "strings"
10
+
11
+ "github.com/spf13/cobra"
12
+ )
13
+
14
+ var (
15
+ version = "dev"
16
+ commit = "none"
17
+ )
18
+
19
+ func main() {
20
+ var major, minor, push bool
21
+
22
+ rootCmd := &cobra.Command{
23
+ Use: "tag",
24
+ Short: "Calculate the next semantic version tag",
25
+ Version: fmt.Sprintf("%s\ncommit %s", version, commit),
26
+ Run: func(cmd *cobra.Command, args []string) {
27
+ latestTag, err := getLatestSemverTag()
28
+ if err != nil {
29
+ fmt.Printf("Error: %v\n", err)
30
+ os.Exit(1)
31
+ }
32
+
33
+ nextVersion, err := calculateNextVersion(latestTag, major, minor)
34
+ if err != nil {
35
+ fmt.Printf("Error: %v\n", err)
36
+ os.Exit(1)
37
+ }
38
+
39
+ fmt.Printf("Next version: %s\n", nextVersion)
40
+
41
+ if push {
42
+ if err := createAndPushTag(nextVersion); err != nil {
43
+ fmt.Printf("Error: %v\n", err)
44
+ os.Exit(1)
45
+ }
46
+ fmt.Printf("Tag %s created and pushed to remote.\n", nextVersion)
47
+ }
48
+ },
49
+ }
50
+
51
+ rootCmd.Flags().BoolVar(&major, "major", false, "increment the major version")
52
+ rootCmd.Flags().BoolVar(&minor, "minor", false, "increment the minor version")
53
+ rootCmd.Flags().BoolVar(&push, "push", false, "create and push the tag to remote")
54
+
55
+ rootCmd.AddCommand(addCompletionCmd(rootCmd))
56
+
57
+ if err := rootCmd.Execute(); err != nil {
58
+ fmt.Printf("Error: %v\n", err)
59
+ os.Exit(1)
60
+ }
61
+ }
62
+
63
+ func addCompletionCmd(cmd *cobra.Command) *cobra.Command {
64
+ var completionCmd = &cobra.Command{
65
+ Use: "completion [bash|zsh|fish|powershell]",
66
+ Short: "Generate completion script",
67
+ Long: fmt.Sprintf(`To load completions:
68
+
69
+ Bash:
70
+
71
+ $ source <(%[1]s completion bash)
72
+
73
+ # To load completions for each session, execute once:
74
+ # Linux:
75
+ $ %[1]s completion bash > /etc/bash_completion.d/%[1]s
76
+ # macOS:
77
+ $ %[1]s completion bash > $(brew --prefix)/etc/bash_completion.d/%[1]s
78
+
79
+ Zsh:
80
+
81
+ # If shell completion is not already enabled in your environment,
82
+ # you will need to enable it. You can execute the following once:
83
+
84
+ $ echo "autoload -U compinit; compinit" >> ~/.zshrc
85
+
86
+ # To load completions for each session, execute once:
87
+ $ %[1]s completion zsh > "${fpath[1]}/_%[1]s"
88
+
89
+ # You will need to start a new shell for this setup to take effect.
90
+
91
+ fish:
92
+
93
+ $ %[1]s completion fish | source
94
+
95
+ # To load completions for each session, execute once:
96
+ $ %[1]s completion fish > ~/.config/fish/completions/%[1]s.fish
97
+
98
+ PowerShell:
99
+
100
+ PS> %[1]s completion powershell | Out-String | Invoke-Expression
101
+
102
+ # To load completions for every new session, run:
103
+ PS> %[1]s completion powershell > %[1]s.ps1
104
+ # and source this file from your PowerShell profile.
105
+ `, cmd.Root().Name()),
106
+ DisableFlagsInUseLine: true,
107
+ ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
108
+ Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
109
+ Run: func(cmd *cobra.Command, args []string) {
110
+ switch args[0] {
111
+ case "bash":
112
+ cmd.Root().GenBashCompletion(os.Stdout)
113
+ case "zsh":
114
+ cmd.Root().GenZshCompletion(os.Stdout)
115
+ case "fish":
116
+ cmd.Root().GenFishCompletion(os.Stdout, true)
117
+ case "powershell":
118
+ cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
119
+ }
120
+ },
121
+ }
122
+ return completionCmd
123
+ }
124
+
125
+ func getLatestSemverTag() (string, error) {
126
+ cmd := exec.Command("git", "describe", "--tags", "--abbrev=0", "--match", "v[0-9].[0-9].[0-9]")
127
+ output, err := cmd.Output()
128
+ if err != nil {
129
+ return "v0.0.0", nil
130
+ }
131
+ return strings.TrimSpace(string(output)), nil
132
+ }
133
+
134
+ func calculateNextVersion(tag string, incMajor, incMinor bool) (string, error) {
135
+ re := regexp.MustCompile(`v(\d+)\.(\d+)\.(\d+)`)
136
+ matches := re.FindStringSubmatch(tag)
137
+ if matches == nil {
138
+ return "", fmt.Errorf("invalid semver tag: %s", tag)
139
+ }
140
+
141
+ major, _ := strconv.Atoi(matches[1])
142
+ minor, _ := strconv.Atoi(matches[2])
143
+ patch, _ := strconv.Atoi(matches[3])
144
+
145
+ if incMajor {
146
+ major++
147
+ minor = 0
148
+ patch = 0
149
+ } else if incMinor {
150
+ minor++
151
+ patch = 0
152
+ } else {
153
+ patch++
154
+ }
155
+
156
+ return fmt.Sprintf("v%d.%d.%d", major, minor, patch), nil
157
+ }
158
+
159
+ func createAndPushTag(tag string) error {
160
+ cmd := exec.Command("git", "tag", tag)
161
+ if err := cmd.Run(); err != nil {
162
+ return fmt.Errorf("failed to create tag: %w", err)
163
+ }
164
+
165
+ cmd = exec.Command("git", "push", "origin", tag)
166
+ if err := cmd.Run(); err != nil {
167
+ return fmt.Errorf("failed to push tag: %w", err)
168
+ }
169
+
170
+ return nil
171
+ }
@@ -0,0 +1,33 @@
1
+ [build-system]
2
+ requires = ["hatchling", "hatch-vcs"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "release-tag"
7
+ description = "Automatically create semantic version git tags"
8
+ license = {file = "LICENSE"}
9
+ authors = [{ name = "Jamison Lahman", email = "jamison@lahman.dev" }]
10
+ readme = "README.md"
11
+ requires-python = ">=3.6"
12
+ keywords = [
13
+ "releasing", "release", "git", "semver", "tagging", "git tags"
14
+ ]
15
+ classifiers = [
16
+ "Programming Language :: Go",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: OS Independent",
19
+ ]
20
+ dynamic = ["version"]
21
+
22
+
23
+ [project.urls]
24
+ Repository = "https://github.com/jmelahman/tag"
25
+
26
+ [tool.hatch.build]
27
+ include = ["go.mod", "go.sum", "**/*.go"]
28
+
29
+ [tool.hatch.version]
30
+ source = "vcs"
31
+
32
+ [tool.hatch.build.hooks.custom]
33
+ binary_name = "tag"