-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
150 lines (139 loc) · 5.22 KB
/
action.yml
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
name: Build
description: Build the Java project
inputs:
java_version:
description: 'The java version to use'
default: '17'
java_distribution:
description: 'The java distribution to use'
default: 'zulu'
maven_version:
description: 'The maven version to use'
default: '3.8.3'
maven_flag:
description: 'The maven flag to use'
default: '-T 4C -B --no-transfer-progress'
token:
description: 'The GitHub token'
required: true
publish_artifacts:
description: 'Publish the artifacts'
default: 'false'
ref:
description: 'The ref to build'
default: "${{ github.ref }}"
required: false
outputs:
version:
description: 'The version of the artifact'
value: ${{ steps.set-version.outputs.version }}
runs:
using: 'composite'
steps:
- name: Set up JDK ${{ inputs.java_version }}
uses: actions/setup-java@v4
with:
java-version: ${{ inputs.java_version }}
server-id: github
distribution: ${{ inputs.java_distribution }}
- name: Cache local Maven repository
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven
restore-keys: |
${{ runner.os }}-maven
- name: Set up Maven
uses: stCarolas/setup-maven@v5
with:
maven-version: ${{ inputs.maven_version }}
- name: Setup Git Config
run: |
git config --global user.email "[email protected]"
git config --global user.name "clearci"
shell: bash
- name: Check the source ref
id: ref
env:
HOTFIX: ${{ contains( inputs.ref, 'hotfix/') }}
MASTER: ${{ inputs.ref == 'refs/heads/master' || inputs.ref == 'refs/heads/main' }}
run: |
echo "hotfix=$HOTFIX" >> $GITHUB_OUTPUT
echo "master=$MASTER" >> $GITHUB_OUTPUT
shell: bash
- name: Set Version
id: set-version
run: |
if [[ "${{ steps.ref.outputs.master }}" == "true" ]]; then
VERSION=$(mvn ${{inputs.maven_flag}} --non-recursive -q \
build-helper:parse-version exec:exec \
-Dexec.executable=echo \
-Dexec.args='${parsedVersion.majorVersion}.${parsedVersion.nextMinorVersion}.0') || {
echo "Failed to generate version for master branch\n${VERSION}"
exit 1
}
elif [[ "${{ steps.ref.outputs.hotfix }}" == "true" ]]; then
QUALIFIER=$(mvn ${{inputs.maven_flag}} --non-recursive -q \
build-helper:parse-version exec:exec \
-Dexec.executable=echo -Dexec.args='${parsedVersion.qualifier}') || {
echo "Failed to extract qualifier for hotfix branch\n${QUALIFIER}"
exit 1
}
if [[ -z "$QUALIFIER" ]]; then
mvn ${{inputs.maven_flag}} -q build-helper:parse-version \
versions:set \
-DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion}-SNAPSHOT \
versions:commit
mvn ${{inputs.maven_flag}} -q scm:checkin -Dmessage="[ci skip] set snapshot version"
fi
VERSION=$(mvn ${{inputs.maven_flag}} help:evaluate -Dexpression=project.version -q -DforceStdout|sed 's/-SNAPSHOT//') || {
echo "Failed to evaluate project version for hotfix branch\n${VERSION}"
exit 1
}
else
VERSION="dev-${GITHUB_SHA::8}"
fi
if [[ -z "${VERSION// }" ]]; then
echo "Error: Version string is empty or invalid"
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "## Version: $VERSION" >> $GITHUB_STEP_SUMMARY
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.token }}
GITHUB_ACTOR: clearci
- name: Build for production release
if: ${{ steps.ref.outputs.master == 'true' || steps.ref.outputs.hotfix == 'true' }}
env:
GITHUB_TOKEN: ${{ inputs.token }}
GITHUB_ACTOR: clearci
run: |
mvn -DskipTests ${{inputs.maven_flag}} -Darguments=-DskipTests \
release:clean release:prepare \
-DtagNameFormat="v@{project.version}" \
-DscmCommentPrefix="[ci skip] " \
-DreleaseVersion=${{ steps.set-version.outputs.version }} \
-Dusername=clearci -Dpassword=${{ inputs.token }}
shell: bash
- name: Build for dev release
env:
GITHUB_TOKEN: ${{ inputs.token }}
GITHUB_ACTOR: clearci
if: ${{ steps.ref.outputs.master == 'false' && steps.ref.outputs.hotfix == 'false' }}
run: mvn -DskipTests ${{inputs.maven_flag}} package
shell: bash
- name: Deploy Artifacts to Production
if: ${{ ( steps.ref.outputs.master == 'true' || steps.ref.outputs.hotfix == 'true' ) && inputs.publish_artifacts == 'true' }}
env:
GITHUB_TOKEN: ${{ inputs.token }}
GITHUB_ACTOR: clearci
run: mvn -fn deploy --settings ./.mvn/settings.xml -T 4C -DskipTests --file pom.xml
shell: bash
- name: Upload artifacts
uses: 'actions/upload-artifact@v4'
with:
name: artifacts-${{github.run_id}}
path: |
${{ github.workspace }}/**/*.jar
retention-days: 1