Skip to content

Commit f0c12b4

Browse files
authored
Convert make release to Go script with improved UI (#18)
- Convert release target from shell script to Go script (scripts/make-release.go) - Add colored terminal output with emojis for better UX - Improve error handling and validation - Use proper version parsing library for tag management - Update README to reflect PR-based workflow as default - Simplify Makefile release target to call Go script - Maintain all existing functionality including default branch updates
1 parent 419f76b commit f0c12b4

File tree

4 files changed

+589
-50
lines changed

4 files changed

+589
-50
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ name: "CodeQL"
1313

1414
on:
1515
push:
16-
branches: [ master ]
16+
branches: [ "r3.0.62", "3.0.62" ]
1717
pull_request:
1818
# The branches below must be a subset of the branches above
19-
branches: [ master ]
19+
branches: [ "r3.0.62", "3.0.62" ]
2020
schedule:
2121
- cron: '20 21 * * 3'
2222

@@ -42,7 +42,7 @@ jobs:
4242

4343
# Initializes the CodeQL tools for scanning.
4444
- name: Initialize CodeQL
45-
uses: github/codeql-action/init@v2
45+
uses: github/codeql-action/init@v3
4646
with:
4747
languages: ${{ matrix.language }}
4848
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -56,7 +56,7 @@ jobs:
5656
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5757
# If this step fails, then you should remove it and run the build manually (see below)
5858
- name: Autobuild
59-
uses: github/codeql-action/autobuild@v2
59+
uses: github/codeql-action/autobuild@v3
6060

6161
# ℹ️ Command-line programs to run using the OS shell.
6262
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
@@ -69,4 +69,4 @@ jobs:
6969
# ./location_of_script_within_repo/buildscript.sh
7070

7171
- name: Perform CodeQL Analysis
72-
uses: github/codeql-action/analyze@v2
72+
uses: github/codeql-action/analyze@v3

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ help: ## Show this help message
4242
@echo ''
4343
@echo 'Examples:'
4444
@echo ' make build Build the provider'
45+
@echo ' make release Create a release PR branch (PR-based workflow)'
4546
@echo ' make testversion8.0 Run tests against MySQL 8.0'
4647
@echo ' make testtidb8.5.3 Run tests against TiDB 8.5.3'
4748
@echo ' make acceptance Run all acceptance tests'
@@ -181,7 +182,7 @@ testmariadb: ## Run tests against MariaDB version (set MYSQL_VERSION)
181182

182183
vet: ## Run go vet
183184
@echo "go vet ."
184-
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
185+
@go vet $$(go list ./... | grep -v vendor/ | grep -v '/scripts') ; if [ $$? -eq 1 ]; then \
185186
echo ""; \
186187
echo "Vet found suspicious constructs. Please check the reported constructs"; \
187188
echo "and fix them if necessary before submitting the code for review."; \
@@ -241,7 +242,7 @@ tag: ## Create git tag from VERSION file
241242
@echo git tag -a $(shell cat VERSION) -m $(shell cat VERSION)
242243
@git tag -a v$(shell cat VERSION) -m v$(shell cat VERSION)
243244

244-
release: ## Create a release (tag, build, and optionally push to GitHub)
245+
release-local: ## Create a release locally (for testing - use 'make release' for PR-based workflow)
245246
@VERSION=$$(cat VERSION); \
246247
TAG="v$$VERSION"; \
247248
echo "Checking if tag $$TAG already exists..."; \
@@ -347,4 +348,7 @@ release: ## Create a release (tag, build, and optionally push to GitHub)
347348
echo ""; \
348349
echo "Release complete! Tag $$TAG has been pushed to GitHub."
349350

350-
.PHONY: help build test testacc vet fmt fmtcheck errcheck vendor-status test-compile website website-test tag format-tag release
351+
release: ## Create a release PR branch (tag, push branch and tag, then create PR to merge to default branch)
352+
@go run scripts/make-release.go
353+
354+
.PHONY: help build test testacc vet fmt fmtcheck errcheck vendor-status test-compile website website-test tag format-tag release release-local

README.md

Lines changed: 79 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -40,36 +40,25 @@ https://www.linkedin.com/in/zph/ that appropriate safeguards are being taken.
4040

4141
## Release Process
4242

43-
The release process is automated through the `make release` command, which handles tag management, version file updates, GitHub releases, and pushing changes.
43+
The release process uses a PR-based workflow through the `make release` command. This creates a release branch, tags the release, and pushes both to GitHub. GitHub Actions then automatically builds and creates the release when the tag is pushed.
4444

4545
### Prerequisites
4646

4747
Before running the release process, ensure you have the following set up:
4848

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.
49+
1. **GitHub Authentication**: You need authentication configured for pushing to GitHub.
6150
- Either configure SSH keys for git push, or
6251
- 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
6452

65-
3. **Required Tools**:
66-
- `goreleaser` - Install from https://goreleaser.com/install/
53+
2. **Required Tools**:
6754
- `git` - For version control operations
6855
- `make` - For running the release command
6956

70-
### Release Workflow
57+
**Note**: GPG signing and release building are handled automatically by GitHub Actions CI/CD. You don't need to configure GPG keys or goreleaser locally for the PR-based workflow.
7158

72-
The `make release` command performs the following steps:
59+
### Release Workflow (PR-Based)
60+
61+
The `make release` command implements a PR-based workflow:
7362

7463
1. **Version Check**: Reads the current version from the `VERSION` file and checks if a tag for that version already exists.
7564

@@ -80,38 +69,47 @@ The `make release` command performs the following steps:
8069

8170
3. **Version File Update**: If a new version was determined, the `VERSION` file is automatically updated with the new version number.
8271

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
72+
4. **Default Branch Update**: Fetches and updates the default branch (`r3.0.62`) to ensure the release branch is created from the latest code.
73+
74+
5. **Release Branch Creation**: Creates a new branch named `release/v{VERSION}` (e.g., `release/v3.0.62007`) from the updated default branch.
75+
76+
6. **Version File Commit**: If the `VERSION` file was modified, it commits the change on the release branch with message "Update VERSION to {version}".
77+
78+
7. **Tag Creation**: Creates an annotated git tag with the version number on the release branch.
8779

88-
5. **Tag Creation**: Creates an annotated git tag with the version number.
80+
8. **Push to GitHub**: Pushes both the release branch and tag to GitHub.
8981

90-
6. **Version File Commit**: If the `VERSION` file was modified, it commits the change with message "Update VERSION to {version}".
82+
9. **GitHub Actions**: When the tag is pushed, GitHub Actions automatically:
83+
- Builds binaries for all supported platforms (Linux, macOS, Windows, FreeBSD)
84+
- Creates archives (zip files) for each platform/architecture combination
85+
- Generates SHA256 checksums
86+
- Signs the checksum file with GPG (configured in CI/CD)
87+
- Creates a GitHub release
9188

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)
89+
10. **Pull Request**: Create a pull request from the release branch (`release/v{VERSION}`) to the default branch (`r3.0.62`).
9890

