Skip to content

Commit 957a733

Browse files
authored
Merge pull request #21 from fairagro/feature/workflow
Feature/workflow
2 parents 73db4c3 + 210c3b7 commit 957a733

File tree

3 files changed

+71
-31
lines changed

3 files changed

+71
-31
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Add Version Info to Merge Commit
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
types: [closed]
7+
8+
permissions:
9+
contents: write
10+
11+
env:
12+
GIT_USER_NAME: GitHub Pipeline
13+
GIT_USER_EMAIL: [email protected]
14+
15+
jobs:
16+
add-merge-message:
17+
if: github.event.pull_request.merged == true
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout main
22+
uses: actions/checkout@v5
23+
with:
24+
ref: ${{ github.ref }}
25+
fetch-depth: 0
26+
27+
# Prüfen des Labels für Version Bump
28+
- name: Determine Version label
29+
id: version-label
30+
uses: actions/github-script@v7
31+
with:
32+
github-token: ${{ secrets.GITHUB_TOKEN }}
33+
script: |
34+
const allowedLabels = ["major version","minor version","patch version"];
35+
const pr = context.payload.pull_request;
36+
const labels = pr.labels.map(l => l.name);
37+
console.log("Labels on PR:", labels);
38+
const matching = labels.filter(l => allowedLabels.includes(l));
39+
console.log("Matching labels:", matching);
40+
if (matching.length === 0) {
41+
throw new Error("No version label found on the PR. Please add one of: " + allowedLabels.join(", "));
42+
}
43+
const result = matching[0].replace(" version","");
44+
console.log("Determined version label:", result);
45+
core.setOutput("result", result);
46+
47+
- name: Amend merge commit message
48+
run: |
49+
MERGE_COMMIT=$(git log -1 --merges --pretty=format:%H)
50+
VERSION_LABEL=${{ steps.version-label.outputs.result }}
51+
git config user.name "${{ env.GIT_USER_NAME }}"
52+
git config user.email "${{ env.GIT_USER_EMAIL }}"
53+
git commit --amend -m "$(git log -1 --pretty=%B) +semver: $VERSION_LABEL"
54+
git push --force

.github/workflows/docker-build.yml

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,6 @@ jobs:
3535
ref: ${{ github.ref }}
3636
fetch-depth: 0
3737

38-
# Prüfen des Labels für Version Bump
39-
- name: Determine Version Bump
40-
id: version-bump
41-
uses: actions/github-script@v7
42-
with:
43-
github-token: ${{ secrets.GITHUB_TOKEN }}
44-
script: |
45-
const allowedLabels = ["major version","minor version","patch version"];
46-
const pr = context.payload.pull_request;
47-
const labels = pr.labels.map(l => l.name);
48-
console.log("Labels on PR:", labels);
49-
const matching = labels.filter(l => allowedLabels.includes(l));
50-
console.log("Matching labels:", matching);
51-
const result = matching[0].replace(" version","");
52-
console.log("Determined version bump:", result);
53-
core.setOutput("bump", result);
54-
5538
# GitVersion für main Merge
5639
- name: Install GitVersion
5740
uses: gittools/actions/gitversion/setup@v4
@@ -62,7 +45,8 @@ jobs:
6245
id: gitversion
6346
uses: gittools/actions/gitversion/execute@v4
6447
with:
65-
configFilePath: GitVersion.${{ steps.version-bump.outputs.bump }}.yml
48+
# configFilePath: GitVersion.${{ steps.version-bump.outputs.bump }}.yml
49+
configFilePath: GitVersion.yml
6650

6751
- name: Show calculated version
6852
run: |

GitVersion.yml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
workflow: GitHubFlow/v1
12
tag-prefix: v
23

3-
branches:
4-
main:
5-
increment: Patch
6-
# prevent-increment:
7-
# of-merged-branch: true
4+
# mode: ContinuousDelivery
5+
# tag-prefix: v
86

9-
feature:
10-
increment: Patch
11-
source-branches: [main]
12-
label: "{BranchName}"
13-
prevent-increment:
14-
of-merged-branch: true
15-
regex: ^feature/(?<BranchName>.+)$
16-
is-source-branch-for: []
7+
# branches:
8+
# main:
9+
# merge-message-strategy: MergeMessage
10+
11+
# feature:
12+
# increment: Patch
13+
# source-branches: [main]
14+
# label: "{BranchName}"
15+
# prevent-increment:
16+
# of-merged-branch: true
17+
# regex: ^feature/(?<BranchName>.+)$
18+
# is-source-branch-for: []

0 commit comments

Comments
 (0)