Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test #3

Merged
merged 3 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: ci

on:
push:
# branches: [ "master" ]
pull_request:
# branches: [ "master" ]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt install -y bats python3
- name: Test with Bats
shell: 'script -q -e -c "bash {0}"' # work around tty issues
env:
TERM: linux # fix tput for tty issue work around
run: |
cd tests
python3 -m http.server --bind 127.0.0.1 --directory ${GITHUB_WORKSPACE}/tests/mock &
sleep 1 # wait for server start
export BASE_URL="http://127.0.0.1:8000"
bats -t .
23 changes: 12 additions & 11 deletions bin/jenkinsOp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
SELECT=$1

JOB=core_ci
if [ ! -z "$3" ]
then
JOB=$3
if [ ! -z "$3" ]; then
JOB=$3
fi

JENKINS="jenkins.ivyteam.io"
URL="https://${JENKINS}/job/${JOB}/"
if [ -z "${BASE_URL}" ]; then
BASE_URL="https://${JENKINS}/"
fi
DIR="$( cd "$( dirname "$BASH_SOURCE" )" && pwd )"

ENV="$DIR/.env"
Expand All @@ -29,14 +30,14 @@ if ! [ -x "$(command -v curl)" ]; then
fi

getAvailableBranches(){
local JSON=$(curl -sS "${URL}/api/json?tree=jobs\[name\]")
local JSON=$(curl -sS "${BASE_URL}/job/${JOB}/api/json?tree=jobs\[name\]")
local BRANCHES="$(jsonField "${JSON}" "name" \
| sed -e 's|%2F|/|' )"
echo ${BRANCHES}
}

getAvailableTestJobs(){
local JSON=$(curl -sS "https://$JENKINS/api/json?tree=jobs\[name\]")
local JSON=$(curl -sS "${BASE_URL}/api/json?tree=jobs\[name\]")
local JOBS="$(jsonField "$JSON" "name" \
| grep 'core_product\|core_test\|core_ci\|core_json-schema' \
| sed -e 's|%2F|/|' )"
Expand All @@ -46,7 +47,7 @@ getAvailableTestJobs(){
getHealth(){
JOB="$1"
BRANCH="$2"
API_URI="https://${JENKINS}/job/${JOB}/job/${BRANCH}/api/json?tree=color"
API_URI="${BASE_URL}/job/${JOB}/job/${BRANCH}/api/json?tree=color"
JSON=$(curl -sS "${API_URI}")
COLOR=$(jsonField "${JSON}" "color")
colorToEmo $COLOR
Expand Down Expand Up @@ -95,13 +96,13 @@ triggerBuild(){
RUN_JOB=$1
BRANCH=$2

JOB_URL="https://$JENKINS/job/${RUN_JOB}/job/${BRANCH}"
JOB_URL="${BASE_URL}/job/${RUN_JOB}/job/${BRANCH}"
RESPONSE=$( requestBuild ${JOB_URL} )
echo -e "[ $( statusColor ${RESPONSE} ) ] @ $JOB_URL"

if [ "$RESPONSE" == 404 ] || [ "$RESPONSE" == 409 ] ; then
# job may requires a manual rescan to expose our new branch | isolate in sub bash to avoid conflicts!
SCANNED=$( rescanBranches "https://$JENKINS/job/$RUN_JOB/" 3>&1 1>&2 2>&3 )
SCANNED=$( rescanBranches "${BASE_URL}/job/$RUN_JOB/" 3>&1 1>&2 2>&3 )
# re-try
RESPONSE=$( requestBuild ${JOB_URL} )
echo -e "[ $( statusColor ${RESPONSE} ) ] @ $JOB_URL"
Expand All @@ -121,7 +122,7 @@ requestBuild(){

# get XSS preventention token
if [ -z ${CRUMB+x} ]; then
ISSUER_URI="https://${JENKINS}/crumbIssuer/api/xml"
ISSUER_URI="${BASE_URL}/crumbIssuer/api/xml"
CRUMB=$(curl -sS --basic -u "${JENKINS_USER}:${JENKINS_TOKEN}" "$ISSUER_URI") \
| grep -o -E '"crumb":"[^"]*' | sed -e 's|"crumb":"||'
export CRUMB="$CRUMB" #re-use for follow up requests
Expand Down Expand Up @@ -164,7 +165,7 @@ createView(){
BRANCH=$1
BRANCH_NAME=$( echo $BRANCH | sed -e 's|/|_|')
ISSUE_REGEX=$( echo ".*${BRANCH}" | sed -e 's|.*/|\.*|' )
MYVIEWS_URL="https://$JENKINS/user/${JENKINS_USER}/my-views"
MYVIEWS_URL="${BASE_URL}/user/${JENKINS_USER}/my-views"
curl -sS -k -X POST -u "$JENKINS_USER:$JENKINS_TOKEN" -H "$CRUMB" \
--form name="${BRANCH_NAME}" --form mode=hudson.model.ListView \
--form json="{'name': '${BRANCH_NAME}', 'mode': 'hudson.model.ListView', 'useincluderegex': 'on', 'includeRegex': '${ISSUE_REGEX}', 'recurse': 'true'}" \
Expand Down
File renamed without changes.
16 changes: 10 additions & 6 deletions bin/jenkins_test.bats → tests/jenkins_test.bats
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/usr/bin/env bats

setup(){
. ./jenkinsOp.sh
DIR=`pwd`
if ! [ -f "${DIR}/../bin/.env" ]; then
touch "${DIR}/../bin/.env"
fi
source "${DIR}/../bin/jenkinsOp.sh"
}

@test "parseJson" {
Expand All @@ -17,20 +21,20 @@ setup(){

@test "loadJobs" {
jobs=$(getAvailableTestJobs)
[[ " ${jobs[@]} " =~ "ivy-core_test-bpm-exec" ]]
[[ " ${jobs[@]} " =~ "ivy-core_ci-windows" ]]
[[ " ${jobs[@]} " != *ivy-core_techdoc* ]]
[[ " ${jobs[@]} " =~ "core_test-bpm-exec" ]]
[[ " ${jobs[@]} " =~ "core_ci-windows" ]]
[[ " ${jobs[@]} " != *core_techdoc* ]]
}

@test "connectability" {
URL="http://jenkins.ivyteam.oblivion"
BASE_URL="http://jenkins.ivyteam.oblivion"
rm -f /tmp/stderr
getAvailableBranches 2> /tmp/stderr
grep "Could not resolve host" /tmp/stderr
}

@test "health emoji" {
state=$(getHealth "ivy-core_ci" "master")
state=$(getHealth "core_ci" "master")
[[ "$state" == 🆗* ]]
}

Expand Down
Loading