-
Notifications
You must be signed in to change notification settings - Fork 0
205 lines (173 loc) · 6.92 KB
/
Copy pathrelease.yml
File metadata and controls
205 lines (173 loc) · 6.92 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
name: Release
on:
push:
branches: [ main ]
workflow_dispatch:
permissions:
contents: write
packages: write
env:
REGISTRY: ghcr.io
jobs:
release:
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.bump.outputs.new_version }}
new_tag: ${{ steps.bump.outputs.new_tag }}
should_release: ${{ steps.bump.outputs.should_release }}
steps:
- name: Generate release bot token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.RELEASE_APP_ID }}
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- name: Get previous tag
id: prev_tag
run: |
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
echo "tag=$PREV_TAG" >> $GITHUB_OUTPUT
- name: Determine version bump
id: bump
run: |
if [ -z "${{ steps.prev_tag.outputs.tag }}" ]; then
# No previous tag, start from version in build.gradle
CURRENT=$(grep "^version = " build.gradle | sed 's/version = "\([^"]*\)".*/\1/')
echo "new_version=$CURRENT" >> $GITHUB_OUTPUT
echo "new_tag=v$CURRENT" >> $GITHUB_OUTPUT
echo "should_release=true" >> $GITHUB_OUTPUT
exit 0
fi
# Get full commit messages (subject + body) since last tag
# This catches conventional commits in squash-merge bodies
COMMITS=$(git log ${{ steps.prev_tag.outputs.tag }}..HEAD --pretty=format:"%B")
if [ -z "$COMMITS" ]; then
echo "should_release=false" >> $GITHUB_OUTPUT
exit 0
fi
# Determine bump type based on conventional commits
# Patterns allow optional "* " or "- " prefix for squash-merge bullet points
if echo "$COMMITS" | grep -qE "^(\* |- )?feat(\(.+\))?!:|^(\* |- )?fix(\(.+\))?!:|BREAKING CHANGE:"; then
BUMP_TYPE="major"
elif echo "$COMMITS" | grep -qE "^(\* |- )?feat(\(.+\))?:"; then
BUMP_TYPE="minor"
elif echo "$COMMITS" | grep -qE "^(\* |- )?fix(\(.+\))?:"; then
BUMP_TYPE="patch"
else
echo "should_release=false" >> $GITHUB_OUTPUT
exit 0
fi
# Parse version (remove 'v' prefix if present)
VERSION=${{ steps.prev_tag.outputs.tag }}
VERSION=${VERSION#v}
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
case $BUMP_TYPE in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
esac
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "new_tag=v$NEW_VERSION" >> $GITHUB_OUTPUT
echo "should_release=true" >> $GITHUB_OUTPUT
- name: Generate changelog
id: changelog
if: steps.bump.outputs.should_release == 'true'
run: |
PREV_TAG="${{ steps.prev_tag.outputs.tag }}"
if [ -n "$PREV_TAG" ]; then
CHANGELOG=$(git log $PREV_TAG..HEAD --pretty=format:"* %s (%h)" | head -50)
else
CHANGELOG=$(git log --pretty=format:"* %s (%h)" | head -20)
fi
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "content<<$EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
- name: Update version in build.gradle
if: steps.bump.outputs.should_release == 'true'
run: |
VERSION="${{ steps.bump.outputs.new_version }}"
sed -i "s/^version = \".*\"/version = \"$VERSION\"/" build.gradle
echo "Updated build.gradle to version $VERSION"
grep "^version = " build.gradle
- name: Commit build.gradle, create tag, and push both to git
if: steps.bump.outputs.should_release == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add build.gradle
git commit -m "Update build.gradle version to ${{ steps.bump.outputs.new_version }}"
git tag -a ${{ steps.bump.outputs.new_tag }} -m "Release ${{ steps.bump.outputs.new_version }}"
git push origin HEAD ${{ steps.bump.outputs.new_tag }}
- name: Create GitHub Release
if: steps.bump.outputs.should_release == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.bump.outputs.new_tag }}
name: ${{ steps.bump.outputs.new_tag }}
body: |
## What's Changed
${{ steps.changelog.outputs.content }}
**Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ steps.prev_tag.outputs.tag }}...${{ steps.bump.outputs.new_tag }}
docker:
needs: release
if: needs.release.outputs.should_release == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ needs.release.outputs.new_tag }}
- name: Set image name to lowercase
id: image
run: echo "name=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT
- name: Set up Java 25
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '25'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Generate Dockerfile and build context
run: ./gradlew buildLayers dockerfile
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- 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: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: build/docker/main
push: true
platforms: linux/amd64,linux/arm64
tags: |
${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:${{ needs.release.outputs.new_version }}
${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:${{ needs.release.outputs.new_tag }}
${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:latest
- name: Trigger RavenEye deployment
run: |
echo '{"event_type":"deploy","client_payload":{"service":"app"}}' | \
gh api repos/RunnymedeRobotics1310/RavenEye/dispatches --input -
env:
GH_TOKEN: ${{ secrets.RAVENEYE_DISPATCH_TOKEN }}