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

Tmp 22.06 to master #22329

Merged
merged 14 commits into from
May 31, 2022
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
105 changes: 105 additions & 0 deletions .cicd/github.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/bash

TEST_RESULTS="test-results-core-web"
GITHUB="github.com"
GITHACK="raw.githack.com"
GITHUB_TEST_RESULTS_PATH="DotCMS/${TEST_RESULTS}"
DOT_CICD_TARGET="core-web"
GITHUB_USER="victoralfaro-dotcms"
GITHUB_USER_EMAIL="[email protected]"

if [[ $IS_PULL_REQUEST == true ]]; then
CURRENT_BRANCH=${HEAD_REF}
else
CURRENT_BRANCH=${GITHUB_REF##*/}
fi

DOT_CICD_PATH="./dotcicd"
OUTPUT_FOLDER="ui/karma_html"
export GITHUB_TEST_RESULTS_HOST_PATH="${GITHUB}/${GITHUB_TEST_RESULTS_PATH}"
export GITHUB_TEST_RESULTS_URL="https://${GITHUB_TEST_RESULTS_HOST_PATH}"
export GITHACK_TEST_RESULTS_URL="https://${GITHACK}/${GITHUB_TEST_RESULTS_PATH}"
export GITHUB_TEST_RESULTS_REPO="${GITHUB_TEST_RESULTS_URL}.git"
export GITHUB_TEST_RESULTS_BROWSE_URL="${GITHACK_TEST_RESULTS_URL}/${CURRENT_BRANCH}/projects/${DOT_CICD_TARGET}/${GITHUB_SHA::8}"
export GITHUB_TEST_RESULTS_REMOTE="https://${GITHUB_USER}:${GH_TOKEN}@${GITHUB_TEST_RESULTS_HOST_PATH}"
export GITHUB_TEST_RESULTS_REMOTE_REPO="https://${GITHUB_USER}:${GH_TOKEN}@${GITHUB_TEST_RESULTS_HOST_PATH}.git"


function existsOrCreateAndSwitch {
local results=${1}
if [[ ! -d $results ]]; then
mkdir -p $results
fi

cd $results
}

function gitConfig {
git config --global user.email "${GITHUB_USER_EMAIL}"
git config --global user.name "${GITHUB_USER}"
git config pull.rebase false
git config -l | grep user
}

function addResults {
local results=${1}
if [[ -z "$results" ]]; then
echo "Cannot add results since its empty, ignoring"
exit 1
fi

local targetFolder=${results}
mkdir -p ${targetFolder}
echo "Adding test results to: ${targetFolder}"
echo "output: ${OUTPUT_FOLDER}/* target:${targetFolder}"
cp -r "${GITHUB_WORKSPACE}/${OUTPUT_FOLDER}/." ${targetFolder}
}


function persistResults {
TEST_RESULTS_PATH=${DOT_CICD_PATH}/${TEST_RESULTS}
gitConfig

if [[ ! -d dotcicd/test-results ]]; then
echo "Cloning ${GITHUB_TEST_RESULTS_REPO} to ${TEST_RESULTS_PATH}"
git clone ${GITHUB_TEST_RESULTS_REPO} ${TEST_RESULTS_PATH}
fi

existsOrCreateAndSwitch ${TEST_RESULTS_PATH}/projects/${DOT_CICD_TARGET}

git fetch --all

remoteBranch=$(git ls-remote --heads ${GITHUB_TEST_RESULTS_REMOTE_REPO} ${CURRENT_BRANCH} | wc -l | tr -d '[:space:]')
localBranch=$(git show-ref --heads ${CURRENT_BRANCH} | wc -l | tr -d '[:space:]')

if [[ ${remoteBranch} == 1 ]]; then
if [[ ${localBranch} == 1 ]]; then
git checkout ${CURRENT_BRANCH}
else
echo "git checkout -b ${CURRENT_BRANCH} --track origin/${CURRENT_BRANCH}"
git checkout -b ${CURRENT_BRANCH} --track origin/${CURRENT_BRANCH}
fi
else
git checkout -b ${CURRENT_BRANCH}
fi

if [[ $? != 0 ]]; then
echo "Error checking out branch '${CURRENT_BRANCH}', continuing with master"
git pull origin master
else
if [[ ${remoteBranch} == 1 ]]; then
echo "git pull origin ${CURRENT_BRANCH}"
git pull origin ${CURRENT_BRANCH}
fi
fi

addResults ./${GITHUB_SHA::8}
git add .
git commit -m "Adding tests results for ${GITHUB_SHA::8} from ${CURRENT_BRANCH}"
git push ${GITHUB_TEST_RESULTS_REMOTE}
git status
}

function logResults {
echo "${GITHUB_TEST_RESULTS_BROWSE_URL}/report.html"
}
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# exclude package-lock from github diffs
package-lock.json -diff
4 changes: 4 additions & 0 deletions .github/actions/module-matcher/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
lib/
node_modules/
src/@types/
17 changes: 17 additions & 0 deletions .github/actions/module-matcher/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"plugins": ["@typescript-eslint", "github", "jest"],
"extends": ["plugin:github/typescript"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
},
"env": {
"node": true,
"es6": true,
"jest/globals": true
}
}
3 changes: 3 additions & 0 deletions .github/actions/module-matcher/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/
lib/
node_modules/
11 changes: 11 additions & 0 deletions .github/actions/module-matcher/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
}
38 changes: 38 additions & 0 deletions .github/actions/module-matcher/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: 'Workflow router'
description: 'Based on event (push or pull request) gather the involved commits to determine if workflow is allowed run'
author: 'victoralfaro-dotcms'
inputs:
current:
description: 'Current module'
required: true
modules:
description: 'Modules configuration, space delimited list of modules'
required: true
default: |
[
{
"module": "core",
"folder": ".",
"main": true
},
{
"module": "ui"
},
{
"module": "enterprise"
}
]
pull_request:
description: 'Pull request id'
required: false
default: ${{ github.event.number }}
commit:
description: 'Commit SHA'
required: true
default: ${{ github.sha }}
outputs:
module_found:
description: 'Boolean result: true for ound, otherwise false'
runs:
using: 'node16'
main: 'dist/index.js'
Loading