-
Notifications
You must be signed in to change notification settings - Fork 0
182 lines (161 loc) · 7.19 KB
/
release.yml
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
name: Create Release
on:
workflow_run:
workflows: ["frontera"]
types:
- completed
env:
REGISTRY: ghcr.io
FRONTERA_PROD_IMAGE_NAME: ${{ github.repository }}/prod
DOCKER_BUILDKIT: 1
permissions:
contents: write
packages: write
jobs:
create-release:
runs-on: ubicloud-standard-2
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed to fetch all tags
- name: Get latest tag
id: get_latest_tag
run: |
# Get the latest tag, default to v0.0.0 if no tags exist
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "latest_tag=${latest_tag}" >> $GITHUB_OUTPUT
- name: Get version info from commits
id: commit_message
run: |
# Get the merge commit message
merge_msg=$(git log -1 --pretty=format:"%s")
echo "Merge message: $merge_msg"
# If this is a merge commit, get the PR commits
if [[ "$merge_msg" == "Merge pull request"* ]]; then
# Get just the commits from this PR (between HEAD and where PR branched)
pr_commits=$(git log HEAD^2 --not HEAD^ --pretty=format:"%s")
echo "PR commits:"
echo "$pr_commits"
# Check for version prefixes in PR commits
if echo "$pr_commits" | grep -q "^major:"; then
echo "Found major version commit"
echo "version_bump=major" >> $GITHUB_OUTPUT
elif echo "$pr_commits" | grep -q "^minor:"; then
echo "Found minor version commit"
echo "version_bump=minor" >> $GITHUB_OUTPUT
elif echo "$pr_commits" | grep -q "^patch:"; then
echo "Found patch version commit"
echo "version_bump=patch" >> $GITHUB_OUTPUT
else
echo "No version prefix found, skipping release"
echo "version_bump=skip" >> $GITHUB_OUTPUT
fi
else
# Direct commit to branch - same logic
if [[ "$merge_msg" =~ ^major: ]]; then
echo "Found major version commit"
echo "version_bump=major" >> $GITHUB_OUTPUT
elif [[ "$merge_msg" =~ ^minor: ]]; then
echo "Found minor version commit"
echo "version_bump=minor" >> $GITHUB_OUTPUT
elif [[ "$merge_msg" =~ ^patch: ]]; then
echo "Found patch version commit"
echo "version_bump=patch" >> $GITHUB_OUTPUT
else
echo "No version prefix found, skipping release"
echo "version_bump=skip" >> $GITHUB_OUTPUT
fi
fi
- name: Generate next version
id: generate_version
if: steps.commit_message.outputs.version_bump != 'skip'
run: |
latest_tag=${{ steps.get_latest_tag.outputs.latest_tag }}
version_bump="${{ steps.commit_message.outputs.version_bump }}"
# Debug output
echo "Latest tag: $latest_tag"
echo "Version bump type: $version_bump"
# Extract version numbers
major=$(echo $latest_tag | sed 's/v\([0-9]*\).\([0-9]*\).\([0-9]*\)/\1/')
minor=$(echo $latest_tag | sed 's/v\([0-9]*\).\([0-9]*\).\([0-9]*\)/\2/')
patch=$(echo $latest_tag | sed 's/v\([0-9]*\).\([0-9]*\).\([0-9]*\)/\3/')
echo "Current version: major=$major minor=$minor patch=$patch"
# Increment version based on bump type
case "$version_bump" in
"major")
echo "Performing major version bump"
new_major=$((major + 1))
next_version="v${new_major}.0.0"
;;
"minor")
echo "Performing minor version bump"
new_minor=$((minor + 1))
next_version="v${major}.${new_minor}.0"
;;
"patch")
echo "Performing patch version bump"
new_patch=$((patch + 1))
next_version="v${major}.${minor}.${new_patch}"
;;
esac
echo "Next version will be: $next_version"
echo "next_version=${next_version}" >> $GITHUB_OUTPUT
echo "should_release=true" >> $GITHUB_OUTPUT
- name: Create Release
if: steps.commit_message.outputs.version_bump != 'skip' && steps.generate_version.outputs.should_release == 'true'
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.generate_version.outputs.next_version }}
generate_release_notes: true
token: ${{ secrets.GITHUB_TOKEN }}
# Docker build and push steps start here
- name: Delete huge unnecessary tools folder
if: steps.generate_version.outputs.should_release == 'true'
run: rm -rf /opt/hostedtoolcache
- name: Set up Docker Buildx
if: steps.generate_version.outputs.should_release == 'true'
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
network=host
- uses: ubicloud/setup-node@v4
if: steps.generate_version.outputs.should_release == 'true'
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: './package-lock.json'
- name: Log in to the Container registry
if: steps.generate_version.outputs.should_release == 'true'
uses: docker/login-action@v3.3.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.REPOSITORY_READ_WRITE_USERNAME }}
password: ${{ secrets.REPOSITORY_READ_WRITE_TOKEN }}
# Build and push production image with the new version tag
- name: Build and push production image
if: steps.generate_version.outputs.should_release == 'true'
uses: docker/build-push-action@v6.13.0
with:
push: true
tags: ${{ env.REGISTRY }}/${{ env.FRONTERA_PROD_IMAGE_NAME }}:${{ steps.generate_version.outputs.next_version }}
cache-from: |
type=gha,scope=frontera-build
type=gha,scope=frontera-build-${{ github.job }}
cache-to: |
type=gha,mode=max,scope=frontera-build-${{ github.job }}
build-args: |
"VITE_MIDDLEWARE_API_URL=${{ secrets.PROD_VITE_MIDDLEWARE_API_URL }}"
"VITE_CLIENT_APP_URL=${{ secrets.PROD_VITE_CLIENT_APP_URL }}"
"VITE_REALTIME_WS_PATH=${{ secrets.PROD_VITE_REALTIME_WS_PATH }}"
"VITE_REALTIME_WS_API_KEY=${{ secrets.PROD_VITE_REALTIME_WS_API_KEY }}"
"VITE_STRIPE_PUBLIC_KEY=${{ secrets.PROD_VITE_STRIPE_PUBLIC_KEY }}"
# Trigger Frontera App Workflow after Docker build is complete
- name: Trigger Frontera App Workflow
if: steps.commit_message.outputs.version_bump != 'skip' && steps.generate_version.outputs.should_release == 'true'
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.FE_TESTS_GITHUB_TOKEN }}
repository: customeros/cloud
event-type: deploy-frontera-app
client-payload: '{"version": "${{ steps.generate_version.outputs.next_version }}"}'