Skip to content

Commit 05b22fd

Browse files
committed
Automated Release to GH (on version tag change)
1 parent 8e42866 commit 05b22fd

3 files changed

Lines changed: 142 additions & 80 deletions

File tree

.github/workflows/build-and-release.yml

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,49 @@ name: Build and Release
33
on:
44
push:
55
branches: [ main, master ]
6-
tags:
7-
- 'v*'
86
pull_request:
97
branches: [ main, master ]
108

119
jobs:
10+
check-version:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
version: ${{ steps.version.outputs.version }}
14+
version-changed: ${{ steps.version.outputs.changed }}
15+
should-release: ${{ steps.version.outputs.changed }}
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 2
21+
22+
- name: Check version change
23+
id: version
24+
run: |
25+
# Get current version from package.json
26+
CURRENT_VERSION=$(node -p "require('./package.json').version")
27+
echo "version=v$CURRENT_VERSION" >> $GITHUB_OUTPUT
28+
29+
# Check if package.json changed in this push
30+
if git diff HEAD~1 HEAD --name-only | grep -q "package.json"; then
31+
# Check if version field specifically changed
32+
PREV_VERSION=$(git show HEAD~1:package.json | node -p "JSON.parse(require('fs').readFileSync('/dev/stdin', 'utf8')).version" 2>/dev/null || echo "0.0.0")
33+
if [ "$CURRENT_VERSION" != "$PREV_VERSION" ]; then
34+
echo "changed=true" >> $GITHUB_OUTPUT
35+
echo "Version changed from $PREV_VERSION to $CURRENT_VERSION"
36+
else
37+
echo "changed=false" >> $GITHUB_OUTPUT
38+
echo "Version unchanged: $CURRENT_VERSION"
39+
fi
40+
else
41+
echo "changed=false" >> $GITHUB_OUTPUT
42+
echo "package.json not modified"
43+
fi
44+
1245
build:
1346
runs-on: windows-latest
47+
needs: check-version
48+
if: always()
1449

