From 1f101cff04bc4e7c8ef002322932a834ece76bdb Mon Sep 17 00:00:00 2001 From: Pavan Mudigonda Date: Sun, 4 Sep 2022 01:56:36 +0000 Subject: [PATCH] updated --- composite/action.yml | 178 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 composite/action.yml diff --git a/composite/action.yml b/composite/action.yml new file mode 100644 index 0000000..3fde35e --- /dev/null +++ b/composite/action.yml @@ -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 < + + + + Test Results + + + +

Test Results

+ .
+ + 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 "├── Latest Test Results - RUN ID: ${INPUT_GITHUB_RUN_NUM}
" >> ./${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 "├── RUN ID: "${line}" - "${NEW_CREATED_AT}"
" >> ./${INPUT_RESULTS_HISTORY}/index.html; + done; + echo "" >> ./${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 + +