Skip to content

Commit 14f17c2

Browse files
jechagueanaiberta
andcommitted
Build refactoring (#307)
* Add GitHub Actions build for commit status and PR checks * Add CODEOWNERS for GitHub Actions workflows * Add dispatch for internal build * Add missing 'beta-corona' branch * Remove unused 'NexusURL' variable from build script * Remove used variable * Fix version script execution permission on Linux runners * Stop adding the short commit SHA on builds from the beta branch This mechanism was intended for when using the result of PR builds but was where never really used. * Consider all branches in the POM version script * Update .github/updatePOMVersion.sh Co-authored-by: Ana Berta <[email protected]>
1 parent 0396c35 commit 14f17c2

File tree

5 files changed

+243
-0
lines changed

5 files changed

+243
-0
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.github/ @genexuslabs/workflow-codeowners

.github/updatePOMVersion.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
function ReadPomMajorMinorNumbers {
4+
currentVersion=$(sed -n '/<version>.*<\/version>/ s/<version>\(.*\)<\/version>/\1/p' pom.xml)
5+
semVerComponents=( ${currentVersion//-/ } )
6+
semVerComponents=${semVerComponents[0]}
7+
semVerComponents=( ${semVerComponents//./ } )
8+
9+
pomMajorNumber=${semVerComponents[0]}
10+
pomMinorNumber=${semVerComponents[1]}
11+
pomPatchNumber="$(git rev-list --count origin/master..)"
12+
}
13+
14+
ReadPomMajorMinorNumbers
15+
16+
branch="$(git symbolic-ref --short HEAD)"
17+
case "$branch" in
18+
beta)
19+
echo "## Is BETA branch, add +100 to major number"
20+
21+
pomMajorNumber=$(expr $pomMajorNumber + 100)
22+
23+
newVersion="$pomMajorNumber.$pomMinorNumber-SNAPSHOT"
24+
;;
25+
26+
beta-corona)
27+
echo "## Is BETA-CORONA branch, use fixed version"
28+
29+
pomMajorNumber="116"
30+
pomMinorNumber="0"
31+
32+
33+
newVersion="$pomMajorNumber.$pomMinorNumber.$pomPatchNumber"
34+
;;
35+
36+
release-*)
37+
echo "## Is RELEASE/UPGRADE branch, use pom.xml version modifing patch number"
38+
39+
newVersion="$pomMajorNumber.$pomMinorNumber.$pomPatchNumber"
40+
;;
41+
42+
*)
43+
echo "## Is MASTER or feature branch, use pom.xml version"
44+
;;
45+
esac
46+
47+
if [[ -n "${newVersion}" ]]; then
48+
echo "## Updating pom.xml version to: $newVersion"
49+
mvn -B versions:set -DgenerateBackupPoms=false -DnewVersion="$newVersion"
50+
fi
51+
52+
# Add current commit's SHA to pom.xml
53+
GIT_HASH=$(git rev-parse HEAD)
54+
scmversion="<vcm_hash>$GIT_HASH</vcm_hash>"
55+
scmv=$(echo $scmversion | sed 's/\//\\\//g')
56+
sed -i "/<\/properties>/ s/.*/${scmv}\n&/" pom.xml

.github/workflows/Build.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Build
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- 'master'
7+
- 'release-*'
8+
push:
9+
branches:
10+
- 'master'
11+
- 'beta'
12+
- 'release-*'
13+
- 'beta-corona'
14+
15+
jobs:
16+
build:
17+
name: Build
18+
env:
19+
GIT_REF: ${{ github.ref }}
20+
GIT_SHA: ${{ github.sha }}
21+
POM_PATH: ./pom.xml
22+
VERSION_SCRIPT: ./github/updatePOMVersion.sh
23+
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v2
29+
with:
30+
fetch-depth: 0
31+
32+
- name: Setup Java JDK
33+
uses: actions/[email protected]
34+
with:
35+
java-version: 1.9
36+
37+
- name: Calculate build variables
38+
id: buildVariables
39+
run: |
40+
if ! [[ "$GIT_REF" =~ 'release-[0-9]?\.[0-9]?$' ]]; then
41+
CommitNumber=$(git rev-list --count HEAD)
42+
else
43+
CommitNumber=$(git rev-list --count origin/master..)
44+
fi
45+
46+
LastCommitter=$(git log -1 --pretty=format:%an)
47+
CommitMessage=$(git log -1 --pretty=%B)
48+
49+
echo "::set-output name=CommitNumber::$CommitNumber"
50+
echo "::set-output name=LastCommitter::$LastCommitter"
51+
echo "::set-output name=CommitMessage::$CommitMessage"
52+
53+
- name: Update POM version
54+
id: POMVersion
55+
run: |
56+
script="$VERSION_SCRIPT"
57+
if [ -f "$script" ]; then
58+
echo "Executing version script at: $script"
59+
sh "$script"
60+
else
61+
echo 'No version script specified. Will generate packages with the version on the POM file'
62+
fi
63+
64+
finalPOMVersion=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout --file $POM_PATH)
65+
echo "Project version: $finalPOMVersion"
66+
echo "::set-output name=finalPOMVersion::$finalPOMVersion"
67+
68+
- name: Validate build
69+
run: mvn -B validate --file $POM_PATH
70+
71+
- name: Build
72+
run: mvn -B compile --file $POM_PATH
73+
74+
- name: Test
75+
run: mvn -B test --file $POM_PATH
76+
77+
- name: Package
78+
run: mvn -B package --file $POM_PATH

