generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 4
182 lines (167 loc) · 6.83 KB
/
build.yaml
File metadata and controls
182 lines (167 loc) · 6.83 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
name: CI/CD
on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch: ~
env:
SOURCE_BRANCH: ${{ github.head_ref || github.ref_name }}
RELEASE_BRANCH: "release/${{ github.head_ref || github.ref_name }}"
jobs:
create-release:
name: Build and push artifacts to release branch
runs-on: [ubuntu-latest]
if: ${{ !startsWith(github.head_ref || github.ref_name, 'release/') }}
permissions:
contents: write
steps:
- name: Checkout source branch
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
with:
ref: ${{ env.SOURCE_BRANCH }}
path: source-folder
- name: Setup Git
run: |
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- name: Setup Node (PR Summary)
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
with:
node-version-file: source-folder/.tool-versions
cache: npm
cache-dependency-path: source-folder/pr-summary/package-lock.json
- name: Build (PR Summary)
working-directory: source-folder/pr-summary
run: |
npm install --frozen-lockfile
npm run build
npm prune --omit=dev
- name: Setup Node (PR Review)
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
with:
node-version-file: source-folder/.tool-versions
cache: npm
cache-dependency-path: source-folder/pr-review/package-lock.json
- name: Build (PR Summary)
working-directory: source-folder/pr-review
run: |
npm install --frozen-lockfile
npm run build
npm prune --omit=dev
- name: If necessary, create release branch
working-directory: source-folder
run: |
if ! git fetch origin ${{ env.RELEASE_BRANCH }}; then
git switch --orphan ${{ env.RELEASE_BRANCH }} --discard-changes
git commit --allow-empty -m "Initial commit"
git push origin ${{ env.RELEASE_BRANCH }}
git switch ${{ env.SOURCE_BRANCH }} --discard-changes
fi
- name: Checkout release branch
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
with:
ref: ${{ env.RELEASE_BRANCH }}
path: release-folder
fetch-depth: 0
- name: Prepare fresh release branch
working-directory: source-folder
run: |
rm -rf ${{ github.workspace }}/release-folder/*
mkdir ${{ github.workspace }}/release-folder/pr-summary
mkdir ${{ github.workspace }}/release-folder/pr-review
- name: Copy build output from source branch to release branch (PR Summary)
working-directory: source-folder/pr-summary
run: |
cp action.yml dist ${{ github.workspace }}/release-folder/pr-summary --verbose --recursive
- name: Copy build output from source branch to release branch (PR Review)
working-directory: source-folder/pr-review
run: |
cp action.yml dist ${{ github.workspace }}/release-folder/pr-review --verbose --recursive
- name: Commit and push build artifacts
working-directory: release-folder
run: |
git add -A
git commit -m "${{ github.event.number && format('PR-{0}', github.event.number) || join(github.event.commits.*.message, ', ') }}" || true
git push
testing-summary:
name: Execute the action (PR Summary) defined in this PR
runs-on: [ubuntu-latest]
needs: create-release
if: ${{ github.ref_name != 'main' }}
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout release branch
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
with:
ref: ${{ env.RELEASE_BRANCH }}
- name: Run the AI-assisted action (PR Summary)
uses: ./pr-summary # action.yml is in the pr-summary folder of the release branch
with:
aicore-service-key: ${{ secrets.AICORE_SERVICE_KEY }}
model: o4-mini
exclude-files: package-lock.json
display-mode: comment-delta
testing-review:
name: Execute the action (PR Review) defined in this PR
runs-on: [ubuntu-latest]
needs: create-release
if: ${{ github.ref_name != 'main' }}
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout release branch
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
with:
ref: ${{ env.RELEASE_BRANCH }}
- name: Run the AI-assisted action (PR Review)
uses: ./pr-review # action.yml is in the pr-review folder of the release branch
with:
aicore-service-key: ${{ secrets.AICORE_SERVICE_KEY }}
model: o4-mini
exclude-files: package-lock.json
display-mode: review-comment-delta
update-tags:
name: Update semantic version tags
runs-on: [ubuntu-latest]
needs: create-release
if: ${{ github.ref_name == 'main' }}
permissions:
contents: write
steps:
- name: Checkout release branch
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
with:
ref: ${{ env.RELEASE_BRANCH }}
- name: Create tags for new version
run: |
set -x
: get latest semantic version tag
git fetch --tags
tag_format="^v?([0-9]+)\.([0-9]+)\.([0-9]+)$"
matching_tag_refs=$(git tag --list --sort=-committerdate | grep -E "$tag_format")
tag=$(head -n 1 <<< "$matching_tag_refs")
: stop if current commit is already tagged
[[ $(git rev-parse HEAD) == $(git rev-list -n 1 "$tag") ]] && exit 0
: update the version
[[ $tag =~ $tag_format ]] && major=${BASH_REMATCH[1]} && minor=${BASH_REMATCH[2]} && patch=${BASH_REMATCH[3]}
commit_log=$(git log -1)
commit_subject=$(git log -1 --pretty=%s);
[[ $commit_log == *"[bot]"* ]] && part="patch" || part="minor"
grep -iq "#patch" <<< "$commit_subject" && part="patch"
grep -iq "#minor" <<< "$commit_subject" && part="minor"
grep -iq "#major" <<< "$commit_subject" && part="major"
[[ $part == "major" ]] && major=$((major + 1)) && minor=0 && patch=0
[[ $part == "minor" ]] && minor=$((minor + 1)) && patch=0
[[ $part == "patch" ]] && patch=$((patch + 1))
: create and push a tag with the new semantic version
tag="v$major.$minor.$patch"
git tag -f "$tag"
git push -f origin "$tag"
: create and push a tag with only the major version
tag="v$major"
git tag -f "$tag"
git push -f origin "$tag"