-
Notifications
You must be signed in to change notification settings - Fork 18
191 lines (153 loc) · 7.39 KB
/
Build.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
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
name: Build
on:
workflow_dispatch:
pull_request:
branches:
- 'master'
- 'release-*'
push:
branches:
- 'master'
- 'beta'
- 'release-*'
- 'beta-corona'
jobs:
build:
name: Build
env:
GIT_REF: ${{ github.ref }}
GIT_SHA: ${{ github.sha }}
POM_PATH: ./pom.xml
runs-on: ubuntu-latest
outputs:
MAVEN_VERSION: ${{ steps.buildVariables.outputs.MAVEN_VERSION }}
LAST_COMMITTER: ${{ steps.buildVariables.outputs.LAST_COMMITTER }}
COMMIT_MESSAGE: ${{ steps.buildVariables.outputs.COMMIT_MESSAGE }}
SHOULD_DEPLOY: ${{ steps.buildVariables.outputs.SHOULD_DEPLOY }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Java JDK
uses: actions/setup-java@v4
with:
java-version: ${{ vars.JAVA_VERSION }}
distribution: 'temurin'
gpg-private-key: ${{ secrets.MAVEN_GPG_BUILDER_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: Setup Maven
uses: stCarolas/[email protected]
with:
maven-version: ${{ vars.MAVEN_VERSION }}
- name: Setup Maven settings
uses: whelk-io/maven-settings-xml-action@v14
with:
repositories: '[{ "id": "github-genexuslabs", "url": "https://maven.pkg.github.com/genexuslabs/*", "releases": { "enabled": "true" }, "snapshots": { "enabled": "true" } }]'
servers: '[
{ "id": "github-genexuslabs", "username": "genexusbot", "password": "${{ secrets.SECURE_TOKEN }}" },
{ "id": "azure-devops", "username": "genexuslabs", "password": "${env.AZURE_ARTIFACTS_TOKEN}" },
{ "id": "ossrh", "username": "${env.MAVEN_USERNAME}", "password": "${env.MAVEN_PASSWORD}" },
{ "id": "gpg.passphrase", "passphrase": "${env.MAVEN_GPG_PASSPHRASE}" }
]'
- name: Calculate build variables
id: buildVariables
run: |
currentVersion="$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)"
semVerComponents=( ${currentVersion//-/ } )
semVerComponents=${semVerComponents[0]}
semVerComponents=( ${semVerComponents//./ } )
pomMajorNumber=${semVerComponents[0]}
pomMinorNumber=${semVerComponents[1]}
[[ $(git branch --show-current) ]] && branch="$(git symbolic-ref --short HEAD)" || branch=“DETACHED_HEAD“
timestamp=$(date --utc +%Y%m%d%H%M%S)
SHOULD_DEPLOY='false'
SHOULD_DEPLOY_MAVEN_CENTRAL='false'
case "$branch" in
master)
echo "## Is MASTER branch"
versionChangelist="-preview.$timestamp-SNAPSHOT"
SHOULD_DEPLOY='true'
;;
beta)
echo "## Is BETA branch"
versionChangelist="-beta.$timestamp-SNAPSHOT"
SHOULD_DEPLOY='true'
;;
beta-corona)
echo "## Is BETA-CORONA branch, use fixed version"
pomMajorNumber="116"
pomMinorNumber="0"
pomPatchNumber="$(git rev-list --count origin/master..)"
SHOULD_DEPLOY='true'
;;
release-*)
echo "## Is RELEASE/UPGRADE branch, use pom.xml version modifing patch number"
pomPatchNumber="$(git rev-list --count origin/master..)"
SHOULD_DEPLOY='true'
SHOULD_DEPLOY_MAVEN_CENTRAL='true'
;;
*)
echo "## Is a feature branch, use pom.xml version as is"
;;
esac
if [ -z "$pomPatchNumber" ]; then
newVersion="$pomMajorNumber.$pomMinorNumber"
else
newVersion="$pomMajorNumber.$pomMinorNumber.$pomPatchNumber"
fi
# Add current commit's SHA to pom.xml
GIT_HASH=$(git rev-parse HEAD)
scmversion="<vcm_hash>$GIT_HASH</vcm_hash>"
scmv=$(echo $scmversion | sed 's/\//\\\//g')
sed -i "/<\/properties>/ s/.*/ ${scmv}\n&/" pom.xml
echo "Project version: $newVersion"
echo "Version changelist: $versionChangelist"
MAVEN_VERSION="$newVersion$versionChangelist"
echo "Full project version: $MAVEN_VERSION"
LastCommitter=$(git log -1 --pretty=format:%an)
CommitMessage=$(git log -1 --pretty=%B)
echo "LAST_COMMITTER=$LastCommitter" >> $GITHUB_OUTPUT
# Handling a multi-line output value
OUTPUT_MESSAGE_EOF="eof${MAVEN_VERSION}"
echo "COMMIT_MESSAGE<<$OUTPUT_MESSAGE_EOF" >> $GITHUB_OUTPUT
echo "$CommitMessage" >> $GITHUB_OUTPUT
echo "$OUTPUT_MESSAGE_EOF" >> $GITHUB_OUTPUT
echo "newVersion=$newVersion" >> $GITHUB_OUTPUT
echo "versionChangelist=$versionChangelist" >> $GITHUB_OUTPUT
echo "MAVEN_VERSION=$MAVEN_VERSION" >> $GITHUB_OUTPUT
echo "SHOULD_DEPLOY=$SHOULD_DEPLOY" >> $GITHUB_OUTPUT
echo "SHOULD_DEPLOY_MAVEN_CENTRAL=$SHOULD_DEPLOY_MAVEN_CENTRAL" >> $GITHUB_OUTPUT
- name: Validate build
run: mvn -B validate -Drevision=${{ steps.buildVariables.outputs.newVersion }} -Dchangelist=${{ steps.buildVariables.outputs.versionChangelist }} -Dsha1=${{ github.sha }} --file $POM_PATH -P ci-cd
- name: Build
run: mvn -B compile -Drevision=${{ steps.buildVariables.outputs.newVersion }} -Dchangelist=${{ steps.buildVariables.outputs.versionChangelist }} -Dsha1=${{ github.sha }} --file $POM_PATH -P ci-cd
- name: Test
run: mvn -B test -Drevision=${{ steps.buildVariables.outputs.newVersion }} -Dchangelist=${{ steps.buildVariables.outputs.versionChangelist }} -Dsha1=${{ github.sha }} --file $POM_PATH -P ci-cd
- name: Package
run: mvn -B -DskipTests package -Drevision=${{ steps.buildVariables.outputs.newVersion }} -Dchangelist=${{ steps.buildVariables.outputs.versionChangelist }} -Dsha1=${{ github.sha }} --file $POM_PATH -P ci-cd
- name: Deploy to Azure Artifacts
if: steps.buildVariables.outputs.SHOULD_DEPLOY == 'true'
run: mvn -B -DskipTests deploy -Drevision=${{ steps.buildVariables.outputs.newVersion }} -Dchangelist=${{ steps.buildVariables.outputs.versionChangelist }} -Dsha1=${{ github.sha }} -DdeployAtEnd=true --file "$POM_PATH" -P ci-cd -P deploy-to-azure
env:
AZURE_ARTIFACTS_TOKEN: ${{ secrets.AZURE_ARTIFACTS_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_BUILDER_PASSPHRASE }}
- name: Deploy to Maven Central
if: steps.buildVariables.outputs.SHOULD_DEPLOY_MAVEN_CENTRAL == 'true'
run: mvn -B -DskipTests deploy -Drevision=${{ steps.buildVariables.outputs.newVersion }} -Dchangelist=${{ steps.buildVariables.outputs.versionChangelist }} -Dsha1=${{ github.sha }} -DdeployAtEnd=true --file "$POM_PATH" -P ci-cd -P deploy-to-maven-central
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_OSSRH_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_BUILDER_PASSPHRASE }}
update-genexus-dependency:
concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true
uses: genexuslabs/build-genexus-reusable-workflow/.github/workflows/update-genexus-dep-version.yml@main
needs: build
if: github.repository_owner == 'genexuslabs' && needs.build.outputs.SHOULD_DEPLOY == 'true'
with:
VERSION: ${{ needs.build.outputs.MAVEN_VERSION }}
PACKAGE_NAMES: ${{ needs.build.outputs.PACKAGES_NAME }}
COMMITTER: ${{ needs.build.outputs.LAST_COMMITTER }}
secrets: inherit