-
Notifications
You must be signed in to change notification settings - Fork 0
166 lines (139 loc) · 7.12 KB
/
version-and-build.yml
File metadata and controls
166 lines (139 loc) · 7.12 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
name: Auto Update Version and Build
on:
pull_request:
types: [opened, synchronize, reopened]
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
# Only run for collaborators or repository owner
if: |
github.event.pull_request.author_association == 'OWNER' ||
github.event.pull_request.author_association == 'COLLABORATOR' ||
github.event.pull_request.author_association == 'MEMBER'
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 (PR only - no push)
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 }})"
# Note: Not pushing changes in PR context - they will be available for review
- 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=pr-${{ github.event.number }}
type=raw,value=${{ steps.version_update.outputs.new_version }}-pr-${{ github.event.number }}
type=ref,event=pr
type=sha,prefix=pr-${{ github.event.number }}-
- 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: Add PR comment with build info
uses: actions/github-script@v7
with:
script: |
const comment = `## 🚀 CI/CD Build Summary for PR #${{ github.event.number }}
**Build Status:** ✅ Success
**Version:** ${{ steps.version_update.outputs.new_version }}
**Docker Images Built:**
- \`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pr-${{ github.event.number }}\`
- \`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version_update.outputs.new_version }}-pr-${{ github.event.number }}\`
**Files Updated:**
- \`apps/web/projectData.ts\` - Updated to ${{ steps.version_update.outputs.new_version }}
- \`version.json\` - prod: ${{ steps.version_update.outputs.prod_version }}, dev: ${{ steps.version_update.outputs.dev_version }}
${steps.version_update.outputs.version_file ? `- \`Versions/${{ steps.version_update.outputs.version_file }}\` - New version file created` : ''}
> **Note:** This is a PR build. No releases or version branches will be created until the PR is merged.`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
- name: Output summary
run: |
echo "## 🚀 PR Build Summary for #${{ github.event.number }}" >> $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 "- **PR Author:** ${{ github.event.pull_request.user.login }}" >> $GITHUB_STEP_SUMMARY
echo "- **Author Association:** ${{ github.event.pull_request.author_association }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 🐳 Docker Images Built" >> $GITHUB_STEP_SUMMARY
echo "- \`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pr-${{ github.event.number }}\`" >> $GITHUB_STEP_SUMMARY
echo "- \`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version_update.outputs.new_version }}-pr-${{ github.event.number }}\`" >> $GITHUB_STEP_SUMMARY
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
echo "### ℹ️ PR Build Notes" >> $GITHUB_STEP_SUMMARY
echo "This is a pull request build. No releases, tags, or version branches will be created." >> $GITHUB_STEP_SUMMARY
echo "Version changes are committed locally for review but not pushed to the repository." >> $GITHUB_STEP_SUMMARY
echo "Once the PR is merged, you may want to run a separate workflow for production deployments." >> $GITHUB_STEP_SUMMARY