Creating a workflow file

GitHub flow is a lightweight branch that was recently introduced by GitHub. Let's perform the following steps to create our first workflow:

  1. Sign in to your GitHub account at https://github.com/.
  2. Select a repository where you have maintainer access. In our example, we are using the fork of the k8sdevopscookbook/python-flask-docker project.
  1. Create a ci.yml file in the .github/workflows directory with the following content:
name: My Application
on:
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-16.04
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
  1. Add the following lines to install any dependencies:
    - name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
  1. When using computer programming languages, lint tools are used to perform static analysis of source code to check for semantic discrepancies. In our example, we will use flake8 to lint our Python code using the following command:
 - name: Lint with flake8
run: |
pip install flake8
# 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
  1. If you have unit tests, add the following lines to test your application with pytest, a framework that's used in Python programming to write small tests:
 - name: Test with pytest
run: |
pip install pytest
pytest

  1. After the configuration is complete, send a pull request to your repository to trigger the pipeline:

After the pipeline is complete, you will be able to see a green checkmark on your Pull Request (PR). In the preceding screenshot, you can see that all the checks have passed and that the pull request was successful.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.120.187