Update Dockerfile #19
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
name: Building and Testing | |
on: | |
# triggers the workflow on push or pull request events but only for the master branch | |
push: | |
branches: [ main ] | |
paths-ignore: | |
- '**/.md' | |
- '**/.yml' | |
- 'docs/**/*' | |
- LICENSE | |
- .gitignore | |
pull_request: | |
branches: [ main ] | |
# allow for workflow to be manually initiated from the Actions tab | |
workflow_dispatch: | |
jobs: | |
#build and test iso3166-updates | |
build_test: | |
name: Building and testing | |
timeout-minutes: 15 | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
# os: [ubuntu-latest, windows-latest] #testing on multiple OS's, macos-latest | |
os: [ubuntu-latest] | |
python-version: ["3.8", "3.9", "3.10"] #testing on multiple python versions | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python ${{ matrix.python-version }} #checkout repo | |
uses: actions/setup-python@v3 | |
with: | |
python-version: ${{ matrix.python-version }} #install python version | |
- uses: nanasess/setup-chromedriver@v2 | |
with: | |
# chromedriver-version: '88.0.4324.96' #install Chromedriver | |
chromedriver-version: '125.0.6422.60' #install Chromedriver | |
# install all required modules and dependancies using pip and requirements.txt file | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip3 install pytest bandit safety codecov | |
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
# install and setup Chromedriver on workflow runner | |
- name: Setup Chromedriver | |
run: | | |
export DISPLAY=:99 | |
chromedriver --url-base=/wd/hub & | |
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & # optional | |
#unit tests using unittest framework | |
- name: Running unit tests | |
run: | | |
echo "Testing using unittest..." | |
python3 -m unittest discover tests -v | |
#run various vulnerability, security and package checks | |
security_check: | |
name: Bandit and package safety check | |
timeout-minutes: 15 | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
# os: [ubuntu-latest, windows-latest] #testing on multiple OS's, macos-latest | |
os: [ubuntu-latest] | |
python-version: ["3.8", "3.9", "3.10"] #testing on multiple python versions | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v3 | |
with: | |
python-version: ${{ matrix.python-version }} | |
#create artifacts dir | |
- name: Artifacts mkdir | |
run: mkdir artifacts | |
#package vulnerability check | |
- name: Package safety check | |
run: | | |
echo "Running package safety check" | |
python3 -m safety check > artifacts/package_safety_output.txt | |
cat artifacts/package_safety_output.txt | |
continue-on-error: true | |
#run Bandit security check for any known vulnerabilities in code | |
- name: Bandit | |
run: | | |
echo "Running Bandit" | |
python3 -m bandit -r iso3166-updates > artifacts/bandit_output.txt | |
cat artifacts/bandit_output.txt | |
continue-on-error: true | |
#upload test artifacts to workflow | |
- name: Upload Test Artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: test_artifacts | |
path: | | |
artifacts/package_safety_output.txt | |
artifacts/bandit_output.txt | |
#linter check on repo | |
linter: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ["3.8", "3.9", "3.10"] #testing on multiple python versions | |
steps: | |
#checkout repo | |
- name: Checkout repo | |
uses: actions/checkout@v3 | |
# install all required modules and dependancies using pip installation | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install flake8 pytest | |
#create temp artifacts repo | |
- name: Artifacts mkdir | |
run: mkdir flake8_artifacts | |
#linting with flake8 | |
- name: Lint with flake8 | |
run: | | |
echo "Testing using flake8..." | |
# stop the build if there are Python syntax errors or undefined names | |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics > flake8_artifacts/flake8_output.txt | |
# 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 >> flake8_artifacts/flake8_output.txt | |
continue-on-error: true | |
#upload artifacts to repo | |
- name: Upload flake8 Artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: flake8_artifact | |
path: flake8_artifacts/flake8_output.txt | |
if-no-files-found: error | |
#linter check on repo | |
code_coverage: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ["3.10"] | |
steps: | |
#checkout repo | |
- name: Checkout repo | |
uses: actions/checkout@v3 | |
# install all required modules and dependancies using pip and requirements.txt file | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip3 install pytest pytest-cov codecov | |
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
#generate codecov report using pytest | |
- name: Generate Coverage report | |
run: | | |
pytest --cov . | |
#upload to Code Coverage, only if matrix python version is 3.10 | |
- name: Upload Coverage Report to Codecov | |
uses: codecov/codecov-action@v3 | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
with: | |
flags: iso3166_updates_workflow |