generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
224 lines (204 loc) · 8.17 KB
/
build-and-test.yml
File metadata and controls
224 lines (204 loc) · 8.17 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
name: Build & Test
on:
pull_request:
branches:
- main
types:
- opened
- synchronize
- reopened
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
build-dist:
runs-on: [ubuntu-latest]
permissions:
contents: write
pull-requests: write
outputs:
committed_sha: ${{ steps.commit_dist.outputs.commit_sha }}
steps:
- name: Checkout PR head
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref || github.ref_name }}
token: ${{ secrets.GITHUB_TOKEN}}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20 # use stable LTS; previous 24 caused manifest warning
check-latest: true
- name: Install dependencies
working-directory: .github/actions/core
run: npm ci
- name: Run tests
working-directory: .github/actions/core
run: npm run test
- name: Build action
working-directory: .github/actions/core
run: npm run build
- name: Commit build artifacts (same-repo PRs only)
if: github.event.pull_request.head.repo.full_name == github.repository
id: commit_dist
uses: EndBug/add-and-commit@v9
with:
add: "."
message: "chore: build core action dist (auto)"
default_author: github_actions
push: true
- name: Fail if dist is dirty (Forked PRs only)
if: github.event.pull_request.head.repo.full_name != github.repository
working-directory: .github/actions/core
run: |
if [[ -n $(git status --porcelain dist) ]]; then
echo "::error::The 'dist' folder is out of sync with the source code."
echo "::error::Because this is a forked PR, we cannot automatically commit the changes."
echo "::error::Please run 'npm run build' in '.github/actions/core' locally and commit the changes."
exit 1
fi
test-python:
needs: build-dist
runs-on: [ubuntu-latest]
permissions:
contents: write
pull-requests: read
steps:
- uses: actions/checkout@v4
- name: Patch composite actions for E2E
run: |
sed -i -E 's|sap/pull-request-semver-bumper/.github/actions/core@[^[:space:]"]+|./.github/actions/core|g' .github/actions/version-bumping/*/action.yml
sed -i -E 's|sap/pull-request-semver-bumper/.github/actions/version-bumping/python@[^[:space:]"]+|./.github/actions/version-bumping/python|g' action.yml
- name: Test Python Action (Dry Run)
id: version_bump
uses: ./
with:
type: python
token: ${{ secrets.GITHUB_TOKEN }}
pyproject-file: "test-resources/pyproject.toml"
dry-run: "true"
- name: Verify Outputs
run: |
echo "Bumped: ${{ steps.version_bump.outputs.bumped }}"
echo "New Version: ${{ steps.version_bump.outputs.new-version }}"
echo "### Python Test New Version: ${{ steps.version_bump.outputs.new-version }}" >> $GITHUB_STEP_SUMMARY
if [ -z "${{ steps.version_bump.outputs.bumped }}" ]; then
echo "Error: 'bumped' output is empty"
exit 1
fi
test-npm:
needs: build-dist
runs-on: [ubuntu-latest]
permissions:
contents: write
pull-requests: read
steps:
- uses: actions/checkout@v4
- name: Patch composite actions for E2E
run: |
sed -i -E 's|sap/pull-request-semver-bumper/.github/actions/core@[^[:space:]"]+|./.github/actions/core|g' .github/actions/version-bumping/*/action.yml
sed -i -E 's|sap/pull-request-semver-bumper/.github/actions/version-bumping/npm@[^[:space:]"]+|./.github/actions/version-bumping/npm|g' action.yml
- name: Test NPM Action (Dry Run)
id: version_bump
uses: ./
with:
type: npm
token: ${{ secrets.GITHUB_TOKEN }}
package-json-file: "test-resources/package.json"
dry-run: "true"
- name: Verify Outputs
run: |
echo "Bumped: ${{ steps.version_bump.outputs.bumped }}"
echo "New Version: ${{ steps.version_bump.outputs.new-version }}"
echo "### NPM Test New Version: ${{ steps.version_bump.outputs.new-version }}" >> $GITHUB_STEP_SUMMARY
if [ -z "${{ steps.version_bump.outputs.bumped }}" ]; then
echo "Error: 'bumped' output is empty"
exit 1
fi
test-maven:
needs: build-dist
runs-on: [ubuntu-latest]
permissions:
contents: write
pull-requests: read
steps:
- uses: actions/checkout@v4
- name: Patch composite actions for E2E
run: |
sed -i -E 's|sap/pull-request-semver-bumper/.github/actions/core@[^[:space:]"]+|./.github/actions/core|g' .github/actions/version-bumping/*/action.yml
sed -i -E 's|sap/pull-request-semver-bumper/.github/actions/version-bumping/maven@[^[:space:]"]+|./.github/actions/version-bumping/maven|g' action.yml
- name: Test Maven Action (Dry Run)
id: version_bump
uses: ./
with:
type: maven
token: ${{ secrets.GITHUB_TOKEN }}
dry-run: "true"
pom-file: "test-resources/pom.xml"
# removed actual settings.xml to avoid fetch setting in this simple test
bump-command: "mvn org.codehaus.mojo:versions-maven-plugin:set -DnewVersion=@NEW_VERSION@"
- name: Verify Outputs
run: |
echo "Bumped: ${{ steps.version_bump.outputs.bumped }}"
echo "New Version: ${{ steps.version_bump.outputs.new-version }}"
echo "### Maven Test New Version: ${{ steps.version_bump.outputs.new-version }}" >> $GITHUB_STEP_SUMMARY
if [ -z "${{ steps.version_bump.outputs.bumped }}" ]; then
echo "Error: 'bumped' output is empty"
exit 1
fi
test-version-file:
needs: build-dist
runs-on: [ubuntu-latest]
permissions:
contents: write
pull-requests: read
steps:
- uses: actions/checkout@v4
- name: Patch composite actions for E2E
run: |
sed -i -E 's|sap/pull-request-semver-bumper/.github/actions/core@[^[:space:]"]+|./.github/actions/core|g' .github/actions/version-bumping/*/action.yml
sed -i -E 's|sap/pull-request-semver-bumper/.github/actions/version-bumping/version-file@[^[:space:]"]+|./.github/actions/version-bumping/version-file|g' action.yml
- name: Test Version File Action (Dry Run)
id: version_bump
uses: ./
with:
type: version-file
token: ${{ secrets.GITHUB_TOKEN }}
version-file: "test-resources/VERSION"
dry-run: "true"
- name: Verify Outputs
run: |
echo "Bumped: ${{ steps.version_bump.outputs.bumped }}"
echo "New Version: ${{ steps.version_bump.outputs.new-version }}"
echo "### Version File Test New Version: ${{ steps.version_bump.outputs.new-version }}" >> $GITHUB_STEP_SUMMARY
if [ -z "${{ steps.version_bump.outputs.bumped }}" ]; then
echo "Error: 'bumped' output is empty"
exit 1
fi
all-tests-passed:
if: always()
needs: [build-dist, test-python, test-npm, test-maven, test-version-file]
runs-on: ubuntu-latest
permissions:
statuses: write
steps:
- name: Determine Status
id: status
run: |
if [[ ${{ contains(needs.*.result, 'failure') }} == 'true' || ${{ contains(needs.*.result, 'cancelled') }} == 'true' ]]; then
echo "status=failure" >> $GITHUB_OUTPUT
else
echo "status=success" >> $GITHUB_OUTPUT
fi
- name: Set Commit Status
uses: myrotvorets/set-commit-status-action@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ steps.status.outputs.status }}
sha: ${{ needs.build-dist.outputs.committed_sha || github.event.pull_request.head.sha }}
context: "all-tests-passed"
description: "Aggregation of all tests"
- name: Fail if needed
if: steps.status.outputs.status == 'failure'
run: exit 1