Skip to content

Commit aa28a8d

Browse files
committed
[GHA] GitHub Actions introduced to this repo
1 parent 6c9c7c3 commit aa28a8d

File tree

4 files changed

+291
-195
lines changed

4 files changed

+291
-195
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
1-
#!/bin/bash
1+
#!/bin/bash -e
2+
set +x
23

34
function fatal {
4-
comment_on_pull "Tests failed ($BUILD_URL): $1"
5-
echo "$1"; exit 1
5+
echo "$1"
6+
exit 1
67
}
78

8-
set -x
9-
[ $WORKSPACE ] || fatal "please set WORKSPACE to the quickstarts directory"
9+
function which_java {
10+
type -p java 2>&1 > /dev/null
11+
if [ $? = 0 ]; then
12+
_java=java
13+
elif [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
14+
_java="$JAVA_HOME/bin/java"
15+
else
16+
unset _java
17+
fi
1018

11-
function comment_on_pull
12-
{
13-
if [ "$COMMENT_ON_PULL" = "" ]; then return; fi
19+
if [[ "$_java" ]]; then
20+
version=$("$_java" -version 2>&1 | grep -oP 'version "?(1\.)?\K\d+' || true)
21+
echo $version
22+
fi
23+
}
1424

15-
PULL_NUMBER=$(echo $GIT_BRANCH | awk -F 'pull' '{ print $2 }' | awk -F '/' '{ print $2 }')
16-
if [ "$PULL_NUMBER" != "" ]
17-
then
18-
JSON="{ \"body\": \"$1\" }"
19-
curl -d "$JSON" -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/$GIT_ACCOUNT/$GIT_REPO/issues/$PULL_NUMBER/comments
20-
else
21-
echo "Not a pull request, so not commenting"
22-
fi
25+
function min_java {
26+
MIN_JAVA=17
27+
_jdk=`which_java`
28+
if [ "$_jdk" -lt "$MIN_JAVA" ]; then
29+
fatal "Narayana does not support JDKs less than $MIN_JAVA"
30+
fi
2331
}
2432

2533
# Expects one argument as an integer number and adjust it
@@ -36,62 +44,17 @@ function timeout_adjust {
3644
}
3745

3846
function int_env {
47+
min_java
48+
3949
cd $WORKSPACE
40-
export GIT_ACCOUNT=jbosstm
41-
export GIT_REPO=quickstart
4250
export MFACTOR=${MFACTOR:-1}
4351
export -f timeout_adjust || echo "Function timeout_adjust won't be used in the subshells as it can't be exported"
4452
NARAYANA_REPO=${NARAYANA_REPO:-jbosstm}
4553
NARAYANA_BRANCH="${NARAYANA_BRANCH:-main}"
4654
QUICKSTART_NARAYANA_VERSION=${QUICKSTART_NARAYANA_VERSION:-7.3.4.Final-SNAPSHOT}
4755
REDUCE_SPACE=${REDUCE_SPACE:-0}
4856

49-
[ $NARAYANA_CURRENT_VERSION ] || export NARAYANA_CURRENT_VERSION="7.3.4.Final-SNAPSHOT"
50-
51-
PULL_NUMBER=$(echo $GIT_BRANCH | awk -F 'pull' '{ print $2 }' | awk -F '/' '{ print $2 }')
52-
if [ "$PULL_NUMBER" != "" ]
53-
then
54-
PULL_DESCRIPTION=$(curl -H "Authorization: token $GITHUB_TOKEN" -s https://api.github.com/repos/$GIT_ACCOUNT/$GIT_REPO/pulls/$PULL_NUMBER)
55-
if [[ $PULL_DESCRIPTION =~ "\"state\": \"closed\"" ]]; then
56-
echo "pull closed"
57-
exit 0
58-
fi
59-
fi
60-
_jdk=`which_java`
61-
if [ "$_jdk" -lt 17 ]; then
62-
fatal "Narayana does not support JDKs less than 17"
63-
fi
64-
}
65-
function which_java {
66-
type -p java 2>&1 > /dev/null
67-
if [ $? = 0 ]; then
68-
_java=java
69-
elif [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
70-
_java="$JAVA_HOME/bin/java"
71-
else
72-
unset _java
73-
fi
74-
75-
if [[ "$_java" ]]; then
76-
version=$("$_java" -version 2>&1 | awk -F '"' '/version/ {print $2}')
77-
78-
if [[ $version = 17* ]]; then
79-
echo 17
80-
elif [[ $version = 11* ]]; then
81-
echo 11
82-
fi
83-
fi
84-
}
85-
function rebase_quickstart_repo {
86-
cd $WORKSPACE
87-
git remote add upstream https://github.com/jbosstm/quickstart.git
88-
export BRANCHPOINT=main
89-
git branch $BRANCHPOINT origin/$BRANCHPOINT
90-
git pull --rebase --ff-only origin $BRANCHPOINT
91-
if [ $? -ne 0 ]; then
92-
comment_on_pull "Narayana rebase on $BRANCHPOINT failed. Please rebase it manually: $BUILD_URL"
93-
exit -1
94-
fi
57+
[ $NARAYANA_CURRENT_VERSION ] || export NARAYANA_CURRENT_VERSION="7.3.4.Final-SNAPSHOT"
9558
}
9659

9760
function build_narayana {
@@ -115,21 +78,16 @@ function build_narayana {
11578
fi
11679

11780
if [ $? != 0 ]; then
118-
comment_on_pull "Checkout failed: $BUILD_URL";
81+
echo "Checkout failed: $BUILD_URL";
11982
exit -1
12083
fi
12184
cd narayana
12285
./build.sh clean install -B -DskipTests -Pcommunity
12386

12487
if [ $? != 0 ]; then
125-
comment_on_pull "Narayana build failed: $BUILD_URL";
88+
echo "Narayana build failed: $BUILD_URL";
12689
exit -1
12790
fi
128-
if [ $REDUCE_SPACE = 1 ]; then
129-
echo "Deleting check out - assuming all artifacts are in the .m2"
130-
cd ..
131-
rm -rf narayana
132-
fi
13391
}
13492

13593
function build_narayana_lra {
@@ -154,7 +112,7 @@ function build_narayana_lra {
154112
fi
155113

156114
if [ $? != 0 ]; then
157-
comment_on_pull "Checkout failed: $BUILD_URL";
115+
echo "Checkout failed: $BUILD_URL";
158116
exit -1
159117
fi
160118
cd lra
@@ -163,13 +121,17 @@ function build_narayana_lra {
163121
cd ..
164122

165123
if [ $? != 0 ]; then
166-
comment_on_pull "Narayana LRA build failed: $BUILD_URL";
124+
echo "Narayana LRA build failed: $BUILD_URL";
167125
exit -1
168126
fi
169127
}
170128

171129
function download_and_update_as {
172-
[ ! -z "${WILDFLY_RELEASE_VERSION}" ] || fatal "No WILDFLY_RELEASE_VERSION specified"
130+
if [ -z "${WILDFLY_RELEASE_VERSION}" ]; then
131+
WILDFLY_RELEASE_VERSION=$(curl -sL https://api.github.com/repos/wildfly/wildfly/releases/latest | jq -r ".tag_name")
132+
[ $? -eq 0 ] ||fatal "No WILDFLY_RELEASE_VERSION specified"
133+
echo "version=$WILDFLY_RELEASE_VERSION"
134+
fi
173135

174136
cd $WORKSPACE
175137

@@ -219,16 +181,10 @@ function download_and_update_as {
219181
[ $? -eq 0 ] || fatal "Could not copy narayana-lra-${LRA_CURRENT_VERSION}.jar"
220182
cp ~/.m2/repository/org/jboss/narayana/lra/lra-proxy-api/${LRA_CURRENT_VERSION}/lra-proxy-api-${LRA_CURRENT_VERSION}.jar wildfly-${WILDFLY_RELEASE_VERSION}/modules/system/layers/base/org/jboss/narayana/lra/lra-participant/main/lra-proxy-api-*.jar
221183
[ $? -eq 0 ] || fatal "Could not copy lra-proxy-api-${LRA_CURRENT_VERSION}.jar"
222-
223-
if [ $REDUCE_SPACE = 1 ]; then
224-
echo "Deleting wildfly-${WILDFLY_RELEASE_VERSION}.zip to reduce disk usage"
225-
rm wildfly-${WILDFLY_RELEASE_VERSION}.zip
226-
fi
227-
184+
228185
export JBOSS_HOME=${WORKSPACE}/wildfly-${WILDFLY_RELEASE_VERSION}
229186

230187
init_jboss_home
231-
232188
cd $WORKSPACE
233189
}
234190

@@ -248,30 +204,25 @@ function run_quickstarts {
248204
cd $WORKSPACE
249205
echo Running quickstarts
250206
./build.sh -B clean install -fae -DskipX11Tests=true -Dversion.narayana=$QUICKSTART_NARAYANA_VERSION -Dversion.org.jboss.narayana.lra=$LRA_CURRENT_VERSION
251-
252-
if [ $? != 0 ]; then
253-
comment_on_pull "Pull failed: $BUILD_URL";
254-
exit -1
255-
else
256-
comment_on_pull "Pull passed: $BUILD_URL"
257-
fi
258207
}
259208

209+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
210+
WORKSPACE=$(cd "$SCRIPT_DIR/../.." && pwd)
211+
echo "WORKSPACE is set to: ${WORKSPACE}"
212+
260213
int_env
261214
functionCalled=false
262215
if [ $# -eq 1 ]; then
263-
if [ "$1" == "download_and_update_as" ]; then
264-
download_and_update_as
265-
functionCalled=true
266-
fi
216+
if [ "$1" == "download_and_update_as" ]; then
217+
download_and_update_as
218+
functionCalled=true
219+
fi
267220
fi
268221
if [ $functionCalled = false ]; then
269-
comment_on_pull "Started testing this pull request: $BUILD_URL"
270-
rebase_quickstart_repo
271-
build_narayana
272-
build_narayana_lra
273-
if [ -z "$JBOSS_HOME" ]; then
274-
download_and_update_as "$@"
275-
fi
276-
run_quickstarts
222+
build_narayana
223+
build_narayana_lra
224+
if [ -z "$JBOSS_HOME" ]; then
225+
download_and_update_as "$@"
226+
fi
227+
run_quickstarts
277228
fi

.github/workflows/main.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: main
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
jdk_version:
7+
description: 'JDK version'
8+
required: true
9+
type: string
10+
pull_request_repo:
11+
description: 'Repository to check out'
12+
required: true
13+
type: string
14+
default: 'jbosstm/narayana'
15+
pull_request_ref:
16+
description: 'Branch or commit to test'
17+
required: true
18+
type: string
19+
environment_variables:
20+
description: 'Environment variables'
21+
required: false
22+
type: string
23+
default: '{}'
24+
25+
# Only run the latest job
26+
concurrency:
27+
group: 'main @ ${{ github.workflow }} @ ${{ github.head_ref || github.ref }} @ jdk${{ inputs.jdk_version }}'
28+
cancel-in-progress: true
29+
30+
jobs:
31+
main-test:
32+
name: Testing quickstart with JDK ${{ inputs.jdk_version }}
33+
timeout-minutes: 120
34+
runs-on: ubuntu-latest
35+
36+
steps:
37+
- name: Load Dynamic Environment Variables
38+
uses: actions/github-script@v7
39+
if: ${{ inputs.environment_variables != '' && inputs.environment_variables != '{}' }}
40+
env:
41+
ENV_JSON: ${{ inputs.environment_variables }}
42+
with:
43+
script: |
44+
const envs = JSON.parse(process.env.ENV_JSON);
45+
for (const [key, value] of Object.entries(envs)) {
46+
core.exportVariable(key, value);
47+
core.info(`Set ${key}=${value}`);
48+
}
49+
50+
- name: Log run context
51+
run: |
52+
echo "Triggered by: ${{ github.event_name }}"
53+
echo "Repository: ${{ inputs.pull_request_repo || github.repository }}"
54+
echo "Branch/Ref: ${{ inputs.pull_request_ref || github.ref }}"
55+
56+
- name: Checkout code
57+
uses: actions/checkout@v5
58+
with:
59+
repository: '${{ inputs.pull_request_repo || github.repository }}'
60+
ref: ${{ inputs.pull_request_ref || github.ref }}
61+
62+
- name: Set up JDK ${{ inputs.jdk_version }}
63+
uses: actions/setup-java@v5
64+
with:
65+
distribution: temurin
66+
java-version: ${{ inputs.jdk_version }}
67+
cache: 'maven'
68+
69+
- name: Testing all quickstart
70+
id: main
71+
run: |
72+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
73+
git config --global user.name "github-actions[bot]"
74+
./.github/scripts/quickstart.sh
75+
76+
- uses: actions/upload-artifact@v4
77+
if: ${{ failure() && steps.main.conclusion == 'failure' || cancelled() && steps.main.conclusion == 'cancelled' }}
78+
with:
79+
retention-days: 30
80+
name: main-logs-jdk${{ inputs.jdk_version }}
81+
path: |
82+
**/*.*log*
83+
**/target/*surefire-reports*/**
84+
**/target/*failsafe-reports*/**
85+
if-no-files-found: warn

0 commit comments

Comments
 (0)