@@ -20,10 +20,15 @@ jobs:
20
20
GIT_REF : ${{ github.ref }}
21
21
GIT_SHA : ${{ github.sha }}
22
22
POM_PATH : ./pom.xml
23
- VERSION_SCRIPT : ./github/updatePOMVersion.sh
24
23
25
24
runs-on : ubuntu-latest
26
25
26
+ outputs :
27
+ MAVEN_VERSION : ${{ steps.buildVariables.outputs.MAVEN_VERSION }}
28
+ LAST_COMMITTER : ${{ steps.buildVariables.outputs.LAST_COMMITTER }}
29
+ COMMIT_MESSAGE : ${{ steps.buildVariables.outputs.COMMIT_MESSAGE }}
30
+ SHOULD_DEPLOY : ${{ steps.buildVariables.outputs.SHOULD_DEPLOY }}
31
+
27
32
steps :
28
33
- name : Checkout
29
34
uses : actions/checkout@v2
@@ -34,52 +39,161 @@ jobs:
34
39
uses : actions/setup-java@v1.4.3
35
40
with :
36
41
java-version : 1.9
42
+ gpg-private-key : ${{ secrets.MAVEN_GPG_BUILDER_PRIVATE_KEY }}
43
+ gpg-passphrase : MAVEN_GPG_PASSPHRASE
37
44
38
45
- name : Setup Maven settings
39
46
uses : whelk-io/maven-settings-xml-action@v14
40
47
with :
41
- repositories : ' [{ "id": "github-genexuslabs", "url": "https://maven.pkg.github.com/genexuslabs/Private-Maven-for-GX", "releases": { "enabled": "true" }, "snapshots": { "enabled": "true" } }]'
42
- servers : ' [{ "id": "github-genexuslabs", "username": "genexusbot", "password": "${{ secrets.SECURE_TOKEN }}" }]'
48
+ repositories : ' [{ "id": "github-genexuslabs", "url": "https://maven.pkg.github.com/genexuslabs/*", "releases": { "enabled": "true" }, "snapshots": { "enabled": "true" } }]'
49
+ servers : ' [
50
+ { "id": "github-genexuslabs", "username": "genexusbot", "password": "${{ secrets.SECURE_TOKEN }}" },
51
+ { "id": "azure-devops", "username": "genexuslabs", "password": "${env.AZURE_ARTIFACTS_TOKEN}" },
52
+ { "id": "ossrh", "username": "${env.MAVEN_USERNAME}", "password": "${env.MAVEN_PASSWORD}" },
53
+ { "id": "gpg.passphrase", "passphrase": "${env.MAVEN_GPG_PASSPHRASE}" }
54
+ ]'
43
55
44
56
- name : Calculate build variables
45
57
id : buildVariables
46
58
run : |
47
- if ! [[ "$GIT_REF" =~ 'release-.+$' ]]; then
48
- CommitNumber=$(git rev-list --count HEAD)
49
- else
50
- CommitNumber=$(git rev-list --count origin/master..)
51
- fi
52
-
53
59
LastCommitter=$(git log -1 --pretty=format:%an)
54
60
CommitMessage=$(git log -1 --pretty=%B)
55
61
56
- echo "::set-output name=CommitNumber::$CommitNumber"
57
- echo "::set-output name=LastCommitter::$LastCommitter"
58
- echo "::set-output name=CommitMessage::$CommitMessage"
62
+ echo "::set-output name=LAST_COMMITTER::$LastCommitter"
63
+ echo "::set-output name=COMMIT_MESSAGE::$CommitMessage"
59
64
60
- - name : Update POM version
61
- id : POMVersion
62
- run : |
63
- script="$VERSION_SCRIPT"
64
- if [ -f "$script" ]; then
65
- echo "Executing version script at: $script"
66
- sh "$script"
65
+ currentVersion="$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)"
66
+ semVerComponents=( ${currentVersion//-/ } )
67
+ semVerComponents=${semVerComponents[0]}
68
+ semVerComponents=( ${semVerComponents//./ } )
69
+
70
+ pomMajorNumber=${semVerComponents[0]}
71
+ pomMinorNumber=${semVerComponents[1]}
72
+
73
+ [[ $(git branch --show-current) ]] && branch="$(git symbolic-ref --short HEAD)" || branch=“DETACHED_HEAD“
74
+ timestamp=$(date --utc +%Y%m%d%H%M%S)
75
+
76
+ SHOULD_DEPLOY='false'
77
+ SHOULD_DEPLOY_MAVEN_CENTRAL='false'
78
+
79
+ case "$branch" in
80
+ master)
81
+ echo "## Is MASTER branch"
82
+
83
+ versionChangelist="-stable.$timestamp-SNAPSHOT"
84
+ SHOULD_DEPLOY='true'
85
+ ;;
86
+
87
+ beta)
88
+ echo "## Is BETA branch, add +100 to major number"
89
+
90
+ pomMajorNumber=$(expr $pomMajorNumber + 100)
91
+
92
+ versionChangelist="-trunk.$timestamp-SNAPSHOT"
93
+ SHOULD_DEPLOY='true'
94
+ ;;
95
+
96
+ beta-corona)
97
+ echo "## Is BETA-CORONA branch, use fixed version"
98
+
99
+ pomMajorNumber="116"
100
+ pomMinorNumber="0"
101
+ pomPatchNumber="$(git rev-list --count origin/master..)"
102
+
103
+ SHOULD_DEPLOY='true'
104
+ ;;
105
+
106
+ release-*)
107
+ echo "## Is RELEASE/UPGRADE branch, use pom.xml version modifing patch number"
108
+
109
+ pomPatchNumber="$(git rev-list --count origin/master..)"
110
+
111
+ SHOULD_DEPLOY='true'
112
+ SHOULD_DEPLOY_MAVEN_CENTRAL='true'
113
+ ;;
114
+
115
+ *)
116
+ echo "## Is a feature branch, use pom.xml version as is"
117
+ ;;
118
+ esac
119
+
120
+ if [ -z "$pomPatchNumber" ]; then
121
+ newVersion="$pomMajorNumber.$pomMinorNumber"
67
122
else
68
- echo 'No version script specified. Will generate packages with the version on the POM file'
123
+ newVersion="$pomMajorNumber.$pomMinorNumber.$pomPatchNumber"
69
124
fi
70
125
71
- finalPOMVersion=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout --file $POM_PATH)
72
- echo "Project version: $finalPOMVersion"
73
- echo "::set-output name=finalPOMVersion::$finalPOMVersion"
126
+ # Add current commit's SHA to pom.xml
127
+ GIT_HASH=$(git rev-parse HEAD)
128
+ scmversion="<vcm_hash>$GIT_HASH</vcm_hash>"
129
+ scmv=$(echo $scmversion | sed 's/\//\\\//g')
130
+ sed -i "/<\/properties>/ s/.*/ ${scmv}\n&/" pom.xml
131
+
132
+ echo "Project version: $newVersion"
133
+ echo "Version changelist: $versionChangelist"
134
+
135
+ MAVEN_VERSION="$newVersion$versionChangelist"
136
+ echo "Full project version: $MAVEN_VERSION"
137
+
138
+ echo "::set-output name=newVersion::$newVersion"
139
+ echo "::set-output name=versionChangelist::$versionChangelist"
140
+ echo "::set-output name=MAVEN_VERSION::$MAVEN_VERSION"
141
+ echo "::set-output name=SHOULD_DEPLOY::$SHOULD_DEPLOY"
142
+ echo "::set-output name=SHOULD_DEPLOY_MAVEN_CENTRAL::$SHOULD_DEPLOY_MAVEN_CENTRAL"
74
143
75
144
- name : Validate build
76
- run : mvn -B validate -- file $POM_PATH
145
+ run : mvn -B validate -Drevision=${{ steps.buildVariables.outputs.newVersion }} -Dchangelist=${{ steps.buildVariables.outputs.versionChangelist }} -Dsha1=${{ github.sha }} -- file $POM_PATH -P ci-cd
77
146
78
147
- name : Build
79
- run : mvn -B compile -- file $POM_PATH
148
+ run : mvn -B compile -Drevision=${{ steps.buildVariables.outputs.newVersion }} -Dchangelist=${{ steps.buildVariables.outputs.versionChangelist }} -Dsha1=${{ github.sha }} -- file $POM_PATH -P ci-cd
80
149
81
150
- name : Test
82
- run : mvn -B test -- file $POM_PATH
151
+ run : mvn -B test -Drevision=${{ steps.buildVariables.outputs.newVersion }} -Dchangelist=${{ steps.buildVariables.outputs.versionChangelist }} -Dsha1=${{ github.sha }} -- file $POM_PATH -P ci-cd
83
152
84
153
- name : Package
85
- run : mvn -B package --file $POM_PATH
154
+ run : mvn -B -DskipTests package -Drevision=${{ steps.buildVariables.outputs.newVersion }} -Dchangelist=${{ steps.buildVariables.outputs.versionChangelist }} -Dsha1=${{ github.sha }} --file $POM_PATH -P ci-cd
155
+
156
+ - name : Deploy to Azure Artifacts
157
+ if : steps.buildVariables.outputs.SHOULD_DEPLOY == 'true'
158
+ 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
159
+ env :
160
+ AZURE_ARTIFACTS_TOKEN : ${{ secrets.AZURE_ARTIFACTS_TOKEN }}
161
+ MAVEN_GPG_PASSPHRASE : ${{ secrets.MAVEN_GPG_BUILDER_PASSPHRASE }}
162
+
163
+ - name : Deploy to Maven Central
164
+ if : steps.buildVariables.outputs.SHOULD_DEPLOY_MAVEN_CENTRAL == 'true'
165
+ 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
166
+ env :
167
+ MAVEN_USERNAME : ${{ secrets.MAVEN_OSSRH_USERNAME }}
168
+ MAVEN_PASSWORD : ${{ secrets.MAVEN_OSSRH_TOKEN }}
169
+ MAVEN_GPG_PASSPHRASE : ${{ secrets.MAVEN_GPG_BUILDER_PASSPHRASE }}
170
+
171
+ dispatch-build :
172
+ name : Dispatch build result
173
+ needs : build
174
+ if : github.repository_owner == 'GeneXusLabs' && needs.build.outputs.SHOULD_DEPLOY == 'true'
175
+
176
+ runs-on : ubuntu-latest
177
+
178
+ concurrency :
179
+ group : build-${{ github.ref }}
180
+ cancel-in-progress : true
181
+
182
+ steps :
183
+ - name : Checkout action
184
+ uses : actions/checkout@v2
185
+ with :
186
+ repository : genexuslabs/dispatch-build-result
187
+ ref : releases/v2
188
+ token : ${{ secrets.SECURE_TOKEN }}
189
+ path : ./tmp/.github/actions/dispatch-build-result
190
+
191
+ - name : Dispatch build result
192
+ uses : ./tmp/.github/actions/dispatch-build-result
193
+ with :
194
+ component-name : ${{ github.event.inputs.repository }}
195
+ branch-ref : ${{ env.GIT_REF }}
196
+ new-version : ${{ needs.build.outputs.MAVEN_VERSION }}
197
+ committer : ${{ needs.build.outputs.LAST_COMMITTER }}
198
+ commit-message : ${{ needs.build.outputs.COMMIT_MESSAGE }}
199
+ token : ${{ secrets.SECURE_TOKEN }}
0 commit comments