Skip to content

Commit 3d88f32

Browse files
Include allure-report step into schedule
1 parent 100f4d2 commit 3d88f32

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

.github/workflows/schedule.yaml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,141 @@ jobs:
3232
with:
3333
artifact-prefix: ${{ needs.build.outputs.artifact-prefix }}
3434
secrets: inherit
35+
36+
allure-report:
37+
name: Publish Allure report
38+
if: ${{ !cancelled() && github.run_attempt == '1' }}
39+
needs:
40+
- integration-test
41+
- release-test
42+
runs-on: ubuntu-latest
43+
timeout-minutes: 5
44+
permissions:
45+
contents: write
46+
steps:
47+
- name: Download Allure
48+
# Following instructions from https://allurereport.org/docs/install-for-linux/#install-from-a-deb-package
49+
run: gh release download --repo allure-framework/allure2 --pattern 'allure_*.deb'
50+
env:
51+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
- name: Install Allure
53+
run: |
54+
sudo apt-get update
55+
sudo apt-get install ./allure_*.deb -y
56+
# For first run, manually create branch with no history
57+
# (e.g.
58+
# git checkout --orphan gh-pages-beta
59+
# git rm -rf .
60+
# touch .nojekyll
61+
# git add .nojekyll
62+
# git commit -m "Initial commit"
63+
# git push origin gh-pages-beta
64+
# )
65+
- name: Checkout GitHub pages branch
66+
uses: actions/checkout@v5
67+
with:
68+
ref: gh-pages-beta
69+
path: repo/
70+
- name: Download default test results
71+
# Default test results in case the integration tests time out or runner set up fails
72+
# (So that Allure report will show "unknown"/"failed" test result, instead of omitting the test)
73+
uses: actions/download-artifact@v5
74+
with:
75+
path: allure-default-results/
76+
name: allure-default-results-integration-test
77+
- name: Download test results
78+
uses: actions/download-artifact@v5
79+
with:
80+
path: allure-results/
81+
pattern: allure-results-integration-test-*
82+
merge-multiple: true
83+
- name: Combine Allure default results & actual results
84+
# For every test: if actual result available, use that. Otherwise, use default result
85+
# So that, if actual result not available, Allure report will show "unknown"/"failed" test result
86+
# instead of omitting the test
87+
shell: python
88+
run: |
89+
import dataclasses
90+
import json
91+
import pathlib
92+
93+
94+
@dataclasses.dataclass(frozen=True)
95+
class Result:
96+
test_case_id: str
97+
path: pathlib.Path
98+
99+
def __eq__(self, other):
100+
if not isinstance(other, type(self)):
101+
return False
102+
return self.test_case_id == other.test_case_id
103+
104+
105+
actual_results = pathlib.Path("allure-results")
106+
default_results = pathlib.Path("allure-default-results")
107+
108+
results: dict[pathlib.Path, set[Result]] = {
109+
actual_results: set(),
110+
default_results: set(),
111+
}
112+
for directory, results_ in results.items():
113+
for path in directory.glob("*-result.json"):
114+
with path.open("r") as file:
115+
id_ = json.load(file)["testCaseId"]
116+
results_.add(Result(id_, path))
117+
118+
actual_results.mkdir(exist_ok=True)
119+
120+
missing_results = results[default_results] - results[actual_results]
121+
for default_result in missing_results:
122+
# Move to `actual_results` directory
123+
default_result.path.rename(actual_results / default_result.path.name)
124+
- name: Load test report history
125+
run: |
126+
if [[ -d repo/_latest/history/ ]]
127+
then
128+
echo 'Loading history'
129+
cp -r repo/_latest/history/ allure-results/
130+
fi
131+
- name: Create executor.json
132+
shell: python
133+
run: |
134+
# Reverse engineered from https://github.com/simple-elf/allure-report-action/blob/eca283b643d577c69b8e4f048dd6cd8eb8457cfd/entrypoint.sh
135+
import json
136+
137+
DATA = {
138+
"name": "GitHub Actions",
139+
"type": "github",
140+
"buildOrder": ${{ github.run_number }}, # TODO future improvement: use run ID
141+
"buildName": "Run ${{ github.run_id }}",
142+
"buildUrl": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
143+
"reportUrl": "../${{ github.run_number }}/",
144+
}
145+
with open("allure-results/executor.json", "w") as file:
146+
json.dump(DATA, file)
147+
- name: Generate Allure report
148+
run: allure generate
149+
- name: Create index.html
150+
shell: python
151+
run: |
152+
DATA = f"""<!DOCTYPE html>
153+
<meta charset="utf-8">
154+
<meta http-equiv="cache-control" content="no-cache">
155+
<meta http-equiv="refresh" content="0; url=${{ github.run_number }}">
156+
"""
157+
with open("repo/index.html", "w") as file:
158+
file.write(DATA)
159+
- name: Update GitHub pages branch
160+
working-directory: repo/
161+
# TODO future improvement: commit message
162+
run: |
163+
mkdir '${{ github.run_number }}'
164+
rm -f _latest
165+
ln -s '${{ github.run_number }}' _latest
166+
cp -r ../allure-report/. _latest/
167+
git add .
168+
git config user.name "GitHub Actions"
169+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
170+
git commit -m "Allure report ${{ github.run_number }}"
171+
# Uses token set in checkout step
172+
git push origin gh-pages-beta

0 commit comments

Comments
 (0)