Skip to content

Commit 3718461

Browse files
Nilstyppodgorsek
andauthored
Issue #322 - Automatically upload reports to AWS S3 after each execution (#321)
* Ensure the output directory exists when the test run ID is set * Optionally upload test reports to S3 Co-authored-by: Paul Podgorsek <[email protected]>
1 parent dd8d2c6 commit 3718461

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ ENV ROBOT_GID 1000
3030

3131
# Dependency versions
3232
ENV ALPINE_GLIBC 2.31-r0
33+
ENV AWS_CLI_VERSION 1.18.200
3334
ENV CHROMIUM_VERSION 86.0
3435
ENV DATABASE_LIBRARY_VERSION 1.2
3536
ENV DATETIMETZ_VERSION 1.0.6
@@ -45,6 +46,9 @@ ENV SELENIUM_LIBRARY_VERSION 4.5.0
4546
ENV SSH_LIBRARY_VERSION 3.5.1
4647
ENV XVFB_VERSION 1.20
4748

49+
# By default, no reports are uploaded to AWS S3
50+
ENV AWS_UPLOAD_TO_S3 false
51+
4852
# Prepare binaries to be executed
4953
COPY bin/chromedriver.sh /opt/robotframework/bin/chromedriver
5054
COPY bin/chromium-browser.sh /opt/robotframework/bin/chromium-browser
@@ -88,6 +92,9 @@ RUN apk update \
8892
robotframework-sshlibrary==$SSH_LIBRARY_VERSION \
8993
PyYAML \
9094

95+
# Install awscli to be able to upload test reports to AWS S3
96+
awscli==$AWS_CLI_VERSION \
97+
9198
# Download the glibc package for Alpine Linux from its GitHub repository
9299
&& wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
93100
&& wget -q "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/$ALPINE_GLIBC/glibc-$ALPINE_GLIBC.apk" \

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ The versions used are:
2727
* [Robot Framework SSHLibrary](https://github.com/robotframework/SSHLibrary) 3.5.1
2828
* Firefox ESR 78
2929
* Chromium 86.0
30+
* [Amazon AWS CLI](https://pypi.org/project/awscli/) 1.18.200
3031

3132
As stated by [the official GitHub project](https://github.com/robotframework/Selenium2Library), starting from version 3.0, Selenium2Library is renamed to SeleniumLibrary and this project exists mainly to help with transitioning. The Selenium2Library 3.0.0 is also the last release and for new releases, please look at the [SeleniumLibrary](https://github.com/robotframework/SeleniumLibrary) project.
3233

@@ -159,6 +160,33 @@ The pipeline stage can also rely on a Docker agent, as shown in the example belo
159160
}
160161
}
161162

163+
### Defining a test run ID
164+
165+
When relying on Continuous Integration tools, it can be useful to define a test run ID such as the build number or branch name to avoid overwriting consecutive execution reports.
166+
167+
For that purpose, the `ROBOT_TEST_RUN_ID` variable was introduced:
168+
* If the test run ID is empty, the reports folder will be: `${ROBOT_REPORTS_DIR}/`
169+
* If the test run ID was provided, the reports folder will be: `${ROBOT_REPORTS_DIR}/${ROBOT_TEST_RUN_ID}/`
170+
171+
It can simply be passed during the execution, such as:
172+
173+
docker run \
174+
-e ROBOT_TEST_RUN_ID="feature/branch-name" \
175+
ppodgorsek/robot-framework:latest
176+
177+
By default, the test run ID is empty.
178+
179+
### Upload test reports to an AWS S3 bucket
180+
181+
To upload the report of a test run to an S3 bucket, you need to define the following environment variables:
182+
183+
docker run \
184+
-e AWS_ACCESS_KEY_ID=<your AWS key> \
185+
-e AWS_SECRET_ACCESS_KEY=<your AWS secret> \
186+
-e AWS_DEFAULT_REGION=<your AWS region e.g. eu-central-1> \
187+
-e AWS_BUCKET_NAME=<name of your S3 bucket> \
188+
ppodgorsek/robot-framework:latest
189+
162190
## Testing this project
163191

164192
Not convinced yet? Simple tests have been prepared in the `test/` folder, you can run them using the following commands:

bin/run-tests-in-virtual-screen.sh

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,30 @@
22

33
HOME=${ROBOT_WORK_DIR}
44

5+
if [ "${ROBOT_TEST_RUN_ID}" = "" ]
6+
then
7+
ROBOT_REPORTS_FINAL_DIR="${ROBOT_REPORTS_DIR}"
8+
else
9+
REPORTS_DIR_HAS_TRAILING_SLASH=`echo ${ROBOT_REPORTS_DIR} | grep '/$'`
10+
11+
if [ ${REPORTS_DIR_HAS_TRAILING_SLASH} -eq 0 ]
12+
then
13+
ROBOT_REPORTS_FINAL_DIR="${ROBOT_REPORTS_DIR}${ROBOT_TEST_RUN_ID}"
14+
else
15+
ROBOT_REPORTS_FINAL_DIR="${ROBOT_REPORTS_DIR}/${ROBOT_TEST_RUN_ID}"
16+
fi
17+
fi
18+
19+
# Ensure the output folder exists
20+
mkdir -p ${ROBOT_REPORTS_FINAL_DIR}
21+
522
# No need for the overhead of Pabot if no parallelisation is required
623
if [ $ROBOT_THREADS -eq 1 ]
724
then
825
xvfb-run \
926
--server-args="-screen 0 ${SCREEN_WIDTH}x${SCREEN_HEIGHT}x${SCREEN_COLOUR_DEPTH} -ac" \
1027
robot \
11-
--outputDir $ROBOT_REPORTS_DIR \
28+
--outputDir $ROBOT_REPORTS_FINAL_DIR \
1229
${ROBOT_OPTIONS} \
1330
$ROBOT_TESTS_DIR
1431
else
@@ -18,7 +35,14 @@ else
1835
--verbose \
1936
--processes $ROBOT_THREADS \
2037
${PABOT_OPTIONS} \
21-
--outputDir $ROBOT_REPORTS_DIR \
38+
--outputDir $ROBOT_REPORTS_FINAL_DIR \
2239
${ROBOT_OPTIONS} \
2340
$ROBOT_TESTS_DIR
2441
fi
42+
43+
if [ ${AWS_UPLOAD_TO_S3} = true ]
44+
then
45+
echo "Uploading report to AWS S3..."
46+
aws s3 sync $ROBOT_REPORTS_FINAL_DIR/ s3://${AWS_BUCKET_NAME}/robot-reports/
47+
echo "Reports have been successfully uploaded to AWS S3!"
48+
fi

0 commit comments

Comments
 (0)