Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
firmanrosid committed Jul 12, 2024
0 parents commit ad3a0ac
Show file tree
Hide file tree
Showing 13 changed files with 281 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/allure-history.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: report-history

on:
workflow_dispatch:

jobs:
generate-report:
name: Generate Report
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v4

- name: Get history
uses: actions/checkout@v4
continue-on-error: true
with:
ref: gh-pages
path: gh-pages

- name: Report History Action
uses: kitabisa/dukun@master
with:
subfolder: allure
keep_reports: 2
report_folder: allure-results
allure_report: allure-report
gh_pages: gh-pages
report_history: report-history

- name: Deploy Report to Github Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./report-history
34 changes: 34 additions & 0 deletions .github/workflows/report-history.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: report-history

on:
workflow_dispatch:

jobs:
generate-report:
name: Generate Report
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v4

- name: Get history
uses: actions/checkout@v4
continue-on-error: true
with:
ref: gh-pages
path: gh-pages

- name: Report History Action
uses: kitabisa/dukun@master
with:
subfolder: report
keep_reports: 2
report_folder: report
gh_pages: gh-pages
report_history: report-history

- name: Deploy Report to Github Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./report-history
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- action-docs-description -->
## Description

Generate report history
<!-- action-docs-description -->

<!-- action-docs-inputs -->
## Inputs

| parameter | description | required | default |
| --- | --- | --- | --- |
| report_folder | test report data dir | `true` | true |
| allure_report | allure report target dir | `true` | allure-report |
| gh_pages | folder with gh-pages branch | `false` | false |
| report_history | folder for report history | `true` | report-history |
| subfolder | subfolder | `false` | null |
| keep_reports | keep x last reports | `false` | 5 |
<!-- action-docs-inputs -->

<!-- action-docs-runs -->
## Runs

This action is a `composite` action.
<!-- action-docs-runs -->
78 changes: 78 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: 'Report History'
description: 'Generate report history for automation'
inputs:
report_folder:
description: 'Test report data dir'
required: true
allure_report:
description: 'Allure report target dir'
required: true
default: 'allure-report'
gh_pages:
description: 'Folder with gh-pages branch'
required: true
default: 'gh-pages'
report_history:
description: 'Folder for report history'
required: true
default: 'report-history'
subfolder:
description: 'subfolder'
required: false
default: ''
keep_reports:
description: 'Keep X last reports'
required: false
default: '5'
github_repo:
description: 'GitHub repository'
required: true
default: ${{ github.repository }}
github_repo_owner:
description: 'GitHub repository owner'
required: true
default: ${{ github.repository_owner }}
github_run_num:
description: 'GitHub Actions build number'
required: true
default: ${{ github.run_number }}

runs:
using: 'composite'
steps:
# - name: Setup Java 17
# uses: actions/setup-java@v4
# with:
# distribution: 'temurin'
# java-version: '17'

- name: Install Allure CLI
run: |
npm install -g allure-commandline
allure --version
shell: bash

- name: Get Report History
uses: actions/checkout@v4
continue-on-error: true
with:
ref: gh-pages
path: gh-pages

- name: Set Generate Report History
run: chmod +x $GITHUB_ACTION_PATH/generate.sh
shell: bash

