1+ name : Create Release
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ version_type :
7+ description : ' Version bump type'
8+ required : true
9+ default : ' patch'
10+ type : choice
11+ options :
12+ - patch
13+ - minor
14+ - major
15+ custom_version :
16+ description : ' Custom version (optional, overrides version_type if provided)'
17+ required : false
18+ type : string
19+ prerelease :
20+ description : ' Mark as pre-release'
21+ required : false
22+ default : false
23+ type : boolean
24+
25+ permissions :
26+ contents : write
27+ pull-requests : read
28+
29+ jobs :
30+ create-release :
31+ runs-on : ubuntu-latest
32+
33+ steps :
34+ - name : Check authorized user
35+ run : |
36+ if [ "${{ github.actor }}" != "commjoen" ]; then
37+ echo "❌ Unauthorized user: ${{ github.actor }}"
38+ echo "This workflow can only be triggered by @commjoen"
39+ exit 1
40+ fi
41+ echo "✅ Authorized user: ${{ github.actor }}"
42+
43+ - name : Checkout repository
44+ uses : actions/checkout@v4
45+ with :
46+ fetch-depth : 0
47+ token : ${{ secrets.GITHUB_TOKEN }}
48+
49+ - name : Setup Node.js
50+ uses : actions/setup-node@v4
51+ with :
52+ node-version : ' 22'
53+ cache : ' npm'
54+
55+ - name : Install dependencies
56+ run : npm ci
57+
58+ - name : Run tests
59+ run : npm test
60+
61+ - name : Run build
62+ run : npm run build
63+
64+ - name : Configure Git
65+ run : |
66+ git config user.name "github-actions[bot]"
67+ git config user.email "github-actions[bot]@users.noreply.github.com"
68+
69+ - name : Get current version
70+ id : current_version
71+ run : |
72+ CURRENT_VERSION=$(node -p "require('./package.json').version")
73+ echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
74+ echo "Current version: $CURRENT_VERSION"
75+
76+ - name : Calculate new version
77+ id : new_version
78+ run : |
79+ CURRENT_VERSION="${{ steps.current_version.outputs.version }}"
80+ CUSTOM_VERSION="${{ github.event.inputs.custom_version }}"
81+ VERSION_TYPE="${{ github.event.inputs.version_type }}"
82+
83+ if [ -n "$CUSTOM_VERSION" ]; then
84+ # Use custom version if provided
85+ NEW_VERSION="$CUSTOM_VERSION"
86+ echo "Using custom version: $NEW_VERSION"
87+ else
88+ # Calculate semantic version bump
89+ IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
90+ MAJOR=${VERSION_PARTS[0]}
91+ MINOR=${VERSION_PARTS[1]}
92+ PATCH=${VERSION_PARTS[2]}
93+
94+ case "$VERSION_TYPE" in
95+ "major")
96+ MAJOR=$((MAJOR + 1))
97+ MINOR=0
98+ PATCH=0
99+ ;;
100+ "minor")
101+ MINOR=$((MINOR + 1))
102+ PATCH=0
103+ ;;
104+ "patch")
105+ PATCH=$((PATCH + 1))
106+ ;;
107+ esac
108+
109+ NEW_VERSION="$MAJOR.$MINOR.$PATCH"
110+ echo "Calculated $VERSION_TYPE version bump: $NEW_VERSION"
111+ fi
112+
113+ echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
114+ echo "New version will be: $NEW_VERSION"
115+
116+ - name : Update package.json version
117+ run : |
118+ NEW_VERSION="${{ steps.new_version.outputs.version }}"
119+ npm version "$NEW_VERSION" --no-git-tag-version
120+ echo "Updated package.json to version $NEW_VERSION"
121+
122+ - name : Commit version update
123+ run : |
124+ NEW_VERSION="${{ steps.new_version.outputs.version }}"
125+ git add package.json package-lock.json
126+ git commit -m "bump version to $NEW_VERSION"
127+ echo "Committed version update"
128+
129+ - name : Create and push tag
130+ run : |
131+ NEW_VERSION="${{ steps.new_version.outputs.version }}"
132+ TAG_NAME="v$NEW_VERSION"
133+ git tag -a "$TAG_NAME" -m "Release $TAG_NAME"
134+ git push origin "$TAG_NAME"
135+ git push origin main
136+ echo "Created and pushed tag: $TAG_NAME"
137+
138+ - name : Generate release notes
139+ id : release_notes
140+ run : |
141+ NEW_VERSION="${{ steps.new_version.outputs.version }}"
142+ TAG_NAME="v$NEW_VERSION"
143+
144+ # Get the previous tag (if any)
145+ PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "")
146+
147+ if [ -z "$PREVIOUS_TAG" ]; then
148+ echo "## What's New in $TAG_NAME" > release_notes.md
149+ echo "" >> release_notes.md
150+ echo "This is the first tagged release of the Generated Game Experiment!" >> release_notes.md
151+ echo "" >> release_notes.md
152+ echo "### 🎮 Features" >> release_notes.md
153+ echo "- Browser-based side-scrolling platformer game" >> release_notes.md
154+ echo "- Procedural level generation" >> release_notes.md
155+ echo "- Collectibles and power-ups system" >> release_notes.md
156+ echo "- Optional multiplayer support via WebSocket" >> release_notes.md
157+ echo "- Real-time leaderboard" >> release_notes.md
158+ echo "- Mobile-friendly controls" >> release_notes.md
159+ echo "- Docker containerization for easy deployment" >> release_notes.md
160+ echo "" >> release_notes.md
161+ echo "### 🚀 Deployment" >> release_notes.md
162+ echo "- **Play Online:** [GitHub Pages](https://commjoen.github.io/generated-game-experiment/) (Singleplayer)" >> release_notes.md
163+ echo "- **Play Multiplayer:** [Render](https://generated-game-experiment.onrender.com/)" >> release_notes.md
164+ echo "- **Docker:** \`docker pull ghcr.io/commjoen/generated-game-experiment:$NEW_VERSION\`" >> release_notes.md
165+ else
166+ echo "## What's Changed in $TAG_NAME" > release_notes.md
167+ echo "" >> release_notes.md
168+ echo "### 📋 Commits since $PREVIOUS_TAG" >> release_notes.md
169+ git log "$PREVIOUS_TAG..HEAD" --pretty=format:"- %s (%h)" >> release_notes.md
170+ fi
171+
172+ echo "" >> release_notes.md
173+ echo "### 🔧 Technical Details" >> release_notes.md
174+ echo "- **Version:** $NEW_VERSION" >> release_notes.md
175+ echo "- **Node.js:** $(node --version)" >> release_notes.md
176+ echo "- **Built:** $(date -u +"%Y-%m-%d %H:%M:%S UTC")" >> release_notes.md
177+ echo "- **Commit:** ${{ github.sha }}" >> release_notes.md
178+
179+ # Store the release notes content
180+ {
181+ echo 'notes<<EOF'
182+ cat release_notes.md
183+ echo EOF
184+ } >> $GITHUB_OUTPUT
185+
186+ - name : Create GitHub Release
187+ env :
188+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
189+ run : |
190+ NEW_VERSION="${{ steps.new_version.outputs.version }}"
191+ TAG_NAME="v$NEW_VERSION"
192+ PRERELEASE_FLAG=""
193+
194+ if [ "${{ github.event.inputs.prerelease }}" = "true" ]; then
195+ PRERELEASE_FLAG="--prerelease"
196+ fi
197+
198+ gh release create "$TAG_NAME" \
199+ --title "Release $TAG_NAME" \
200+ --notes-file release_notes.md \
201+ $PRERELEASE_FLAG
202+
203+ - name : Generate summary
204+ run : |
205+ NEW_VERSION="${{ steps.new_version.outputs.version }}"
206+ TAG_NAME="v$NEW_VERSION"
207+
208+ echo "## 🎉 Release Created Successfully!" >> $GITHUB_STEP_SUMMARY
209+ echo "" >> $GITHUB_STEP_SUMMARY
210+ echo "**Version:** \`$NEW_VERSION\`" >> $GITHUB_STEP_SUMMARY
211+ echo "**Tag:** \`$TAG_NAME\`" >> $GITHUB_STEP_SUMMARY
212+ echo "**Pre-release:** ${{ github.event.inputs.prerelease }}" >> $GITHUB_STEP_SUMMARY
213+ echo "" >> $GITHUB_STEP_SUMMARY
214+ echo "### 🔗 Links" >> $GITHUB_STEP_SUMMARY
215+ echo "- [Release Page](https://github.com/${{ github.repository }}/releases/tag/$TAG_NAME)" >> $GITHUB_STEP_SUMMARY
216+ echo "- [Docker Image](https://ghcr.io/${{ github.repository }}:$NEW_VERSION)" >> $GITHUB_STEP_SUMMARY
217+ echo "" >> $GITHUB_STEP_SUMMARY
218+ echo "### 🚀 Docker Usage" >> $GITHUB_STEP_SUMMARY
219+ echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
220+ echo "docker pull ghcr.io/${{ github.repository }}:$NEW_VERSION" >> $GITHUB_STEP_SUMMARY
221+ echo "docker run -p 8080:80 -p 3001:3001 ghcr.io/${{ github.repository }}:$NEW_VERSION" >> $GITHUB_STEP_SUMMARY
222+ echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
223+ echo "" >> $GITHUB_STEP_SUMMARY
224+ echo "### ⚡ What happens next" >> $GITHUB_STEP_SUMMARY
225+ echo "- Docker images will be built automatically via existing workflows" >> $GITHUB_STEP_SUMMARY
226+ echo "- Release will be available on GitHub Releases page" >> $GITHUB_STEP_SUMMARY
227+ echo "- Docker Hub release (if configured) will be triggered" >> $GITHUB_STEP_SUMMARY
0 commit comments