-
Notifications
You must be signed in to change notification settings - Fork 0
228 lines (193 loc) Β· 6.83 KB
/
deploy-render.yml
File metadata and controls
228 lines (193 loc) Β· 6.83 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
name: Deploy to Render
# Only deploy on push to main branch
on:
push:
tags:
- 'v*'
workflow_dispatch: # Allow manual deployment
concurrency:
group: deploy-production
cancel-in-progress: false # Don't cancel deployments
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
# ----------------------------------
# Job 1: Build and Push Docker Image
# ----------------------------------
build:
name: Build Production Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest
- name: Build and push production image
uses: docker/build-push-action@v5
with:
context: .
target: production
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64
# ----------------------------------
# Job 2: Deploy to Render
# ----------------------------------
deploy:
name: Deploy to Render
runs-on: ubuntu-latest
needs: build
if: vars.RENDER_CONFIGURED == 'true'
environment:
name: production
url: ${{ steps.deploy.outputs.url }}
steps:
- name: Extract version from tag
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Trigger Render deployment
id: deploy
run: |
echo "π Deploying version ${{ steps.version.outputs.version }} to Render..."
# Trigger Render deploy hook
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "${{ secrets.RENDER_DEPLOY_HOOK_URL }}")
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
if [ "$HTTP_CODE" -eq 200 ] || [ "$HTTP_CODE" -eq 201 ]; then
echo "β
Deployment triggered successfully"
else
echo "β Deployment trigger failed with HTTP $HTTP_CODE"
exit 1
fi
- name: Wait for deployment
run: |
echo "β³ Waiting for deployment to complete..."
echo "Version: ${{ steps.version.outputs.version }}"
echo "Check status at: https://dashboard.render.com"
sleep 10
- name: Verify deployment
run: |
echo "π Verifying deployment..."
# Wait a bit more for deployment to be fully live
sleep 30
# Check if the app is accessible
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" https://angular-starter-project.onrender.com)
if [ "$HTTP_CODE" = "200" ]; then
echo "β
Deployment verified! App is live."
else
echo "β οΈ App returned HTTP $HTTP_CODE"
echo "Check Render dashboard for details"
fi
- name: Deployment summary
if: always()
run: |
if [ "${{ job.status }}" = "success" ]; then
echo "π Deployment completed successfully!"
echo ""
echo "π Deployment Details:"
echo " Version: ${{ steps.version.outputs.version }}"
echo " Environment: Production"
echo " Platform: Render"
echo " Status: Live β
"
echo ""
echo "π Access your app:"
echo " https://angular-starter-project.onrender.com"
else
echo "β Deployment failed"
echo "Check Render logs for details"
fi
# ----------------------------------
# Job 3: Create GitHub Release
# ----------------------------------
github-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: deploy
if: success()
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract version
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Generate release notes
id: release_notes
run: |
VERSION=${{ steps.version.outputs.version }}
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
# Extract changelog for this version
CHANGELOG=$(sed -n "/## \[$VERSION\]/,/## \[/p" CHANGELOG.md | sed '$d' | tail -n +2)
# If changelog is empty, use commit messages
if [ -z "$CHANGELOG" ]; then
if [ -n "$PREV_TAG" ]; then
CHANGELOG=$(git log $PREV_TAG..HEAD --pretty=format:"* %s" --no-merges)
else
CHANGELOG=$(git log HEAD --pretty=format:"* %s" --no-merges | head -10)
fi
fi
# Build release notes
cat > release_notes.md << EOF
## π What's New
$CHANGELOG
## π¦ Quick Start
### Using as Template
\`\`\`bash
npx degit victorbruce/angular-starter-project my-project
cd my-project
./setup.sh my-project
docker-compose up
\`\`\`
### Clone Repository
\`\`\`bash
git clone https://github.com/victorbruce/angular-starter-project.git
cd angular-starter-project
docker-compose up
\`\`\`
## π Resources
- π **Live Demo**: https://angular-starter-project.onrender.com
- π **Documentation**: [README.md](https://github.com/${{ github.repository }}#readme)
- π **Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...v${VERSION}
- π **Report Issues**: [GitHub Issues](https://github.com/${{ github.repository }}/issues)
---
**Docker Image**: \`ghcr.io/${{ github.repository }}:${VERSION}\`
EOF
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ steps.version.outputs.version }}
body_path: release_notes.md
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}