-
Notifications
You must be signed in to change notification settings - Fork 0
180 lines (148 loc) · 6.09 KB
/
tests_dev.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
name: RAVS TESTS - DEV
on:
push:
branches:
- '**' # Triggers on push to any branch
pull_request:
branches:
- '**' # Triggers on PR to any branch
schedule:
- cron: "30 7 * * *"
workflow_dispatch:
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Stop and remove all containers
run: |
docker stop $(docker ps -q) || true
docker rm $(docker ps -aq) || true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build the Docker image
run: docker build -t playwright-tests -f Docker/tests.dockerfile .
- name: Run Docker container
id: run-container
run: |
docker run -d --name playwright-tests \
--memory 8g \
-e RAVS_PASSWORD="${{ secrets.RAVS_PASSWORD }}" \
-e HEADLESS_MODE="true" \
-e TEST_ENVIRONMENT="dev" \
-e BROWSER="chrome" \
-e MARKER="" \
-e AGENTS=3 \
-p 5050:5050 \
playwright-tests
while true; do
if docker logs playwright-tests 2>&1 | grep -q "Server started "; then
echo "Report successfully generated."
break
else
echo "Waiting for the Allure report to be generated..."
sleep 5
fi
done
- name: Start Docker container
run: |
docker start playwright-tests
sleep 5
- name: Find and upload Allure report directory
run: |
container_id=$(docker ps -qf "name=playwright-tests")
echo "Container ID: $container_id"
allure_directory=$(docker exec $container_id find / -path /proc -prune -o -type d -name "allure-report" -print -quit)
echo "Allure Directory: $allure_directory"
if [[ -n "$allure_directory" ]]; then
echo "ALLURE_DIRECTORY=$allure_directory" >> $GITHUB_ENV
# Create a temporary directory to store the contents
temp_dir="$(mktemp -d)"
echo "Temporary Directory: $temp_dir"
# Copy the contents of allure_directory to the temporary directory
docker cp "$container_id":"$allure_directory"/. "$temp_dir"
# Archive the contents of the temporary directory
(cd "$(dirname "$temp_dir")" && tar -czf allure-report.tar.gz -C "$(basename "$temp_dir")" .)
# Set the path of Allure report archive as output
echo "::set-output name=allure_report_archive::$(realpath "$(dirname "$temp_dir")/allure-report.tar.gz")"
# Set the environment variable for the archive path
export ALLURE_REPORT_ARCHIVE=$(realpath "$(dirname "$temp_dir")/allure-report.tar.gz")
echo "ALLURE_REPORT_ARCHIVE=$ALLURE_REPORT_ARCHIVE" >> $GITHUB_ENV
# Check if tar was generated successfully
if [ $? -eq 0 ]; then
echo "Tar archive generated successfully."
# Echo the path of the tar file
echo "Path of the tar file: $ALLURE_REPORT_ARCHIVE"
# List the contents of the tar file
tar -tf "$ALLURE_REPORT_ARCHIVE"
else
echo "Failed to generate tar archive."
fi
else
echo "Allure directory not found or is empty."
fi
- name: Upload Allure report archive
uses: actions/upload-artifact@v4
with:
name: allure-report
path: ${{ env.ALLURE_REPORT_ARCHIVE }}
- name: Retrieve and extract Allure report artifact
uses: actions/download-artifact@v4
with:
name: allure-report
path: allure-report
- name: List contents of the downloaded artifact
run: |
ls -l allure-report
- name: Unzip the tar file
run: |
tar -xzvf allure-report/allure-report.tar.gz -C allure-report
- name: List contents after unzipping
run: |
ls -l allure-report
# Move the Allure report files to the root of the gh-pages directory
- name: Move Allure report files
run: |
mv allure-report/* .
- name: Upload Attachments
uses: actions/upload-artifact@v3
with:
name: screenshots
path: data/attachments/**
if-no-files-found: warn
include-hidden-files: false
- name: Get branch name
id: get_branch_name
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF##*/})" >> $GITHUB_ENV
- name: Set destination branch for GitHub Pages
id: set-destination-branch
run: echo "DESTINATION_BRANCH=gh-pages-${{ env.BRANCH_NAME }}" >> $GITHUB_ENV
- name: Deploy Allure report to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: .
destination_branch: gh-pages-dev
- name: Check contents of gh-pages
run: ls -la
- name: Get GitHub Pages URL
id: pages-url
uses: actions/github-script@v7
with:
script: |
const repo = context.repo.repo;
const owner = context.repo.owner;
const branchName = context.ref.split('/').pop(); // Use the branch name you want to reference
const pagesUrl = `https://${owner}.github.io/${repo}/gh-pages-${branchName}`; // Use backticks for template literals
core.setOutput('pages_url', pagesUrl);
- name: Output GitHub Pages URL
run: |
echo "GitHub Pages URL: ${{ steps.pages-url.outputs.pages_url }}"
- name: Clean up
run: docker stop $(docker ps -q) || true
- name: Notify Slack on success
if: success()
run: |
BRANCH_NAME=$(echo $GITHUB_REF | sed 's|refs/heads/||')
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"Ravs tests finished running for the DEV environment on branch $BRANCH_NAME! Check the Allure report: https://nhsdigital.github.io/ravs-tests/#\"}" ${{ secrets.SLACK_WEBHOOK_URL }}