|
5 | 5 | # test: run all unit tests |
6 | 6 | # lint: run linting checks (golangci-lint) |
7 | 7 | # install-lint-deps: install linting dependencies |
| 8 | +# release: create a new release by updating version numbers and committing changes |
8 | 9 | # help: print this help message |
9 | 10 | # .PHONY: mark targets as phony |
10 | 11 | # .DEFAULT_GOAL: set the default goal to all |
|
14 | 15 | PROJECT_NAME := "gh-token" |
15 | 16 |
|
16 | 17 | # Mark targets as phony |
17 | | -.PHONY: all clean build test lint install-lint-deps |
| 18 | +.PHONY: all clean build test lint install-lint-deps release |
18 | 19 |
|
19 | 20 | # Build the project |
20 | 21 | all: clean build |
|
41 | 42 | install-lint-deps: |
42 | 43 | @mkdir -p .bin |
43 | 44 | curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b .bin v2.4.0 |
| 45 | + |
| 46 | +# Create a new release |
| 47 | +release: |
| 48 | + @echo "Current version in main.go: $$(grep 'Version:' main.go | sed 's/.*Version: *"\(.*\)".*/\1/')" |
| 49 | + @echo "Current version in SECURITY.md: $$(grep -A2 '| Version' SECURITY.md | tail -1 | sed 's/| *\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/')" |
| 50 | + @echo "" |
| 51 | + @read -p "Enter the new semver version (e.g., 2.1.0): " VERSION; \ |
| 52 | + if [ -z "$$VERSION" ]; then \ |
| 53 | + echo "Error: Version cannot be empty"; \ |
| 54 | + exit 1; \ |
| 55 | + fi; \ |
| 56 | + if ! echo "$$VERSION" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$$' > /dev/null; then \ |
| 57 | + echo "Error: Version must be in semver format (e.g., 2.1.0)"; \ |
| 58 | + exit 1; \ |
| 59 | + fi; \ |
| 60 | + MAJOR_MINOR=$$(echo "$$VERSION" | sed 's/\([0-9]*\.[0-9]*\)\.[0-9]*/\1/'); \ |
| 61 | + echo "Updating version to $$VERSION..."; \ |
| 62 | + sed -i.bak 's/Version: *"[^"]*"/Version: "'"$$VERSION"'"/' main.go && rm main.go.bak; \ |
| 63 | + sed -i.bak 's/| [0-9]*\.[0-9]*\.[0-9]* *|/| '"$$MAJOR_MINOR"'.x |/' SECURITY.md && rm SECURITY.md.bak; \ |
| 64 | + echo "Files updated successfully."; \ |
| 65 | + echo ""; \ |
| 66 | + echo "Staging and committing changes..."; \ |
| 67 | + git add main.go SECURITY.md; \ |
| 68 | + git commit -m "Update version to $$VERSION"; \ |
| 69 | + echo ""; \ |
| 70 | + echo "Changes committed successfully!"; \ |
| 71 | + echo ""; \ |
| 72 | + echo "Next steps:"; \ |
| 73 | + echo "- Go to https://github.com/Link-/gh-token/releases/new to create a new release"; \ |
| 74 | + echo "- Create a tag with the same version as the release ($$VERSION)"; \ |
| 75 | + echo "- The binaries will automatically be uploaded as assets once the release has been created" |
0 commit comments