- name: Generate Report History
env:
INPUT_REPORT_FOLDER: ${{ inputs.report_folder }}
INPUT_ALLURE_REPORT: ${{ inputs.allure_report }}
INPUT_GH_PAGES: ${{ inputs.gh_pages }}
INPUT_REPORT_HISTORY: ${{ inputs.report_history }}
INPUT_SUBFOLDER: ${{ inputs.subfolder }}
INPUT_KEEP_REPORTS: ${{ inputs.keep_reports }}
INPUT_GITHUB_REPO: ${{ inputs.github_repo }}
INPUT_GITHUB_REPO_OWNER: ${{ inputs.github_repo_owner }}
INPUT_GITHUB_RUN_NUM: ${{ inputs.github_run_num }}
run: $GITHUB_ACTION_PATH/generate.sh
shell: bash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"uuid":"4a4ced84-621a-424f-89a4-f70a4cff2b89","historyId":"068ddcc3887fa93a25e46082c15a774f","status":"passed","statusDetails":{},"stage":"finished","steps":[{"status":"passed","statusDetails":{},"stage":"finished","steps":[],"attachments":[],"parameters":[],"start":1720772487030,"name":"Given Step 1 for test 2","stop":1720772487030},{"status":"passed","statusDetails":{},"stage":"finished","steps":[],"attachments":[],"parameters":[],"start":1720772487030,"name":"When Step 2 for test 2","stop":1720772487031},{"status":"passed","statusDetails":{},"stage":"finished","steps":[],"attachments":[],"parameters":[],"start":1720772487031,"name":"Then Step 3 for test 2","stop":1720772487031}],"attachments":[],"parameters":[{"name":"device","value":"iPhone 15 Pro 3"}],"labels":[{"name":"language","value":"javascript"},{"name":"framework","value":"wdio"},{"name":"package","value":".Users.firmansyah.Repositories.jin.src.features.test.feature"},{"name":"thread","value":"0-0"},{"name":"suite","value":"Report history action"},{"name":"feature","value":"Report history action"}],"links":[],"start":1720772485222,"name":"Test 1","testCaseId":"068ddcc3887fa93a25e46082c15a774f","stop":1720772487031}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"uuid":"9a32ec12-03e9-4c71-982f-0f901e942907","historyId":"068ddcc3887fa93a25e46082c15a774f","status":"passed","statusDetails":{},"stage":"finished","steps":[{"status":"passed","statusDetails":{},"stage":"finished","steps":[],"attachments":[],"parameters":[],"start":1720772487282,"name":"Given Step 1 for test 3","stop":1720772487282},{"status":"passed","statusDetails":{},"stage":"finished","steps":[],"attachments":[],"parameters":[],"start":1720772487282,"name":"When Step 2 for test 3","stop":1720772487283},{"status":"passed","statusDetails":{},"stage":"finished","steps":[],"attachments":[],"parameters":[],"start":1720772487283,"name":"Then Step 3 for test 3","stop":1720772487283}],"attachments":[],"parameters":[{"name":"device","value":"iPhone 15 Pro 3"}],"labels":[{"name":"language","value":"javascript"},{"name":"framework","value":"wdio"},{"name":"package","value":".Users.firmansyah.Repositories.jin.src.features.test.feature"},{"name":"thread","value":"0-0"},{"name":"suite","value":"Report history action"},{"name":"feature","value":"Report history action"}],"links":[],"start":1720772487032,"name":"Test 1","testCaseId":"068ddcc3887fa93a25e46082c15a774f","stop":1720772487290}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"uuid":"e70f1694-de45-4d91-aa4f-d77d3383ee64","historyId":"068ddcc3887fa93a25e46082c15a774f","status":"passed","statusDetails":{},"stage":"finished","steps":[{"status":"passed","statusDetails":{},"stage":"finished","steps":[],"attachments":[],"parameters":[],"start":1720772485205,"name":"Given Step 1 for test 1","stop":1720772485213},{"status":"passed","statusDetails":{},"stage":"finished","steps":[],"attachments":[],"parameters":[],"start":1720772485213,"name":"When Step 2 for test 1","stop":1720772485214},{"status":"passed","statusDetails":{},"stage":"finished","steps":[],"attachments":[],"parameters":[],"start":1720772485214,"name":"Then Step 3 for test 1","stop":1720772485215}],"attachments":[],"parameters":[{"name":"device","value":"iPhone 15 Pro 3"}],"labels":[{"name":"language","value":"javascript"},{"name":"framework","value":"wdio"},{"name":"package","value":".Users.firmansyah.Repositories.jin.src.features.test.feature"},{"name":"thread","value":"0-0"},{"name":"suite","value":"Report history action"},{"name":"feature","value":"Report history action"}],"links":[],"start":1720772481744,"name":"Test 1","testCaseId":"068ddcc3887fa93a25e46082c15a774f","stop":1720772485221}
1 change: 1 addition & 0 deletions allure-results/executor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"GitHub Actions","type":"github","reportName":"Allure Report with history"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"uuid":"f602bb42-865c-4848-8c80-9bcd2a1ca6e3","children":["e70f1694-de45-4d91-aa4f-d77d3383ee64","4a4ced84-621a-424f-89a4-f70a4cff2b89","9a32ec12-03e9-4c71-982f-0f901e942907"],"befores":[],"afters":[],"name":"Report history action"}
1 change: 1 addition & 0 deletions executor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"GitHub Actions","type":"github","reportName":"Allure Report with history"}
99 changes: 99 additions & 0 deletions generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env bash

# Create directories for gh-pages and report-history if they don't exist
echo "Creating directories: ./${INPUT_GH_PAGES} and ./${INPUT_REPORT_HISTORY}"
mkdir -p ./${INPUT_GH_PAGES}
mkdir -p ./${INPUT_REPORT_HISTORY}

# Copy all contents from gh-pages to report-history
echo "Copying contents from ./${INPUT_GH_PAGES} to ./${INPUT_REPORT_HISTORY}"
cp -r ./${INPUT_GH_PAGES}/. ./${INPUT_REPORT_HISTORY}

# Get repository name from full input (owner/repo)
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}"

# If a subfolder is specified, adjust paths and URL
if [[ ${INPUT_SUBFOLDER} != '' ]]; then
INPUT_REPORT_HISTORY="${INPUT_REPORT_HISTORY}/${INPUT_SUBFOLDER}"
INPUT_GH_PAGES="${INPUT_GH_PAGES}/${INPUT_SUBFOLDER}"
mkdir -p ./${INPUT_REPORT_HISTORY}
GITHUB_PAGES_WEBSITE_URL="${GITHUB_PAGES_WEBSITE_URL}/${INPUT_SUBFOLDER}"
echo "Adjusted paths for subfolder: INPUT_REPORT_HISTORY=${INPUT_REPORT_HISTORY}, INPUT_GH_PAGES=${INPUT_GH_PAGES}"
echo "Updated GITHUB_PAGES_WEBSITE_URL: ${GITHUB_PAGES_WEBSITE_URL}"
fi

