Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
367ce1e
first commit
rahulpatidar0191 Oct 26, 2022
d6f9179
make shell file executable
rahulpatidar0191 Oct 26, 2022
fa764fd
remove js
rahulpatidar0191 Nov 1, 2022
d7fb3ac
make shell exec
rahulpatidar0191 Nov 1, 2022
30c1ed5
add app health check
rahulpatidar0191 Nov 1, 2022
a7b8c45
add codeowners and update readme
rahulpatidar0191 Nov 2, 2022
612f0d5
merge docker up and docker down
rahulpatidar0191 Nov 3, 2022
bd9b74c
fix if condition
rahulpatidar0191 Nov 3, 2022
8dcc5f7
move scripts in one folder
rahulpatidar0191 Nov 3, 2022
70aacbf
fix typo
rahulpatidar0191 Nov 3, 2022
368af2d
add logic for multiple server
rahulpatidar0191 Nov 3, 2022
f972fd6
change container name
rahulpatidar0191 Nov 3, 2022
8a7a6ae
add comments
rahulpatidar0191 Nov 3, 2022
d18fa7a
fix name
rahulpatidar0191 Nov 3, 2022
9aec3bb
fix typos
rahulpatidar0191 Nov 3, 2022
8b55774
add comments
rahulpatidar0191 Nov 4, 2022
439c101
fix typo
rahulpatidar0191 Nov 4, 2022
9b1730b
fix branch name
rahulpatidar0191 Nov 4, 2022
2b87dfb
add names for steps
rahulpatidar0191 Nov 5, 2022
fa60922
add redoc
rahulpatidar0191 Feb 2, 2023
3f931a1
enable create dir
rahulpatidar0191 Feb 2, 2023
05b7d26
fix typo
rahulpatidar0191 Feb 2, 2023
4132c40
remove redoc part
rahulpatidar0191 Feb 7, 2023
5ac8fab
add work-dir
rahulpatidar0191 Feb 7, 2023
c5fc731
increase sleep time to avoid failing
rahulpatidar0191 Feb 8, 2023
4b1ce97
turn off health check for now
rahulpatidar0191 Feb 8, 2023
4bd9971
add wor-dir for testing
rahulpatidar0191 Feb 8, 2023
2ec7149
print env
rahulpatidar0191 Feb 8, 2023
304f80f
improve instructions
rahulpatidar0191 Feb 8, 2023
22bbfe5
add envs
rahulpatidar0191 Mar 29, 2023
f8a3b73
remove default for work dir
rahulpatidar0191 Mar 29, 2023
2a57995
make work dir optional
rahulpatidar0191 Mar 29, 2023
d732556
add openapi
rahulpatidar0191 Mar 29, 2023
c4b9cde
replace _ with -
rahulpatidar0191 Mar 29, 2023
36b96c9
fix mkdir
rahulpatidar0191 Mar 29, 2023
53406d2
fix syntax
rahulpatidar0191 Mar 29, 2023
c3011b3
fix typo
rahulpatidar0191 Mar 29, 2023
a01c233
print clean branch name
rahulpatidar0191 Mar 30, 2023
9894c59
debug underscore
rahulpatidar0191 Mar 30, 2023
e030b58
revert -
rahulpatidar0191 Mar 30, 2023
057dcab
turn on checks for now
rahulpatidar0191 Mar 30, 2023
4d6bf73
remove app part from ls
rahulpatidar0191 Mar 30, 2023
8e9e0ac
add / for mnt
rahulpatidar0191 Mar 30, 2023
be4ac36
remove app name
rahulpatidar0191 Mar 30, 2023
c058a21
enable testing
rahulpatidar0191 Mar 30, 2023
815f4cc
add fast api parameter
rahulpatidar0191 Mar 30, 2023
ff86a61
add debug
rahulpatidar0191 Mar 31, 2023
adca6e4
update docs
rahulpatidar0191 Apr 3, 2023
379e062
fix spacing
rahulpatidar0191 Apr 3, 2023
a01e61b
change version
rahulpatidar0191 Apr 3, 2023
b3c6e0b
finish formatting
rahulpatidar0191 Apr 3, 2023
85567ee
fix typo
rahulpatidar0191 Apr 3, 2023
d73e5ae
Merge branch 'feature/webapp-deployment-shell' of https://github.com/…
rahulpatidar0191 Apr 3, 2023
ebe633f
add port as an input
rahulpatidar0191 Apr 3, 2023
704e20f
add port
rahulpatidar0191 Apr 3, 2023
1207137
add validatecodeonce for multiple
rahulpatidar0191 Apr 3, 2023
e8976b9
remove port and add openapi in multiple
rahulpatidar0191 Apr 3, 2023
916d88e
debug openapi link
rahulpatidar0191 Apr 3, 2023
42c7849
remove debugs
rahulpatidar0191 Apr 3, 2023
96fca5a
add flake8 back
rahulpatidar0191 Apr 3, 2023
a92bd7e
improve text
rahulpatidar0191 Apr 3, 2023
3764b1d
remove unwanted text
rahulpatidar0191 Apr 3, 2023
0cea89c
always run docker dowm
rahulpatidar0191 Apr 3, 2023
2d2d9fd
change description to reflect repo name
rahulpatidar0191 Apr 5, 2023
67e38d2
add container name
rahulpatidar0191 May 4, 2023
1527e46
merge single and multiple code
rahulpatidar0191 May 5, 2023
33addf4
fix syntax
rahulpatidar0191 May 5, 2023
7e57459
add an echo to debug
rahulpatidar0191 May 5, 2023
be6d366
remove extra parameters
rahulpatidar0191 May 5, 2023
02b2729
add proper reports
rahulpatidar0191 May 5, 2023
230530f
Revert changes due to this [error](https://github.com/SatelCreative/s…
rahulpatidar0191 May 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .gitignore
Empty file.
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @rahulpatidar0191
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
# satel-webapp-testing
Centralized GitHub actions to test a webapp
# Satel Python Docker Tests
This centralized GitHub action runs tests on a python app using docker services

## Usage
```yml
name: Run tests
on:
<conditions-you-want-this-workflow-to-run-on>

jobs:
code-validation:
# HOST-NAME is self-hosted or the name of server where the action runner is hosted, cosmicray for example
runs-on: <HOST-NAME>
steps:
- name: Validate code
uses: SatelCreative/satel-local-python-tests@1.0.0
with:
# APP-NAME can be st-pim or sb-pim for example
app-name: <APP-NAME>
registry: <REGISTRY-NAME>
clean-branch-name: <CLEAN-BRANCH-NAME>
# WORK-DIR, where all the docker related files are located, optional field, default is root
work-dir: <WORK-DIR>
fastapi-parameter: </PARAMETER>
container-name: <NAME_OF-WEBAPP-CONTAINER>


```
54 changes: 54 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Validate code using docker
description: Run docker services, test them and then remove them
inputs:
app-name:
description: Name of the Webapp
required: false
registry:
description: Provides current name of the registry
required: true
clean-branch-name:
description: Branch name that was pushed to registry
required: true
work-dir:
description: Location of all the docker files
required: false
fastapi-parameter:
description: Extra URL parameter for openapi
required: false
container-name:
description: Name of the docker container for webapp
required: false
default: webapp

runs:
using: "composite"
steps:
- name: Docker Up
env:
APP_NAME: ${{ inputs.app-name }}
REGISTRY: ${{ inputs.registry }}
CLEAN_BRANCH_NAME: ${{ inputs.clean-branch-name }}
WORK_DIR: ${{ inputs.work-dir }}
run: ${{ github.action_path }}/scripts/DockerUp.sh
shell: bash

- name: Run docker tests
env:
APP_NAME: ${{ inputs.app-name }}
CLEAN_BRANCH_NAME: ${{ inputs.clean-branch-name }}
WORK_DIR: ${{ inputs.work-dir }}
FAST_PARA: ${{ inputs.fastapi-parameter }}
CONTAINER_NAME: ${{ inputs.container-name }}
run: ${{ github.action_path }}/scripts/ValidateCode.sh
shell: bash

- name: Docker Down
if: ${{ always() }}
env:
APP_NAME: ${{ inputs.app-name }}
REGISTRY: ${{ inputs.registry }}
CLEAN_BRANCH_NAME: ${{ inputs.clean-branch-name }}
WORK_DIR: ${{ inputs.work-dir }}
run: ${{ github.action_path }}/scripts/DockerDown.sh
shell: bash
14 changes: 14 additions & 0 deletions scripts/DockerDown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# Set registry and clean branch name as global variables
export REGISTRY=$REGISTRY
export CLEAN_BRANCH_NAME=$CLEAN_BRANCH_NAME

if [[ -n $WORK_DIR ]]
then
echo "WORK_DIR ${WORK_DIR}"
cd $WORK_DIR
fi

echo "Docker down"
docker-compose -f docker-compose.yml -f docker-compose.pipeline.yml down
21 changes: 21 additions & 0 deletions scripts/DockerUp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Set registry and clean branch name as global variables
export REGISTRY=$REGISTRY
export CLEAN_BRANCH_NAME=$CLEAN_BRANCH_NAME

if [[ -n $WORK_DIR ]]
then
echo "WORK_DIR ${WORK_DIR}"
cd $WORK_DIR
fi
echo "Dev image check"
IMG_STR=`cat docker-compose.override.yml | grep 'devenv'| cut -d ":" -f 2-3`
IMG_LIST=( $IMG_STR ) #convert string into an array
for IMG in "${IMG_LIST[@]}"
do
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect ${IMG} > /dev/null || exit 1 # Check to see if the dev image is on registry or not
done

echo "Docker up"
docker-compose -f docker-compose.yml -f docker-compose.pipeline.yml up -d
37 changes: 37 additions & 0 deletions scripts/ValidateCode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

if [[ -n $WORK_DIR ]]
then
echo "WORK_DIR ${WORK_DIR}"
cd $WORK_DIR
fi

echo "App health check" # Check to see if the app container is running or not
sleep 5
docker-compose exec -T ${CONTAINER_NAME} python -c "import requests; requests.get('http://localhost:8000/health')" || exit 1

echo "Openapi link" # copy openapi files to samba mount
docker-compose exec -T ${CONTAINER_NAME} python -c "import requests; f=open('${CLEAN_BRANCH_NAME}_openapi.json','w',encoding = 'utf-8'); f.write(requests.get('http://localhost:8000${FAST_PARA}/openapi.json').text);f.close()"
[ -d "/mnt/samba/${APP_NAME}" ] || mkdir -p "/mnt/samba/${APP_NAME}"
docker cp "$(docker-compose ps -q ${CONTAINER_NAME})":"/python/app/${CLEAN_BRANCH_NAME}_openapi.json" "/mnt/samba/${APP_NAME}/${CLEAN_BRANCH_NAME}_openapi.json"

echo "Clean up old reports"
rm -f unittesting.xml coverage.xml typing.xml typing-server.xml typing-integrations.xml

echo "Code tests"
## Catch the exit codes so we don't exit the whole script before we are done.
## Typing, linting, formatting check & unit and integration testing
if [[ $CONTAINER_NAME != "webapp" ]]; then
echo "flake8 tests" #TODO: remove the if else block once the errors on sb-pim are fixed
docker-compose exec -T ${CONTAINER_NAME} flake8; STATUS1=$? # For Sb-pim only

else
docker-compose exec -T ${CONTAINER_NAME} validatecodeonce; STATUS1=$?
docker cp "$(docker-compose ps -q ${CONTAINER_NAME})":/python/reports/typing.xml typing.xml
docker cp "$(docker-compose ps -q ${CONTAINER_NAME})":/python/reports/unittesting.xml unittesting.xml
docker cp "$(docker-compose ps -q ${CONTAINER_NAME})":/python/reports/coverage.xml coverage.xml
fi

## Return the status code
TOTAL=$((STATUS1))
exit $TOTAL