Skip to content

Commit c2f2580

Browse files
committed
Improve release process with tag checks and confirmations
Adds interactive prompts for tag management, version file updates, and GitHub release deployment. Includes documentation for required environment variables and GPG signing setup.
1 parent 7eda440 commit c2f2580

File tree

2 files changed

+220
-2
lines changed

2 files changed

+220
-2
lines changed

GNUmakefile

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,109 @@ tag:
166166
@git tag -a v$(shell cat VERSION) -m v$(shell cat VERSION)
167167

168168
release:
169-
@goreleaser release --clean --verbose
170-
.PHONY: build test testacc vet fmt fmtcheck errcheck vendor-status test-compile website website-test tag format-tag
169+
@VERSION=$$(cat VERSION); \
170+
TAG="v$$VERSION"; \
171+
echo "Checking if tag $$TAG already exists..."; \
172+
if git rev-parse "$$TAG" >/dev/null 2>&1; then \
173+
echo "Tag $$TAG already exists!"; \
174+
echo "Current version from VERSION file: $$VERSION"; \
175+
\
176+
LAST_TAG=$$(git tag --list "v*" | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+" | sort -V | tail -1); \
177+
if [ -n "$$LAST_TAG" ]; then \
178+
LAST_VERSION=$${LAST_TAG#v}; \
179+
echo "Most recent tag: $$LAST_TAG (version: $$LAST_VERSION)"; \
180+
\
181+
MAJOR_MINOR=$$(echo "$$LAST_VERSION" | sed -E 's/\.[0-9]+$$//'); \
182+
BUILD_NUM=$$(echo "$$LAST_VERSION" | sed -E 's/.*\.([0-9]+)$$/\1/'); \
183+
NEXT_BUILD=$$((BUILD_NUM + 1)); \
184+
NEXT_VERSION="$$MAJOR_MINOR.$$NEXT_BUILD"; \
185+
NEXT_TAG="v$$NEXT_VERSION"; \
186+
\
187+
echo ""; \
188+
echo "Suggested next tag: $$NEXT_TAG"; \
189+
echo -n "Enter next tag (or press Enter to use $$NEXT_TAG): "; \
190+
read USER_TAG; \
191+
if [ -z "$$USER_TAG" ]; then \
192+
USER_TAG="$$NEXT_TAG"; \
193+
fi; \
194+
if [ "$${USER_TAG#v}" = "$$USER_TAG" ]; then \
195+
TAG="v$$USER_TAG"; \
196+
else \
197+
TAG="$$USER_TAG"; \
198+
fi; \
199+
VERSION=$${TAG#v}; \
200+
else \
201+
echo "Could not determine next tag. Please enter manually:"; \
202+
read -p "Enter next tag: " USER_TAG; \
203+
if [ "$${USER_TAG#v}" = "$$USER_TAG" ]; then \
204+
TAG="v$$USER_TAG"; \
205+
else \
206+
TAG="$$USER_TAG"; \
207+
fi; \
208+
VERSION=$${TAG#v}; \
209+
fi; \
210+
else \
211+
echo "Tag $$TAG does not exist. Using version from VERSION file: $$VERSION"; \
212+
fi; \
213+
\
214+
ORIGINAL_VERSION=$$(cat VERSION); \
215+
if [ "$$VERSION" != "$$ORIGINAL_VERSION" ]; then \
216+
echo ""; \
217+
echo "Updating VERSION file from $$ORIGINAL_VERSION to $$VERSION..."; \
218+
echo "$$VERSION" > VERSION; \
219+
echo "VERSION file updated."; \
220+
fi; \
221+
\
222+
echo ""; \
223+
echo "========================================="; \
224+
echo "Release Summary:"; \
225+
echo " Tag: $$TAG"; \
226+
echo " Version: $$VERSION"; \
227+
echo "========================================="; \
228+
echo ""; \
229+
echo -n "Do you want to create tag $$TAG? (yes/no): "; \
230+
read CONFIRM_TAG; \
231+
if [ "$$CONFIRM_TAG" != "yes" ]; then \
232+
echo "Tag creation cancelled."; \
233+
exit 1; \
234+
fi; \
235+
\
236+
echo ""; \
237+
echo "Creating tag $$TAG..."; \
238+
if [ "$$VERSION" != "$$ORIGINAL_VERSION" ]; then \
239+
git add VERSION || exit 1; \
240+
git commit -m "Update VERSION to $$VERSION" || exit 1; \
241+
echo "VERSION file change committed."; \
242+
fi; \
243+
git tag -a "$$TAG" -m "$$TAG" || exit 1; \
244+
echo "Tag $$TAG created successfully."; \
245+
\
246+
echo ""; \
247+
echo -n "Do you want to deploy this as a GitHub release? (yes/no): "; \
248+
read CONFIRM_RELEASE; \
249+
if [ "$$CONFIRM_RELEASE" != "yes" ]; then \
250+
echo "GitHub release cancelled. Tag created but not released."; \
251+
echo "You can release it later with: goreleaser release --clean"; \
252+
exit 0; \
253+
fi; \
254+
\
255+
echo ""; \
256+
echo "Running goreleaser to create GitHub release..."; \
257+
goreleaser release --clean --verbose || exit 1; \
258+
\
259+
echo ""; \
260+
echo -n "Do you want to push tags and commits to GitHub? (yes/no): "; \
261+
read CONFIRM_PUSH; \
262+
if [ "$$CONFIRM_PUSH" != "yes" ]; then \
263+
echo "Push cancelled. Tag and release created locally."; \
264+
exit 0; \
265+
fi; \
266+
\
267+
echo ""; \
268+
echo "Pushing to GitHub..."; \
269+
git push origin --tags || exit 1; \
270+
git push origin HEAD || exit 1; \
271+
echo ""; \
272+
echo "Release complete! Tag $$TAG has been pushed to GitHub."
273+
274+
.PHONY: build test testacc vet fmt fmtcheck errcheck vendor-status test-compile website website-test tag format-tag release

README.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,120 @@ I could not introduce opaque security issues into binary releases.
3838
In the meantime, I certify by my professional reputation and career as:
3939
https://www.linkedin.com/in/zph/ that appropriate safeguards are being taken.
4040

41+
## Release Process
42+
43+
The release process is automated through the `make release` command, which handles tag management, version file updates, GitHub releases, and pushing changes.
44+
45+
### Prerequisites
46+
47+
Before running the release process, ensure you have the following set up:
48+
49+
1. **GPG Key for Signing**: A GPG key must be configured for signing release artifacts.
50+
- Set the `GPG_FINGERPRINT` environment variable to your GPG key fingerprint:
51+
```bash
52+
export GPG_FINGERPRINT="your-gpg-key-fingerprint"
53+
```
54+
- To find your GPG key fingerprint:
55+
```bash
56+
gpg --list-secret-keys --keyid-format LONG
57+
```
58+
- The fingerprint is the long string after the key type (e.g., `RSA 4096/ABC123DEF456...`)
59+
60+
2. **GitHub Authentication**: You need authentication configured for pushing to GitHub.
61+
- Either configure SSH keys for git push, or
62+
- Set up a GitHub Personal Access Token with appropriate permissions
63+
- goreleaser will use `GITHUB_TOKEN` environment variable if set, otherwise it will use git credentials
64+
65+
3. **Required Tools**:
66+
- `goreleaser` - Install from https://goreleaser.com/install/
67+
- `git` - For version control operations
68+
- `make` - For running the release command
69+
70+
### Release Workflow
71+
72+
The `make release` command performs the following steps:
73+
74+
1. **Version Check**: Reads the current version from the `VERSION` file and checks if a tag for that version already exists.
75+
76+
2. **Tag Management**:
77+
- If the tag already exists, it automatically suggests the next version by incrementing the build number (e.g., `v3.0.62006``v3.0.62007`)
78+
- You can accept the suggestion or enter a custom tag
79+
- If the tag doesn't exist, it uses the version from the `VERSION` file
80+
81+
3. **Version File Update**: If a new version was determined, the `VERSION` file is automatically updated with the new version number.
82+
83+
4. **Confirmation Prompts**: The process includes interactive confirmations at key steps:
84+
- Confirmation to create and tag the release
85+
- Confirmation to deploy as a GitHub release
86+
- Confirmation to push tags and commits to GitHub
87+
88+
5. **Tag Creation**: Creates an annotated git tag with the version number.
89+
90+
6. **Version File Commit**: If the `VERSION` file was modified, it commits the change with message "Update VERSION to {version}".
91+
92+
7. **GitHub Release**: Uses `goreleaser` to:
93+
- Build binaries for all supported platforms (Linux, macOS, Windows, FreeBSD)
94+
- Create archives (zip files) for each platform/architecture combination
95+
- Generate SHA256 checksums
96+
- Sign the checksum file with your GPG key
97+
- Create a draft GitHub release (you can publish it manually after review)
98+
99+
8. **Push to GitHub**: Pushes the tag and commits to the remote repository.
100+
101+
### Usage
102+
103+
To create a release, simply run:
104+
105+
```bash
106+
make release
107+
```
108+
109+
The process will guide you through each step with clear prompts. You can cancel at any point if needed.
110+
111+
### Example Release Session
112+
113+
```bash
114+
$ make release
115+
Checking if tag v3.0.62006 already exists...
116+
Tag v3.0.62006 already exists!
117+
Current version from VERSION file: 3.0.62006
118+
Most recent tag: v3.0.62006 (version: 3.0.62006)
119+
120+
Suggested next tag: v3.0.62007
121+
Enter next tag (or press Enter to use v3.0.62007):
122+
123+
Updating VERSION file from 3.0.62006 to 3.0.62007...
124+
VERSION file updated.
125+
126+
=========================================
127+
Release Summary:
128+
Tag: v3.0.62007
129+
Version: 3.0.62007
130+
=========================================
131+
132+
Do you want to create tag v3.0.62007? (yes/no): yes
133+
134+
Creating tag v3.0.62007...
135+
VERSION file change committed.
136+
Tag v3.0.62007 created successfully.
137+
138+
Do you want to deploy this as a GitHub release? (yes/no): yes
139+
140+
Running goreleaser to create GitHub release...
141+
[... goreleaser output ...]
142+
143+
Do you want to push tags and commits to GitHub? (yes/no): yes
144+
145+
Pushing to GitHub...
146+
Release complete! Tag v3.0.62007 has been pushed to GitHub.
147+
```
148+
149+
### Troubleshooting
150+
151+
- **GPG signing fails**: Ensure `GPG_FINGERPRINT` is set correctly and your GPG key is available in your keyring
152+
- **GitHub push fails**: Check your git credentials or SSH keys are configured correctly
153+
- **goreleaser fails**: Ensure you have the latest version of goreleaser installed and check the `.goreleaser.yml` configuration
154+
41155
## Original Readme
42156
Below is from petoju/terraform-provider-mysql:
43157

0 commit comments

Comments
 (0)