-
Notifications
You must be signed in to change notification settings - Fork 0
199 lines (169 loc) · 8.98 KB
/
version-and-build.yml
File metadata and controls
199 lines (169 loc) · 8.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
name: Auto Update Version and Build
on:
push:
branches:
- master
- main
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
update-version-and-build:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
# Skip if the commit message contains the auto-increment marker to prevent infinite loops
if: "!contains(github.event.head_commit.message, '🤖 Auto-increment version')"
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Update versions using comprehensive management script
id: version_update
run: |
# Make script executable
chmod +x .github/scripts/manage-versions.js
# Run the comprehensive version management script
node .github/scripts/manage-versions.js
# Display updated files
echo "Updated projectData.ts:"
cat apps/web/projectData.ts
echo ""
echo "Updated version.json:"
cat version.json
- name: Check for changes
id: git_status
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "changes=true" >> $GITHUB_OUTPUT
else
echo "changes=false" >> $GITHUB_OUTPUT
fi
- name: Commit version changes
if: steps.git_status.outputs.changes == 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Add all changed files
git add apps/web/projectData.ts version.json
# Add version file if it was created
if [ -n "${{ steps.version_update.outputs.version_file }}" ]; then
git add "Versions/${{ steps.version_update.outputs.version_file }}"
fi
git commit -m "🤖 Auto-increment version to ${{ steps.version_update.outputs.new_version }} (prod: ${{ steps.version_update.outputs.prod_version }}, dev: ${{ steps.version_update.outputs.dev_version }})"
git push
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest
type=raw,value=${{ steps.version_update.outputs.new_version }}
type=raw,value=${{ steps.version_update.outputs.prod_version }},enable={{isBranch 'master'}}
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=sha,prefix=
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Create version branch (stable releases only)
if: steps.git_status.outputs.changes == 'true' && steps.version_update.outputs.is_stable == 'true' && steps.version_update.outputs.is_master == 'true'
run: |
# Create a new branch for this stable version
git checkout -b "release/v${{ steps.version_update.outputs.new_version }}"
git push origin "release/v${{ steps.version_update.outputs.new_version }}"
# Switch back to main branch
git checkout ${{ github.ref_name }}
- name: Generate release notes (stable releases only)
if: steps.git_status.outputs.changes == 'true' && steps.version_update.outputs.is_stable == 'true' && steps.version_update.outputs.is_master == 'true'
id: release_notes
run: |
# Make script executable
chmod +x .github/scripts/generate-release-notes.js
# Generate release notes using the script
node .github/scripts/generate-release-notes.js "${{ steps.version_update.outputs.new_version }}"
- name: Create Git Tag (stable releases only)
if: steps.git_status.outputs.changes == 'true' && steps.version_update.outputs.is_stable == 'true' && steps.version_update.outputs.is_master == 'true'
run: |
git tag v${{ steps.version_update.outputs.new_version }}
git push origin v${{ steps.version_update.outputs.new_version }}
- name: Create GitHub Release (stable releases only)
if: steps.git_status.outputs.changes == 'true' && steps.version_update.outputs.is_stable == 'true' && steps.version_update.outputs.is_master == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Use version file if created, otherwise use generated release notes
if [ -f "Versions/${{ steps.version_update.outputs.version_file }}" ]; then
NOTES_FILE="Versions/${{ steps.version_update.outputs.version_file }}"
else
NOTES_FILE="release-notes.md"
fi
# Create release using GitHub CLI
gh release create v${{ steps.version_update.outputs.new_version }} \
--title "Release v${{ steps.version_update.outputs.new_version }}" \
--notes-file "$NOTES_FILE" \
--latest
- name: Output summary
run: |
echo "## 🚀 Comprehensive Version Update & Build Summary" >> $GITHUB_STEP_SUMMARY
echo "- **Previous version:** ${{ steps.version_update.outputs.previous_version }}" >> $GITHUB_STEP_SUMMARY
echo "- **New version:** ${{ steps.version_update.outputs.new_version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Production version:** ${{ steps.version_update.outputs.prod_version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Development version:** ${{ steps.version_update.outputs.dev_version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Branch:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
echo "- **Stable release:** ${{ steps.version_update.outputs.is_stable }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 🐳 Docker Images Built" >> $GITHUB_STEP_SUMMARY
echo "- \`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest\`" >> $GITHUB_STEP_SUMMARY
echo "- \`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version_update.outputs.new_version }}\`" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.version_update.outputs.is_master }}" == "true" ]; then
echo "- \`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version_update.outputs.prod_version }}\`" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 📁 Files Updated" >> $GITHUB_STEP_SUMMARY
echo "- \`apps/web/projectData.ts\` - Updated to ${{ steps.version_update.outputs.new_version }}" >> $GITHUB_STEP_SUMMARY
echo "- \`version.json\` - prod: ${{ steps.version_update.outputs.prod_version }}, dev: ${{ steps.version_update.outputs.dev_version }}" >> $GITHUB_STEP_SUMMARY
if [ -n "${{ steps.version_update.outputs.version_file }}" ]; then
echo "- \`Versions/${{ steps.version_update.outputs.version_file }}\` - New version file created" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.version_update.outputs.is_stable }}" == "true" ] && [ "${{ steps.version_update.outputs.is_master }}" == "true" ]; then
echo "### 🏷️ Release Created" >> $GITHUB_STEP_SUMMARY
echo "- **Tag:** \`v${{ steps.version_update.outputs.new_version }}\`" >> $GITHUB_STEP_SUMMARY
echo "- **Branch:** \`release/v${{ steps.version_update.outputs.new_version }}\`" >> $GITHUB_STEP_SUMMARY
echo "- **Release:** [v${{ steps.version_update.outputs.new_version }}](https://github.com/${{ github.repository }}/releases/tag/v${{ steps.version_update.outputs.new_version }})" >> $GITHUB_STEP_SUMMARY
if [ -n "${{ steps.version_update.outputs.version_file }}" ]; then
echo "- **Version File:** \`Versions/${{ steps.version_update.outputs.version_file }}\`" >> $GITHUB_STEP_SUMMARY
fi
else
echo "### ⚠️ Development Build" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.version_update.outputs.is_master }}" != "true" ]; then
echo "This is a development branch build. No GitHub release or version branch created." >> $GITHUB_STEP_SUMMARY
else
echo "This is a pre-release version (contains alpha, beta, canary, etc.). No GitHub release or version branch created." >> $GITHUB_STEP_SUMMARY
fi
fi