99-
8. **Push to GitHub**: Pushes the tag and commits to the remote repository.
91+
11. **Merge**: After CI completes successfully, merge the PR to complete the release.
10092

10193
### Usage
10294

103-
To create a release, simply run:
95+
To create a release using the PR-based workflow:
10496

10597
```bash
10698
make release
10799
```
108100

109101
The process will guide you through each step with clear prompts. You can cancel at any point if needed.
110102

103+
**Note**: The command automatically updates the default branch (`r3.0.62`) before creating the release branch, so you can run it from any branch. The release branch will always be created from the latest version of the default branch.
104+
111105
### Example Release Session
112106

113107
```bash
114108
$ make release
109+
Updating default branch (r3.0.62) before creating release branch...
110+
Fetching latest changes from origin...
111+
Checking out default branch r3.0.62...
112+
Default branch updated successfully.
115113
Checking if tag v3.0.62006 already exists...
116114
Tag v3.0.62006 already exists!
117115
Current version from VERSION file: 3.0.62006
@@ -127,30 +125,69 @@ VERSION file updated.
127125
Release Summary:
128126
Tag: v3.0.62007
129127
Version: 3.0.62007
128+
Release Branch: release/v3.0.62007
129+
Target Branch: r3.0.62
130130
=========================================
131131

132-
Do you want to create tag v3.0.62007? (yes/no): yes
132+
Do you want to create release branch and tag v3.0.62007? (yes/no): yes
133+
134+
Creating release branch release/v3.0.62007 from updated default branch (r3.0.62)...
135+
Release branch created from updated r3.0.62.
133136

134-
Creating tag v3.0.62007...
137+
Committing VERSION file change...
135138
VERSION file change committed.
139+
140+
Creating annotated tag v3.0.62007...
136141
Tag v3.0.62007 created successfully.
137142

138-
Do you want to deploy this as a GitHub release? (yes/no): yes
143+
Pushing branch and tag to origin...
144+
Branch and tag pushed successfully.
145+
146+
=========================================
147+
Release PR Created Successfully!
148+
=========================================
149+
150+
Next steps:
151+
1. GitHub Actions will automatically build the release when the tag is pushed.
152+
2. Create a pull request:
153+
- Source: release/v3.0.62007
154+
- Target: r3.0.62
155+
- URL: https://github.com/zph/terraform-provider-mysql/compare/r3.0.62...release/v3.0.62007
156+
3. Wait for CI to complete the release build.
157+
4. Review and merge the PR into r3.0.62 to complete the release.
158+
159+
To switch back to your previous branch, run:
160+
git checkout your-feature-branch
161+
```
139162
140-
Running goreleaser to create GitHub release...
141-
[... goreleaser output ...]
163+
### Local Testing Workflow (`make release-local`)
142164
143-
Do you want to push tags and commits to GitHub? (yes/no): yes
165+
For local testing and debugging, you can use `make release-local` which runs goreleaser locally:
144166
145-
Pushing to GitHub...
146-
Release complete! Tag v3.0.62007 has been pushed to GitHub.
167+
```bash
168+
make release-local
147169
```
148170
171+
This command:
172+
- Runs the same version detection and tag management logic as `make release`
173+
- Creates tags and commits locally
174+
- Runs `goreleaser` locally to build and create a GitHub release
175+
- Requires GPG key setup (set `GPG_FINGERPRINT` environment variable)
176+
- Requires `goreleaser` installed locally
177+
178+
**Use `make release-local` only for:**
179+
- Testing release builds locally
180+
- Debugging goreleaser configuration
181+
- Creating releases without CI/CD (not recommended for production)
182+
183+
**For production releases, always use `make release` (PR-based workflow).**
184+
149185
### Troubleshooting
150186
151-
- **GPG signing fails**: Ensure `GPG_FINGERPRINT` is set correctly and your GPG key is available in your keyring
152187
- **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
188+
- **Branch already exists**: If the release branch already exists, delete it first or use a different version
189+
- **CI/CD build fails**: Check GitHub Actions logs for build errors. The release will be created automatically when the tag is pushed successfully
190+
- **PR merge conflicts**: Resolve conflicts in the PR before merging. The tag and release are already created, so merging just updates the default branch
154191
155192
## Original Readme
156193
Below is from petoju/terraform-provider-mysql:

0 commit comments

Comments
 (0)