.github/workflows/ProcessCommit.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Process commit
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches:
6+
- 'master'
7+
- 'beta'
8+
- 'beta-corona'
9+
- 'release-*'
10+
ignore-paths:
11+
- '*.md'
12+
13+
jobs:
14+
dispatchWorkflow:
15+
name: Dispatch build
16+
runs-on: [ubuntu-latest]
17+
18+
steps:
19+
- name: Dispatch Workflow
20+
run: >
21+
curl -X POST
22+
-H 'Accept: application/vnd.github.v3+json'
23+
-H 'Authorization: token ${{ secrets.SECURE_TOKEN }}'
24+
--silent --show-error --fail
25+
${{ secrets.BUILD_WORKFLOW_DISPATCH }}
26+
-d '{
27+
"ref":"main",
28+
"inputs": {
29+
"repository": "${{ github.repository }}",
30+
"ref": "${{ github.ref }}",
31+
"sha": "${{ github.sha }}",
32+
"build-file": "pom.xml",
33+
"version-script": ".github/updatePOMVersion.sh"
34+
}
35+
}'

.github/workflows/codeql-analysis.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
# ******** NOTE ********
12+
13+
name: "CodeQL"
14+
15+
on:
16+
push:
17+
branches: [ master, beta, beta-corona, release-* ]
18+
pull_request:
19+
# The branches below must be a subset of the branches above
20+
branches: [ master ]
21+
schedule:
22+
- cron: '34 20 * * 0'
23+
24+
jobs:
25+
analyze:
26+
name: Analyze
27+
runs-on: ubuntu-latest
28+
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
language: [ 'java' ]
33+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
34+
# Learn more...
35+
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
36+
37+
steps:
38+
- name: Checkout repository
39+
uses: actions/checkout@v2
40+
41+
# Initializes the CodeQL tools for scanning.
42+
- name: Initialize CodeQL
43+
uses: github/codeql-action/init@v1
44+
with:
45+
languages: ${{ matrix.language }}
46+
# If you wish to specify custom queries, you can do so here or in a config file.
47+
# By default, queries listed here will override any specified in a config file.
48+
# Prefix the list here with "+" to use these queries and those in the config file.
49+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
50+
51+
- name: Setup Java JDK
52+
uses: actions/[email protected]
53+
with:
54+
java-version: 1.9
55+
56+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
57+
# If this step fails, then you should remove it and run the build manually (see below)
58+
- name: Autobuild
59+
uses: github/codeql-action/autobuild@v1
60+
61+
# ℹ️ Command-line programs to run using the OS shell.
62+
# 📚 https://git.io/JvXDl
63+
64+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
65+
# and modify them (or add more) to build your code if your project
66+
# uses a compiled language
67+
68+
#- run: |
69+
# make bootstrap
70+
# make release
71+
72+
- name: Perform CodeQL Analysis
73+
uses: github/codeql-action/analyze@v1

0 commit comments

Comments
 (0)