-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (122 loc) · 4.43 KB
/
release-frontend-app-generic.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
on:
workflow_call:
inputs:
releaseVersion:
description: 'Release version (format: vX.X)'
required: true
type: string
commitSha:
description: 'SHA of the commit to release from'
required: true
type: string
dockerImage:
description: 'Name of the Docker image (e.g., organization/app-name)'
required: true
type: string
dockerUsername:
required: true
type: string
githubappId:
description: 'GitHub App ID for authentication'
required: true
type: string
secrets:
githubappPrivateKey:
required: true
docker-token:
required: true
sonar-token:
required: true
env:
NODE_OPTIONS: '--max_old_space_size=4096'
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Generate GitHub App Token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ inputs.githubappId }}
private-key: ${{ secrets.githubappPrivateKey }}
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org
- name: Extract Version Numbers
run: |
if ! [[ ${{ inputs.releaseVersion }} =~ ^v([0-9]+)\.([0-9]+)$ ]]; then
echo "Error: Invalid version format. Must be vX.X (e.g., v1.2)"
exit 1
fi
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
echo "RELEASE_MAJOR_VERSION=${MAJOR}" >> $GITHUB_ENV
echo "RELEASE_MINOR_VERSION=${MINOR}" >> $GITHUB_ENV
echo "RELEASE_VERSION=${MAJOR}.${MINOR}.0" >> $GITHUB_ENV
echo "RELEASE_BRANCH=release-v${MAJOR}.${MINOR}" >> $GITHUB_ENV
- name: Create Release Branch
run: git checkout -b ${{ env.RELEASE_BRANCH }} ${{ inputs.commitSha }}
- name: Update Version and Tag
run: |
# Configure git for commits
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
# Use npm version to update version, create commit and tag
npm version ${{ env.RELEASE_VERSION }}
- name: Install Dependencies
run: npm ci
- name: Quality Checks
run: |
npm run lint
npm run test:coverage
npm run licenses-check
- name: Build Application
run: npm run build
- name: SonarCloud Analysis
uses: SonarSource/[email protected]
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
SONAR_TOKEN: ${{ secrets.sonar-token }}
- name: Build and publish Docker image
uses: elgohr/Publish-Docker-Github-Action@33a481be3e179353cb7793a92b57cf9a6c985860 # v4
with:
name: ${{ inputs.dockerImage }}
username: ${{ inputs.dockerUsername }}
password: ${{ secrets.docker-token }}
tags: ${{ env.RELEASE_VERSION }}
- name: Push release branch and tag
run: |
git push origin ${{ env.RELEASE_BRANCH }}
git push origin v${{ env.RELEASE_VERSION }}
- name: Checkout main
run: |
git checkout main
git pull
- name: Get current package version
run: echo "CURRENT_NPM_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
- name: Extract current version
run: |
regex="(.*)-SNAPSHOT"
if [[ ${{ env.CURRENT_NPM_VERSION }} =~ $regex ]];
then
echo "CURRENT_RELEASE_VERSION=${BASH_REMATCH[1]}" >> $GITHUB_ENV
fi
- name: Update SNAPSHOT version on main
if: env.CURRENT_RELEASE_VERSION == env.RELEASE_VERSION
run: |
# Calculate next development version
NEW_MINOR=$((RELEASE_MINOR_VERSION + 1))
DEV_VERSION="${RELEASE_MAJOR_VERSION}.${NEW_MINOR}.0-SNAPSHOT"
# Update package.json with development version
npm version ${DEV_VERSION} --no-git-tag-version
# Commit and push changes
git add .
git commit -m "Bump version to v${DEV_VERSION}"
git push origin main