-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3276241
commit 1f101cf
Showing
1 changed file
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
name: 'html-reporter-github-pages' | ||
description: 'HTML Test Results with history' | ||
author: 'Pavan Mudigonda' | ||
branding: | ||
icon: 'layout' | ||
color: 'green' | ||
inputs: | ||
workflow_id: | ||
description: 'Workflow File NAME' | ||
required: true | ||
default: '' | ||
token: | ||
description: 'Github Token' | ||
required: true | ||
default: ${{ github.token }} | ||
test_results: | ||
description: 'test result data dir' | ||
required: true | ||
gh_pages: | ||
description: 'Folder with gh-pages branch' | ||
required: true | ||
default: 'gh-pages' | ||
results_history: | ||
description: 'Folder for allure history' | ||
required: true | ||
default: 'results-history' | ||
subfolder: | ||
description: 'subfolder' | ||
required: false | ||
default: '' | ||
keep_reports: | ||
description: 'Keep X last reports' | ||
required: false | ||
default: '20' | ||
github_run_num: | ||
description: 'GitHub Actions build number' | ||
required: true | ||
default: ${{ github.run_number }} | ||
github_run_id: | ||
description: 'GitHub Actions run id' | ||
required: true | ||
default: ${{ github.run_id }} | ||
github_repo: | ||
description: 'GitHub repository' | ||
required: true | ||
github_repo_owner: | ||
description: 'GitHub repository owner' | ||
required: true | ||
default: ${{ github.repository_owner }} | ||
report_url: | ||
description: 'Use a custom URL instead of *.github.io' | ||
required: false | ||
default: '' | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Run Script | ||
shell: bash | ||
run: | | ||
cat > index-template.html <<EOF | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | ||
<title>Test Results</title> | ||
<style type="text/css"> | ||
BODY { font-family : monospace, sans-serif; color: black;} | ||
P { font-family : monospace, sans-serif; color: black; margin:0px; padding: 0px;} | ||
A:visited { text-decoration : none; margin : 0px; padding : 0px;} | ||
A:link { text-decoration : none; margin : 0px; padding : 0px;} | ||
A:hover { text-decoration: underline; background-color : yellow; margin : 0px; padding : 0px;} | ||
A:active { margin : 0px; padding : 0px;} | ||
.VERSION { font-size: small; font-family : arial, sans-serif; } | ||
.NORM { color: black; } | ||
.FIFO { color: purple; } | ||
.CHAR { color: yellow; } | ||
.DIR { color: blue; } | ||
.BLOCK { color: yellow; } | ||
.LINK { color: aqua; } | ||
.SOCK { color: fuchsia;} | ||
.EXEC { color: green; } | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Test Results</h1><p> | ||
<a href=".">.</a><br> | ||
EOF | ||
mkdir -p ./${INPUT_GH_PAGES} | ||
mkdir -p ./${INPUT_RESULTS_HISTORY} | ||
cp -r ./${INPUT_GH_PAGES}/. ./${INPUT_RESULTS_HISTORY} | ||
REPOSITORY_OWNER_SLASH_NAME=${INPUT_GITHUB_REPO} | ||
REPOSITORY_NAME=${REPOSITORY_OWNER_SLASH_NAME##*/} | ||
GITHUB_PAGES_WEBSITE_URL="https://${INPUT_GITHUB_REPO_OWNER}.github.io/${REPOSITORY_NAME}" | ||
#echo "Github pages url $GITHUB_PAGES_WEBSITE_URL" | ||
if [[ ${INPUT_SUBFOLDER} != '' ]]; then | ||
INPUT_RESUTLS_HISTORY="${INPUT_RESULTS_HISTORY}/${INPUT_SUBFOLDER}" | ||
INPUT_GH_PAGES="${INPUT_GH_PAGES}/${INPUT_SUBFOLDER}" | ||
echo "NEW results history folder ${INPUT_RESULTS_HISTORY}" | ||
mkdir -p ./${INPUT_RESULTS_HISTORY} | ||
GITHUB_PAGES_WEBSITE_URL="${GITHUB_PAGES_WEBSITE_URL}/${INPUT_SUBFOLDER}" | ||
echo "NEW github pages url ${GITHUB_PAGES_WEBSITE_URL}" | ||
fi | ||
if [[ ${INPUT_REPORT_URL} != '' ]]; then | ||
GITHUB_PAGES_WEBSITE_URL="${INPUT_REPORT_URL}" | ||
echo "Replacing github pages url with user input. NEW url ${GITHUB_PAGES_WEBSITE_URL}" | ||
fi | ||
COUNT=$( ( ls ./${INPUT_RESULTS_HISTORY} | wc -l ) ) | ||
echo "count folders in results-history: ${COUNT}" | ||
echo "keep reports count ${INPUT_KEEP_REPORTS}" | ||
INPUT_KEEP_REPORTS=$((INPUT_KEEP_REPORTS+1)) | ||
echo "if ${COUNT} > ${INPUT_KEEP_REPORTS}" | ||
if (( COUNT > INPUT_KEEP_REPORTS )); then | ||
cd ./${INPUT_RESULTS_HISTORY} | ||
echo "remove index.html last-history" | ||
rm index.html last-history -rv | ||
echo "remove old reports" | ||
ls | sort -n | head -n -$((${INPUT_KEEP_REPORTS}-2)) | xargs rm -rv; | ||
cd ${GITHUB_WORKSPACE} | ||
fi | ||
cat index-template.html > ./${INPUT_RESULTS_HISTORY}/index.html | ||
echo "├── <a href="./${INPUT_GITHUB_RUN_NUM}/index.html">Latest Test Results - RUN ID: ${INPUT_GITHUB_RUN_NUM}</a><br>" >> ./${INPUT_RESULTS_HISTORY}/index.html; | ||
ls -l ./${INPUT_RESULTS_HISTORY} | grep "^d" | sort -nr | awk -F' ' '{print $9;}' | while read line; | ||
do | ||
curl \ | ||
--silent \ | ||
--location \ | ||
--request GET \ | ||
--header 'Accept: application/vnd.github.v4+json' \ | ||
--header 'Content-Type: application/json' \ | ||
--header "Authorization: token ${INPUT_TOKEN}" \ | ||
--header 'cache-control: no-cache' \ | ||
"https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/workflows/${INPUT_WORKFLOW_ID}/runs" > temp.json; | ||
CREATED_AT=$(cat temp.json | jq --argjson "RUN_NUM" "${line}" -r '.workflow_runs[] | select(.run_number==$RUN_NUM) | .created_at'); | ||
NEW_CREATED_AT=`sed -e 's/T/ /' -e 's/Z/ UTC/' <<<"$CREATED_AT"` | ||
echo "├── <a href="./"${line}"/">RUN ID: "${line}" - "${NEW_CREATED_AT}" </a><br>" >> ./${INPUT_RESULTS_HISTORY}/index.html; | ||
done; | ||
echo "</html>" >> ./${INPUT_RESULTS_HISTORY}/index.html; | ||
# cat ./${INPUT_RESULTS_HISTORY}/index.html | ||
#echo "executor.json" | ||
echo '{"name":"GitHub Actions","type":"github","reportName":"Test Results Report with history",' > executor.json | ||
echo "\"url\":\"${GITHUB_PAGES_WEBSITE_URL}\"," >> executor.json # ??? | ||
echo "\"reportUrl\":\"${GITHUB_PAGES_WEBSITE_URL}/${INPUT_GITHUB_RUN_NUM}/\"," >> executor.json | ||
echo "\"buildUrl\":\"https://github.com/${INPUT_GITHUB_REPO}/actions/runs/${INPUT_GITHUB_RUN_ID}\"," >> executor.json | ||
echo "\"buildName\":\"GitHub Actions Run #${INPUT_GITHUB_RUN_ID}\",\"buildOrder\":\"${INPUT_GITHUB_RUN_NUM}\"}" >> executor.json | ||
#cat executor.json | ||
mv ./executor.json ./${INPUT_TEST_RESULTS} | ||
#environment.properties | ||
echo "URL=${GITHUB_PAGES_WEBSITE_URL}" >> ./${INPUT_TEST_RESULTS}/environment.properties | ||
echo "keep test results history from ${INPUT_GH_PAGES}/last-history to ${INPUT_TEST_RESULTS}/history" | ||
mkdir -p ${INPUT_TEST_RESULTS}/history | ||
cp -R ./${INPUT_GH_PAGES}/last-history/. ./${INPUT_TEST_RESULTS}/history | ||
echo "generating report from ${INPUT_TEST_RESULTS} to ${INPUT_TEST_REPORT} ..." | ||
ls -l ${INPUT_TEST_RESULTS} | ||
#echo "listing report directory ..." | ||
echo "copy test-results to ${INPUT_RESULTS_HISTORY}/${INPUT_GITHUB_RUN_NUM}" | ||
cp -R ./${INPUT_TEST_RESULTS}/. ./${INPUT_RESULTS_HISTORY}/${INPUT_GITHUB_RUN_NUM} | ||
echo "copy test-results history to /${INPUT_RESULTS_HISTORY}/last-history" | ||
cp -R ./${INPUT_TEST_RESULTS}/history/. ./${INPUT_RESULTS_HISTORY}/last-history | ||