Skip to content

Commit 350b014

Browse files
authored
Add GitHub Actions CI build (#434)
* Add GHA CI build (Java 11/17) * Add GHA build status badge * Update required Java version range used by the enforcer plugin Signed-off-by: Wouter Born <github@maindrain.net>
1 parent 3bbf205 commit 350b014

4 files changed

Lines changed: 134 additions & 2 deletions

File tree

.github/scripts/maven-build

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
BUILD_LOG=build.log
4+
5+
ARGUMENTS="clean verify -B -T 1.5C -U"
6+
if [ $# -ge 1 ]; then
7+
ARGUMENTS=$@
8+
fi
9+
10+
function print_reactor_summary() {
11+
local start_end=$(grep -anE "\[INFO\] \\-{70,}" "$BUILD_LOG" | tail -n4 | cut -f1 -d: | sed -e 1b -e '$!d' | xargs)
12+
local start=$(awk '{print $1}' <<< $start_end)
13+
local end=$(awk '{print $2}' <<< $start_end)
14+
cat "$BUILD_LOG" | sed -n "${start},${end}p" | sed 's/\[INFO\] //'
15+
}
16+
17+
function mvnp() {
18+
set -o pipefail # exit build with error when pipes fail
19+
local reactor_size=$(find -name "pom.xml" | grep -vE '/src/|/target/' | wc -l)
20+
local padding=$(bc -l <<< "scale=0;2*(l($reactor_size)/l(10)+1)")
21+
local command=(mvn $@)
22+
exec "${command[@]}" 2>&1 | # execute, redirect stderr to stdout
23+
tee "$BUILD_LOG" | # write output to log
24+
stdbuf -oL grep -aE '^\[INFO\] Building .+ \[.+\]$' | # filter progress
25+
stdbuf -o0 sed -uE 's/^\[INFO\] Building (.*[^ ])[ ]+\[([0-9]+\/[0-9]+)\]$/\2| \1/' | # prefix project name with progress
26+
stdbuf -o0 sed -e :a -e "s/^.\{1,${padding}\}|/ &/;ta" # right align progress with padding
27+
}
28+
29+
function build_all() {
30+
echo
31+
echo "Building all projects"
32+
echo
33+
echo "+ mvn $ARGUMENTS"
34+
echo
35+
36+
mvnp $ARGUMENTS
37+
38+
status=$?
39+
echo
40+
41+
if [ $status -eq 0 ]; then
42+
print_reactor_summary
43+
else
44+
tail -n 2000 "$BUILD_LOG"
45+
fi
46+
47+
exit $status
48+
}
49+
50+
mvn -v
51+
build_all

.github/workflows/ci-build.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
paths-ignore:
8+
- '.github/**/*.md'
9+
pull_request:
10+
branches:
11+
- 'main'
12+
paths-ignore:
13+
- '.github/**/*.md'
14+
workflow_dispatch:
15+
16+
jobs:
17+
build:
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
java: [ '11', '17' ]
22+
maven: [ '3.8.4']
23+
os: [ 'ubuntu-20.04' ]
24+
name: Build (Java ${{ matrix.java }}, ${{ matrix.os }})
25+
runs-on: ${{ matrix.os }}
26+
steps:
27+
- name: Checkout
28+
if: github.head_ref == ''
29+
uses: actions/checkout@v2
30+
31+
- name: Checkout merge
32+
if: github.head_ref != ''
33+
uses: actions/checkout@v2
34+
with:
35+
ref: refs/pull/${{github.event.pull_request.number}}/merge
36+
37+
- name: Set up Cache
38+
uses: actions/cache@v2
39+
with:
40+
path: |
41+
~/.m2/repository
42+
!~/.m2/repository/org/openhab
43+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
44+
restore-keys: |
45+
${{ runner.os }}-maven-
46+
47+
- name: Set up Java ${{ matrix.java }}
48+
uses: actions/setup-java@v2
49+
with:
50+
distribution: 'zulu'
51+
java-version: ${{ matrix.java }}
52+
53+
- name: Set up Maven ${{ matrix.maven }}
54+
uses: stCarolas/setup-maven@v4.2
55+
with:
56+
maven-version: ${{ matrix.maven }}
57+
58+
- name: Build
59+
id: build
60+
run: './.github/scripts/maven-build'
61+
env:
62+
MAVEN_OPTS: >-
63+
-Xmx2g
64+
-Dmaven.wagon.http.retryHandler.count=5
65+
-Dmaven.wagon.httpconnectionManager.ttlSeconds=25
66+
-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
67+
68+
- name: Upload Build Log
69+
if: ${{ always() && ((steps.build.outcome == 'success') || (steps.build.outcome == 'failure')) }}
70+
uses: actions/upload-artifact@v2
71+
with:
72+
name: build-log-java-${{ matrix.java }}-${{ matrix.os }}
73+
path: build.log
74+
75+
- name: Upload SAT Summary Report
76+
if: ${{ always() && ((steps.build.outcome == 'success') || (steps.build.outcome == 'failure')) }}
77+
uses: actions/upload-artifact@v2
78+
with:
79+
name: sat-summary-report
80+
path: target/summary_report.html

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Static Code Analysis Tool
22

3-
[![Build Status](https://ci.openhab.org/job/static-code-analysis/badge/icon)](https://ci.openhab.org/job/static-code-analysis/)
3+
[![GitHub Actions Build Status](https://github.com/openhab/static-code-analysis/actions/workflows/ci-build.yml/badge.svg?branch=main)](https://github.com/openhab/static-code-analysis/actions/workflows/ci-build.yml)
4+
[![Jenkins Build Status](https://ci.openhab.org/job/static-code-analysis/badge/icon)](https://ci.openhab.org/job/static-code-analysis/)
45
[![EPL-2.0](https://img.shields.io/badge/license-EPL%202-green.svg)](https://opensource.org/licenses/EPL-2.0)
56
[![Bountysource](https://www.bountysource.com/badge/tracker?tracker_id=56481698)](https://www.bountysource.com/teams/openhab/issues?tracker_ids=56481698)
67

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@
479479
<configuration>
480480
<rules>
481481
<requireJavaVersion>
482-
<version>[11.0,12.0)</version>
482+
<version>[11.0,18.0)</version>
483483
</requireJavaVersion>
484484
</rules>
485485
</configuration>

0 commit comments

Comments
 (0)