-
Notifications
You must be signed in to change notification settings - Fork 9
212 lines (184 loc) · 7.42 KB
/
release.yaml
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
name: Release
permissions:
contents: write
on:
workflow_dispatch:
inputs:
dryRun:
description: 'Dry Run'
required: true
type: boolean
default: true
releaseVersion:
description: 'Custom Version (major.minor.patch; leave empty for automatic determination)'
required: true
type: choice
default: 'auto'
options:
- 'auto'
# - 'major'
# - 'minor'
# - 'patch'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
jobs:
summary:
runs-on: ubuntu-latest
steps:
- run: |
echo "DryRun: ${{ inputs.dryRun }}" >> $GITHUB_STEP_SUMMARY
echo "ReleaseVersion: ${{ inputs.releaseVersion }}" >> $GITHUB_STEP_SUMMARY
echo "Branch: ${{ github.ref }}" >> $GITHUB_STEP_SUMMARY
analyse-changed-services:
uses: ./.github/workflows/get-changed-services.yaml
release:
needs: [analyse-changed-services]
runs-on: ubuntu-latest
if: ${{ needs.analyse-changed-services.outputs.CHANGED_PACKAGES != '[]' && needs.analyse-changed-services.outputs.CHANGED_PACKAGES != ''}}
strategy:
fail-fast: false
max-parallel: 1
matrix:
package: ${{fromJson(needs.analyse-changed-services.outputs.CHANGED_PACKAGES)}}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
ref:
fetch-depth: 0
token: ${{ secrets.PAT }} # use PAT to being able to push to protected branch later on
- name: Checkout latest default branch
run: |
git checkout ${{ github.event.repository.default_branch }}
git pull origin ${{ github.event.repository.default_branch }}
if: ${{ contains(github.ref, github.event.repository.default_branch) }}
- uses: pnpm/action-setup@v3
with:
version: 8
run_install: false
- run: echo "package=${{ matrix.package }}"
- name: Get pnpm store directory
id: pnpm-store
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-store.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: get directory for package
id: get-directory
run: |
directory=$(pnpm ls -r --json --filter $MATRIX_PACKAGE --changed-files-ignore-pattern="**/(garden.yml|.dockerignore)" | jq -r '.[0] | .path')
directory="${directory##*/democracy-development/}"
# Ausgabe
echo "directory=$directory" >> $GITHUB_OUTPUT
echo "directory=$directory"
env:
MATRIX_PACKAGE: ${{ matrix.package }}
- name: Fetch tags
run: git fetch --tags
- name: Configure CI Git User
run: |
git config user.name "Manuel Ruck"
git config user.email "[email protected]"
git config push.followTags true
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/$GITHUB_REPOSITORY
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
- name: Get changelog
id: get_changelog
run: |
changelog=''
if ( ${{ inputs.releaseVersion == 'auto' }} ); then
changelog=`pnpm dlx commit-and-tag-version --path . -t $MATRIX_PACKAGE@v --dry-run | sed -n '/^---$/,/^---$/p' | grep -v '^---$'`
else
changelog=`pnpm dlx commit-and-tag-version --path . -t $MATRIX_PACKAGE@v --release-as '${{ inputs.releaseVersion }}' --dry-run | sed -n '/^---$/,/^---$/p' | grep -v '^---$'`
fi
echo "$changelog"
echo "$changelog" >> $GITHUB_STEP_SUMMARY
echo "$changelog" >> /tmp/CHANGELOG.md
{
echo 'CHANGELOG<<EOF'
echo $changelog
echo EOF
} >> "$GITHUB_ENV"
echo 'CHANGELOG<<EOF' >> $GITHUB_ENV
echo $changelog >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
working-directory: ${{ steps.get-directory.outputs.directory }}
env:
MATRIX_PACKAGE: ${{ matrix.package }}
- name: Determine next version number
if: inputs.releaseVersion == 'auto'
id: determine_next_version
run: |
nextVersion=`pnpm dlx commit-and-tag-version --path . -t $MATRIX_PACKAGE@v --dry-run | sed -n '/^---$/,/^---$/p' | grep -P -o '(\d+\.)(\d+\.)(\d+)' | head -n 1`
echo "$nextVersion"
echo "NEXT_VERSION=$nextVersion" >> $GITHUB_OUTPUT
working-directory: ${{ steps.get-directory.outputs.directory }}
env:
MATRIX_PACKAGE: ${{ matrix.package }}
# - name: Manually next version number
# if: inputs.releaseVersion != 'auto'
# run: |
# echo "NEXT_VERSION=${{ inputs.releaseVersion }}" >> $GITHUB_ENV
# echo "$NEXT_VERSION"
- name: bump version - DRY RUN
if: inputs.dryRun == true
run: |
if ( ${{ inputs.releaseVersion == 'auto' }} ); then
pnpm dlx commit-and-tag-version --path . -t $MATRIX_PACKAGE@v --dry-run
else
pnpm dlx commit-and-tag-version --path . -t $MATRIX_PACKAGE@v --release-as '${{ inputs.releaseVersion }}' --dry-run
fi
working-directory: ${{ steps.get-directory.outputs.directory }}
env:
MATRIX_PACKAGE: ${{ matrix.package }}
- name: bump version - AUTOMATIC
if: inputs.dryRun == false && inputs.releaseVersion == 'auto'
run: pnpm dlx commit-and-tag-version --path . -t $MATRIX_PACKAGE@v
working-directory: ${{ steps.get-directory.outputs.directory }}
env:
MATRIX_PACKAGE: ${{ matrix.package }}
# - name: bump version - MANUAL VERSION NO.
# if: inputs.dryRun == false && inputs.releaseVersion != 'auto'
# run: pnpm dlx commit-and-tag-version --path . -t $MATRIX_PACKAGE@v --release-as '${{ inputs.releaseVersion }}'
# working-directory: ${{ steps.get-directory.outputs.directory }}
# env:
# MATRIX_PACKAGE: ${{ matrix.package }}
- name: Publish tag # only possible on default branch
if: inputs.dryRun == false
run: |
if ( ${{ contains(github.ref, github.event.repository.default_branch) }} ); then
git push --follow-tags origin ${{ github.event.repository.default_branch }}
else
exit 1
fi
- name: Create release
uses: actions/github-script@v7
if: inputs.dryRun == false
env:
TAG: ${{ matrix.package }}@v${{ steps.determine_next_version.outputs.NEXT_VERSION }}
with:
github-token: '${{ secrets.GITHUB_TOKEN }}'
script: |
const fs = require('fs');
const { TAG } = process.env;
const body = fs.readFileSync('/tmp/CHANGELOG.md', 'utf8');
try {
const response = await github.rest.repos.createRelease({
draft: false,
generate_release_notes: false,
name: `${TAG}`,
owner: context.repo.owner,
prerelease: false,
repo: context.repo.repo,
tag_name: `${TAG}`,
body: body.replace('\n', '<br />'),
});
} catch (error) {
core.setFailed(error.message);
}