-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (119 loc) · 4.13 KB
/
release.yml
File metadata and controls
142 lines (119 loc) · 4.13 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
name: Release
on:
push:
tags:
- 'v*'
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run full build
run: npm run build
- name: Extract version from tag
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
- name: Verify version in package.json
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
TAG_VERSION="${{ steps.version.outputs.version }}"
if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then
echo "Version mismatch: package.json has $PACKAGE_VERSION but tag is $TAG_VERSION"
exit 1
fi
echo "Version verified: $PACKAGE_VERSION"
- name: Generate changelog for release
id: changelog
run: |
# Extract changelog for this version
if grep -q "## \[${{ steps.version.outputs.version }}\]" CHANGELOG.md; then
# Extract content between this version and the next
awk '/## \[${{ steps.version.outputs.version }}\]/,/## \[/ {
if (/## \[/ && !/## \[${{ steps.version.outputs.version }}\]/) exit;
if (!/## \[${{ steps.version.outputs.version }}\]/) print
}' CHANGELOG.md > release_notes.md
echo "Release notes generated from CHANGELOG.md"
else
echo "No changelog entry found for version ${{ steps.version.outputs.version }}"
echo "## Changes" > release_notes.md
echo "See CHANGELOG.md for details." >> release_notes.md
fi
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release v${{ steps.version.outputs.version }}
body_path: release_notes.md
draft: false
prerelease: ${{ contains(steps.version.outputs.version, '-') }}
docker:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: release
if: success()
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract version
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
ggcode/compiler:latest
ggcode/compiler:v${{ steps.version.outputs.version }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
notify:
name: Notify Release
runs-on: ubuntu-latest
needs: [release, docker]
if: always()
steps:
- name: Extract version
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Notify success
if: needs.release.result == 'success' && needs.docker.result == 'success'
run: |
echo "🎉 Release v${{ steps.version.outputs.version }} completed successfully!"
echo "- GitHub release created"
echo "- Docker image pushed"
- name: Notify failure
if: needs.release.result == 'failure' || needs.docker.result == 'failure'
run: |
echo "❌ Release v${{ steps.version.outputs.version }} failed!"
echo "- Release status: ${{ needs.release.result }}"
echo "- Docker status: ${{ needs.docker.result }}"
exit 1