# Removing the folder with the smallest number
COUNT=$( (ls ./${INPUT_REPORT_HISTORY} | wc -l))
echo "Count folders in report-history: ${COUNT}"

# Determine which folders to keep based on INPUT_KEEP_REPORTS
echo "Keep reports count ${INPUT_KEEP_REPORTS}"
echo "Removing the folder with the smallest number..."

if [[ "${INPUT_REPORT_FOLDER}" == *"allure-results"* ]]; then
INPUT_KEEP_REPORTS=$((INPUT_KEEP_REPORTS + 1))
echo "If ${COUNT} == ${INPUT_KEEP_REPORTS}"
if ((COUNT > INPUT_KEEP_REPORTS)); then
cd ./${INPUT_REPORT_HISTORY}
echo "remove index.html last-history"
rm index.html last-history -rv
echo "remove old reports"
ls | sort -n | grep -v 'CNAME' | head -n -$((${INPUT_KEEP_REPORTS} - 2)) | xargs rm -rv
cd ${GITHUB_WORKSPACE}
fi

#echo "index.html"
echo "<!DOCTYPE html><meta charset=\"utf-8\"><meta http-equiv=\"refresh\" content=\"0; URL=${GITHUB_PAGES_WEBSITE_URL}/${INPUT_GITHUB_RUN_NUM}/index.html\">" >./${INPUT_REPORT_HISTORY}/index.html # path
echo "<meta http-equiv=\"Pragma\" content=\"no-cache\"><meta http-equiv=\"Expires\" content=\"0\">" >>./${INPUT_REPORT_HISTORY}/index.html
#cat ./${INPUT_REPORT_HISTORY}/index.html

#echo "executor.json"
echo '{"name":"GitHub Actions","type":"github","reportName":"Allure 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\":\"${INPUT_GITHUB_SERVER_URL}/${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_REPORT_FOLDER}

#environment.properties
# echo "URL=${GITHUB_PAGES_WEBSITE_URL}" >> ./${INPUT_REPORT_FOLDER}/environment.properties

echo "keep allure history from ${INPUT_GH_PAGES}/last-history to ${INPUT_REPORT_FOLDER}/history"
cp -r ./${INPUT_GH_PAGES}/last-history/. ./${INPUT_REPORT_FOLDER}/history

echo "generating report from ${INPUT_REPORT_FOLDER} to ${INPUT_ALLURE_REPORT} ..."
#ls -l ${INPUT_REPORT_FOLDER}
allure generate --clean ${INPUT_REPORT_FOLDER} -o ${INPUT_ALLURE_REPORT}
#echo "listing report directory ..."
#ls -l ${INPUT_ALLURE_REPORT}

echo "copy allure-report to ${INPUT_REPORT_HISTORY}/${INPUT_GITHUB_RUN_NUM}"
cp -r ./${INPUT_ALLURE_REPORT}/. ./${INPUT_REPORT_HISTORY}/${INPUT_GITHUB_RUN_NUM}
echo "copy allure-report history to /${INPUT_REPORT_HISTORY}/last-history"
cp -r ./${INPUT_ALLURE_REPORT}/history/. ./${INPUT_REPORT_HISTORY}/last-history
else
if ((COUNT == INPUT_KEEP_REPORTS)); then
echo "If ${COUNT} == ${INPUT_KEEP_REPORTS}"
ls -d ${INPUT_REPORT_HISTORY}/*/ | sort -V | head -n 1 | xargs rm -rv
elif ((COUNT > INPUT_KEEP_REPORTS)); then
echo "elif ${COUNT} > ${INPUT_KEEP_REPORTS}"
ls -d ${INPUT_REPORT_HISTORY}/*/ | sort -V | head -n -$((${INPUT_KEEP_REPORTS} - 1)) | xargs rm -rv
fi

# Copy INPUT_REPORT_FOLDER folder to INPUT_SUBFOLDER
if [ -d "${INPUT_REPORT_FOLDER}" ]; then
echo "Copying ${INPUT_REPORT_FOLDER} to ${INPUT_SUBFOLDER}"
cp -r "${INPUT_REPORT_FOLDER}" "${INPUT_SUBFOLDER}"
fi

# Copy contents of INPUT_SUBFOLDER to INPUT_REPORT_HISTORY/INPUT_GITHUB_RUN_NUM
if [ -d "${INPUT_SUBFOLDER}" ]; then
echo "Copying contents of ${INPUT_SUBFOLDER} to ${INPUT_REPORT_HISTORY}/${INPUT_GITHUB_RUN_NUM}"
cp -r ./${INPUT_SUBFOLDER}/. ./${INPUT_REPORT_HISTORY}/${INPUT_GITHUB_RUN_NUM}
else
echo "Folder ${INPUT_SUBFOLDER} not found."
fi
fi
4 changes: 4 additions & 0 deletions report/text.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"status": 200,
"message": "Healthy"
}

0 comments on commit ad3a0ac

Please sign in to comment.