1550
steps:
1651
- name: Checkout code
@@ -36,7 +71,7 @@ jobs:
3671
- name: Upload Windows artifacts
3772
uses: actions/upload-artifact@v4
3873
with:
39-
name: windows-build
74+
name: windows-build-${{ needs.check-version.outputs.version }}
4075
path: |
4176
dist/*.exe
4277
dist/*.msi
@@ -46,40 +81,60 @@ jobs:
4681
retention-days: 30
4782
if-no-files-found: warn
4883

49-
release:
50-
needs: build
84+
create-tag-and-release:
85+
needs: [check-version, build]
5186
runs-on: ubuntu-latest
52-
if: startsWith(github.ref, 'refs/tags/v')
87+
if: needs.check-version.outputs.should-release == 'true'
5388

5489
steps:
5590
- name: Checkout code
5691
uses: actions/checkout@v4
5792

93+
- name: Create and push tag
94+
run: |
95+
git config user.name "github-actions[bot]"
96+
git config user.email "github-actions[bot]@users.noreply.github.com"
97+
git tag ${{ needs.check-version.outputs.version }}
98+
git push origin ${{ needs.check-version.outputs.version }}
99+
env:
100+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101+
58102
- name: Download Windows artifacts
59103
uses: actions/download-artifact@v4
60104
with:
61-
name: windows-build
105+
name: windows-build-${{ needs.check-version.outputs.version }}
62106
path: dist/
63107

64108
- name: Create GitHub Release
65109
uses: softprops/action-gh-release@v1
66110
with:
111+
tag_name: ${{ needs.check-version.outputs.version }}
112+
name: Release ${{ needs.check-version.outputs.version }}
67113
files: |
68114
dist/*.exe
69115
dist/*.msi
70116
dist/*.zip
71117
draft: false
72118
prerelease: false
73119
generate_release_notes: true
74-
name: Release ${{ github.ref_name }}
75-
tag_name: ${{ github.ref_name }}
120+
body: |
121+
## What's Changed
122+
123+
Version bumped to ${{ needs.check-version.outputs.version }}
124+
125+
### Downloads
126+
- **Windows Installer**: Download the `.exe` file for standard installation
127+
- **Portable**: Download the portable `.exe` for standalone usage
128+
129+
Full changelog: https://github.com/${{ github.repository }}/compare/v${{ needs.check-version.outputs.version }}...HEAD
76130
env:
77131
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78132

79-
# Optional: Build on every push for testing (without release)
80-
build-on-push:
133+
# Build on push without release (when version hasn't changed)
134+
build-only:
81135
runs-on: windows-latest
82-
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
136+
needs: check-version
137+
if: needs.check-version.outputs.should-release != 'true'
83138

84139
steps:
85140
- name: Checkout code

RELEASE.md

Lines changed: 65 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
# Release Process
1+
# Automatic Release Process
22

3-
This project is configured with automated GitHub Actions to build and release Windows executables.
3+
This project now features **fully automated releases** that trigger when the version in `package.json` changes!
44

55
## How it works
66

7-
1. **On every push** to `main`/`master`: The workflow builds the app to test that everything compiles correctly
8-
2. **On tag push** (version tags like `v1.0.0`): The workflow builds the app and creates a GitHub release with Windows executables
7+
1. **On every push**: GitHub Actions checks if the version in `package.json` has changed
8+
2. **If version changed**: Automatically builds the app, creates a git tag, and publishes a GitHub release
9+
3. **If version unchanged**: Just builds the app to test that everything compiles correctly
910

10-
## Creating a Release
11+
## Creating a Release (Super Easy!)
1112

1213
### Method 1: Using the release scripts (Recommended)
1314

@@ -24,85 +25,87 @@ npm run release:major
2425

2526
These scripts will:
2627
- Bump the version in `package.json`
27-
- Create a git tag
28-
- Push changes and tags to GitHub
29-
- Trigger the GitHub Actions workflow automatically
28+
- Push the changes to GitHub
29+
- **GitHub Actions automatically detects the version change and creates the release!**
3030

31-
### Method 2: Manual process
31+
### Method 2: Manual version bump
3232

3333
```bash
3434
# Bump version manually
3535
npm version patch # or minor, major
3636

37-
# Push changes and tags
37+
# Push changes
3838
git push
39-
git push --tags
40-
```
4139

42-
## What gets built
43-
44-
The GitHub Actions workflow will create:
45-
- **NSIS Installer** (`.exe`) - Standard Windows installer
46-
- **Portable Executable** (`.exe`) - Standalone executable that doesn't require installation
47-
- **MSI Package** (if configured) - Windows Installer package
48-
49-
## Build Configuration
50-
51-
The build configuration is in `package.json` under the `build` section:
52-
53-
```json
54-
{
55-
"build": {
56-
"appId": "cdc.starterkit.electron",
57-
"productName": "CDC Electron Starterkit",
58-
"win": {
59-
"target": [
60-
{
61-
"target": "nsis",
62-
"arch": ["x64"]
63-
},
64-
{
65-
"target": "portable",
66-
"arch": ["x64"]
67-
}
68-
]
69-
}
70-
}
71-
}
40+
# GitHub Actions will automatically handle the rest!
7241
```
7342

74-
## GitHub Actions Workflow
43+
### Method 3: Edit package.json directly
44+
45+
You can even manually edit the version in `package.json`, commit, and push - the workflow will detect the change and create a release automatically!
46+
47+
## What Gets Built Automatically
48+
49+
When a version change is detected, GitHub Actions will:
50+
- **Build** the Windows executable
51+
- **Create a git tag** (e.g., `v1.0.1`)
52+
- **Create a GitHub release** with:
53+
- NSIS Installer (`.exe`) - Standard Windows installer
54+
- Portable Executable (`.exe`) - Standalone executable
55+
- Auto-generated release notes
7556

76-
The workflow file is located at `.github/workflows/build-and-release.yml` and includes:
57+
## Workflow Jobs
7758

78-
- **Build job**: Runs on Windows, builds the app, uploads artifacts
79-
- **Release job**: Creates GitHub release with built executables (only on tag push)
80-
- **Build-on-push job**: Tests builds on every push without releasing
59+
The new workflow includes these jobs:
8160

82-
## Requirements
61+
1. **check-version**: Detects if version in `package.json` changed
62+
2. **build**: Builds the app and uploads artifacts (always runs)
63+
3. **create-tag-and-release**: Creates tag and GitHub release (only if version changed)
64+
4. **build-only**: Test build without release (only if version unchanged)
8365

84-
- Repository must have GitHub Actions enabled
85-
- The `GITHUB_TOKEN` is automatically provided by GitHub Actions
86-
- Repository must match the one configured in `package.json` (`codesign-cloud/cdc-electron-starterkit`)
66+
## Example Workflow
67+
68+
```bash
69+
# Current version is 1.0.0
70+
npm run release:patch
71+
72+
# This will:
73+
# 1. Change package.json version to 1.0.1
74+
# 2. Commit the change
75+
# 3. Push to GitHub
76+
# 4. GitHub Actions detects version change
77+
# 5. Builds Windows executable
78+
# 6. Creates tag v1.0.1
79+
# 7. Creates GitHub release with executables
80+
```
81+
82+
## Monitoring Releases
83+
84+
- Check the **Actions** tab to see the build progress
85+
- Check the **Releases** section to see published releases
86+
- Each release will include download links for Windows executables
87+
88+
## Benefits of This Approach
89+
90+
**Fully Automated**: Just bump version and push
91+
**No Manual Tagging**: Tags are created automatically
92+
**Version Control**: Only creates releases when version actually changes
93+
**Consistent**: Same process every time
94+
**Safe**: Still builds and tests on every push
8795

8896
## Troubleshooting
8997

90-
If builds fail:
91-
1. Check the GitHub Actions logs in the "Actions" tab of your repository
92-
2. Ensure all dependencies are properly listed in `package.json`
93-
3. Test the build locally with `npm run build`
94-
4. Make sure the repository name in `package.json` matches your actual repository
98+
If releases aren't being created:
99+
1. Ensure the version in `package.json` actually changed
100+
2. Check the Actions tab for any workflow errors
101+
3. Verify you have push permissions to the repository
102+
4. Make sure the workflow file is in the correct location
95103

96104
## Local Testing
97105

98-
To test the build process locally:
106+
To test builds locally without releasing:
99107

100108
```bash
101-
# Install dependencies
102109
npm ci
103-
104-
# Build renderer
105110
npm run build:renderer
106-
107-
# Build for Windows (requires Windows or cross-compilation setup)
108111
npm run build

scripts/create-release.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const { execSync } = require('child_process');
44
const fs = require('fs');
5-
const path = require('path');
65

76
// Read current version from package.json
87
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
@@ -29,13 +28,18 @@ try {
2928

3029
console.log(`New version: ${newVersion}`);
3130

32-
// Push changes and tags
33-
console.log('Pushing changes and tags...');
31+
// Push changes (GitHub Actions will detect version change and create release automatically)
32+
console.log('Pushing changes...');
3433
execSync('git push', { stdio: 'inherit' });
35-
execSync('git push --tags', { stdio: 'inherit' });
3634

37-
console.log(`✅ Release v${newVersion} created successfully!`);
38-
console.log('GitHub Actions will now build and create the release automatically.');
35+
console.log(`✅ Version bumped to v${newVersion}!`);
36+
console.log('🚀 GitHub Actions will automatically:');
37+
console.log(' - Detect the version change');
38+
console.log(' - Build the Windows executable');
39+
console.log(' - Create a git tag');
40+
console.log(' - Create a GitHub release');
41+
console.log('');
42+
console.log('Check the Actions tab in your repository to monitor progress.');
3943

4044
} catch (error) {
4145
console.error('❌ Error creating release:', error.message);

0 commit comments

Comments
 (0)