Python application #37
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will install Python dependencies, run tests and lint with a single version of Python | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | |
name: Python application | |
on: | |
push: | |
paths-ignore: | |
- '**.md' | |
- '**.png' | |
- '**.jpg' | |
- '**.webp' | |
branches: [ master ] | |
pull_request: | |
branches: [ master ] | |
workflow_dispatch: | |
inputs: | |
python_version: | |
type: choice | |
description: Choose python version | |
options: | |
- "3.12.0-rc.1" | |
- "3.11" | |
- "3.10" | |
- "3.9" | |
default: "3.12.0-rc.1" | |
maria_image: | |
description: MariaDB docker tag (10.x is fine, 11.x isn't) | |
default: "10.8.3-jammy" | |
schedule: | |
- cron: '0 0 * * FRI' | |
jobs: | |
build: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set the variables | |
env: | |
DEFAULT_PY_VERSION: '3.12.0-rc.1' | |
DEFAULT_WP_VERSION: "6.0.1" # This is tied to the SQL dump for this repo. | |
DEFAULT_MARIA_IMG: "10.8.3-jammy" # 11.0.2 is failing to return, don't change! | |
run: | | |
echo "PY_VERS=${{ github.event.inputs.python_version || env.DEFAULT_PY_VERSION }}" >> $GITHUB_ENV | |
echo "WP_VERS=${{ github.event.inputs.wp_version || env.DEFAULT_WP_VERSION }}" >> $GITHUB_ENV | |
echo "MARIADB_IMG=${{ github.event.inputs.maria_image || env.DEFAULT_MARIA_IMG }}" >> $GITHUB_ENV | |
- name: Set up Python ${{env.PY_VERS}} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{env.PY_VERS}} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install flake8 pytest coverage | |
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
- name: Lint with flake8 | |
run: | | |
# stop the build if there are Python syntax errors or undefined names | |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | |
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | |
- name: Check dir | |
run: | | |
ls -la | |
- name: Check ports | |
run: | | |
sudo ss -tulpn | |
- name: Spin up DB container | |
run: | | |
docker run --name mariadb -e MYSQL_ROOT_PASSWORD=mypass -p 3306:3306 -d --restart unless-stopped mariadb:${{env.MARIADB_IMG}} | |
- name: Spin up WordPress container | |
run: | | |
# Query, can we expose on 0? Or localhost only? | |
docker run -p 80:80 -p 443:443 -p 127.0.0.1:8066:22 --name mywp -d --restart unless-stopped wordpress:${{env.WP_VERS}} | |
mariadb_addy=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' mariadb) | |
sed -i "s/172.17.0.3/$mariadb_addy/" wp-config.php | |
docker cp wp-config.php mywp:/var/www/html/wp-config.php | |
docker cp ssl-params.conf mywp:/etc/apache2/conf-available/ssl-params.conf | |
docker cp wordpress.conf mywp:/etc/apache2/sites-available/wordpress.conf | |
docker exec -i mywp bash < wp_provisioning.sh | |
docker restart mywp | |
docker exec -i mywp /etc/init.d/ssh start | |
- name: Install imagemagick | |
run: | | |
sudo apt-get -y install imagemagick | |
- name: Await return of mariadb container | |
run: | | |
sleeps=0 | |
while ! docker exec mariadb mysql -uroot -pmypass -e "SELECT 1" >/dev/null 2>&1; do | |
sleeps=$((sleeps + 1)) | |
if [[ $sleeps -ge 5 ]] | |
then | |
docker stats --no-stream | |
else | |
docker ps | |
fi | |
if [[ $sleeps -eq 12 ]] | |
then | |
exit 1 | |
fi | |
sleep $sleeps | |
done | |
- name: Use WP's IP for DB user | |
run: | | |
wp_addy=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' mywp) | |
echo "wp_addy = $wp_addy" | |
sed -i "s/wpdockerip/$wp_addy/" wpdbsetup.sql | |
cp tests/config_template.json tests/config.json | |
sed -i "s/localhost:8066/$wp_addy/" tests/config.json | |
cat tests/config.json | |
docker ps | |
- name: Grab WP's self-signed cert | |
run: | | |
echo quit | openssl s_client -showcerts -servername "localhost" -connect localhost:443 > self-signed-cacert.crt | |
- name: Inject SQL scripts to MySQL | |
run: | | |
docker exec -i mariadb mysql -uroot -pmypass < wpdbsetup.sql | |
docker exec -i mariadb mysql -uroot -pmypass wordpress < full_db_220727_0953.sql | |
- name: Acquire wp_api | |
run: | | |
git clone https://github.com/ployt0/wp_app_api.git | |
cp -r wp_app_api/wp_api img_compressor/ | |
- name: Test with pytest for coverage | |
run: | | |
cd tests | |
PYTHONPATH=../img_compressor coverage run --source="../img_compressor" --omit="../img_compressor/wp_api/*" -m pytest | |
- name: Test coverage | |
run: | | |
cd tests | |
PYTHONPATH=../img_compressor coverage report -m --fail-under=90 |