Skip to content

Commit 39269f6

Browse files
jechagueanaiberta
andauthored
Publish packages to public feeds (#596)
* Add Dockerfile-based devcontainer * Use revision and changelist properties instead of version * Configure project for publication in Azure Artifacts and Maven Central Update build workflow: - Refactor version script into a step directly in the workflow - Update version format to use a trunk or stable identifier - Add new servers - Use Maven profiles - Separate build dispatch into a separate job - Delete ProcessCommit workflow Co-authored-by: Ana Berta <31777352+anaiberta@users.noreply.github.com>
1 parent 3b57117 commit 39269f6

File tree

29 files changed

+469
-163
lines changed

29 files changed

+469
-163
lines changed

.devcontainer/Dockerfile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
ARG VARIANT=
2+
FROM openjdk:${VARIANT}
3+
4+
LABEL vendor="GeneXus Labs"
5+
USER root
6+
7+
# Set timezone
8+
ENV TZ=America/Montevideo
9+
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
10+
11+
# Install dependencies
12+
RUN apt-get update \
13+
&& apt-get install -y \
14+
curl \
15+
git \
16+
git-lfs \
17+
maven \
18+
sudo \
19+
tar \
20+
zip \
21+
gnupg2 \
22+
-o APT::Immediate-Configure=0 \
23+
&& apt-get clean \
24+
&& rm -fr /var/lib/apt/lists/* /tmp/* /var/tmp/*
25+
26+
#Set Github user
27+
RUN useradd -m github \
28+
&& usermod -aG sudo github \
29+
&& echo "%sudo ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
30+
31+
USER github
32+
WORKDIR /home/github
33+
34+
# Enable Git LFS
35+
RUN git lfs install
36+
37+
# Install updated cacerts
38+
# Build a new Java cacerts using CAs trusted by Mozilla
39+
RUN cd /tmp \
40+
&& curl -OL https://hg.mozilla.org/mozilla-central/raw-file/tip/security/nss/lib/ckfw/builtins/certdata.txt \
41+
&& curl -OL https://raw.githubusercontent.com/curl/curl/master/scripts/mk-ca-bundle.pl \
42+
&& curl -OL https://github.com/use-sparingly/keyutil/releases/download/0.4.0/keyutil-0.4.0.jar \
43+
&& perl mk-ca-bundle.pl -n > ca-bundle.crt \
44+
&& java -jar keyutil-0.4.0.jar --import --new-keystore cacerts-mozilla --password changeit --force-new-overwrite --import-pem-file ca-bundle.crt \
45+
&& sudo cp cacerts-mozilla ${JAVA_HOME}/lib/security/cacerts \
46+
&& rm -r /tmp/*
47+
48+
# Copy Maven settings
49+
COPY --chown=github:github settings.xml /tmp/settings.xml
50+
RUN mkdir -p /home/github/.m2/ \
51+
&& mv /tmp/settings.xml /home/github/.m2/

.devcontainer/devcontainer.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "OpenJDK for compiling GeneXus's Java Classes",
3+
4+
"build": {
5+
"dockerfile": "Dockerfile",
6+
// Update 'VARIANT' to pick a different OpenJDK container
7+
"args": {
8+
//"VARIANT": "9.0.4-12-jdk-slim"
9+
//"VARIANT": "11.0.14-jdk-slim"
10+
"VARIANT": "17.0-jdk-slim"
11+
},
12+
},
13+
14+
"runArgs": [
15+
"--env-file", "${localWorkspaceFolder}/.devcontainer/.env"
16+
],
17+
18+
// Set *default* container specific settings.json values on container create.
19+
"settings": {
20+
"terminal.integrated.shell.linux": "/bin/bash"
21+
},
22+
23+
/*"mounts": [
24+
"source=<LOCAL_PATH>,target=${containerWorkspaceFolder}/<LOCAL_PATH>,type=volume"
25+
],*/
26+
27+
// Use 'postCreateCommand' to run commands after the container is created.
28+
// "postCreateCommand": "",
29+
30+
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
31+
"remoteUser": "github",
32+
33+
"shutdownAction": "stopContainer",
34+
}

.devcontainer/settings.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
3+
<profiles>
4+
<profile>
5+
<id>private-repo-github</id>
6+
<repositories>
7+
<repository>
8+
<id>private-maven-on-github</id>
9+
<url>https://maven.pkg.github.com/genexuslabs/*</url>
10+
</repository>
11+
</repositories>
12+
</profile>
13+
</profiles>
14+
15+
<servers>
16+
<server>
17+
<id>private-maven-on-github</id>
18+
<username>${env.GITHUB_USERNAME}</username>
19+
<password>${env.GITHUB_TOKEN}</password>
20+
</server>
21+
</servers>
22+
23+
<activeProfiles>
24+
<activeProfile>private-repo-github</activeProfile>
25+
</activeProfiles>
26+
</settings>

.github/updatePOMVersion.sh

Lines changed: 0 additions & 56 deletions
This file was deleted.

.github/workflows/Build.yml

Lines changed: 141 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@ jobs:
2020
GIT_REF: ${{ github.ref }}
2121
GIT_SHA: ${{ github.sha }}
2222
POM_PATH: ./pom.xml
23-
VERSION_SCRIPT: ./github/updatePOMVersion.sh
2423

2524
runs-on: ubuntu-latest
2625

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+
2732
steps:
2833
- name: Checkout
2934
uses: actions/checkout@v2
@@ -34,52 +39,161 @@ jobs:
3439
uses: actions/setup-java@v1.4.3
3540
with:
3641
java-version: 1.9
42+
gpg-private-key: ${{ secrets.MAVEN_GPG_BUILDER_PRIVATE_KEY }}
43+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
3744

3845
- name: Setup Maven settings
3946
uses: whelk-io/maven-settings-xml-action@v14
4047
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+
]'
4355

4456
- name: Calculate build variables
4557
id: buildVariables
4658
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-
5359
LastCommitter=$(git log -1 --pretty=format:%an)
5460
CommitMessage=$(git log -1 --pretty=%B)
5561
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"
5964
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"
67122
else
68-
echo 'No version script specified. Will generate packages with the version on the POM file'
123+
newVersion="$pomMajorNumber.$pomMinorNumber.$pomPatchNumber"
69124
fi
70125
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"
74143
75144
- 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
77146

78147
- 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
80149

81150
- 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
83152

84153
- 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

Comments
 (0)