-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
89 lines (78 loc) · 2.71 KB
/
Copy pathaction.yml
File metadata and controls
89 lines (78 loc) · 2.71 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
name: "Maven Flow Release"
description: "Perform Maven release with changelog update"
inputs:
changelog-file:
description: "Changelog file"
default: "CHANGELOG.md"
required: false
type: string
git-user-name:
description: "GIT user name (to commit changes)"
default: "github-actions[bot]"
required: false
type: string
git-user-email:
description: "GIT user email (to commit changes)"
default: "github-actions[bot]@users.noreply.github.com"
required: false
type: string
pom-file:
description: "Maven POM file"
default: "pom.xml"
required: false
type: string
push-changes:
required: true
type: boolean
token:
required: true
default: ${{ github.token }}
runs:
using: "composite"
steps:
- name: Get project version
id: get-project-version
shell: bash
run: |
projectVersion=$(mvn -B help:evaluate -Dexpression=project.version -q -DforceStdout --file ${{ inputs.pom-file }} ${{ inputs.maven-args }})
echo "Project version: $projectVersion"
echo "version=$projectVersion" >> $GITHUB_OUTPUT
- name: Set up GIT
shell: bash
run: |
git config --local user.name '${{ inputs.git-user-name }}'
git config --local user.email '${{ inputs.git-user-email }}'
- name: Update version date in changelog
shell: bash
run: |
current_date=$(date "+%Y-%m-%d")
sed -i "s/\[SNAPSHOT\]/$current_date/g" "${{ inputs.changelog-file }}"
git commit -a -m "Updated version date in changelog."
- name: Perform Maven release
shell: bash
run: mvn -B release:prepare release:perform --file ${{ inputs.pom-file }} ${{ inputs.maven-args }}
env:
GITHUB_TOKEN: ${{ inputs.token }}
- name: Add next version to changelog
shell: bash
run: |
nextVersion=$(mvn -B help:evaluate -Dexpression=project.version -q -DforceStdout --file ${{ inputs.pom-file }} ${{ inputs.maven-args }})
nextVersion=$(echo "$nextVersion" | sed 's/.\{9\}$//')
nextVersionText="## [$nextVersion] - [SNAPSHOT]
"
tempFile=$(mktemp)
head -n 7 "${{ inputs.changelog-file }}" > "$tempFile"
echo "$nextVersionText" >> "$tempFile"
tail -n +8 "${{ inputs.changelog-file }}" >> "$tempFile"
mv "$tempFile" "${{ inputs.changelog-file }}"
git commit -a -m "Added next version to changelog."
- name: Push changes
shell: bash
run: |
# This condition needs to be inside the script (not in "if" field), because GitHub is unable to properly implement boolean inputs.
# https://github.com/actions/runner/issues/2238
if [ "${{ inputs.push-changes }}" = "true" ]; then
echo "Pushing changes:"
git push
git push --tags
fi