Github Actions (Lab 9)

Setting up

For my CI workflow, I went with Anaconda.

I altered the default YAML to run on push and pull requests on the main branch.

When installing dependencies, the default YAML looks for a environment.yml file. I don’t have that in my…


This content originally appeared on DEV Community and was authored by Ahmad

Setting up

For my CI workflow, I went with Anaconda.
Image description

I altered the default YAML to run on push and pull requests on the main branch.
Image description

When installing dependencies, the default YAML looks for a environment.yml file. I don't have that in my project so I set it up to install each dependency individually.
Image description

Testing the workflow

After committing the YAML, I noticed that the workflow failed with this reason:

Version 3.1 with arch x64 not found The list of all available versions can be found here: https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json

I fixed this by changing the python version to 3.9.5, the version on my local machine.
Image description

The workflow then passed successfully.
Image description

name: Python Package using Conda

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build-linux:
    runs-on: ubuntu-latest
    strategy:
      max-parallel: 5

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python 3.9.5
      uses: actions/setup-python@v2
      with:
        python-version: 3.9.5
    - name: Add conda to system path
      run: |
        # $CONDA is an environment variable pointing to the root of the miniconda directory
        echo $CONDA/bin >> $GITHUB_PATH
    - name: Install dependencies
      run: |
        conda install black
        conda install flake8
        conda install markdown
        conda install pygments
    - name: Lint with flake8
      run: |
        conda 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
    - name: Test with pytest
      run: |
        conda install pytest
        pytest

Writing a test for another repo

I chose to work on Roman Rezinkin's SSG for this part. I looked through his testing file roman_ssg_util.py for any functions he may have missed and found create_index_page().

After writing a simple test for it that calls the function and checks if the index page file was created, I created a pull request. The workflow Roman had set up passed and it was quickly merged.

def test_create_index_page():
    roman_ssg_util.create_index_page("en-US", ["1.html"])
    assert os.path.isfile("./index.html")
    os.remove("index.html")

Outcomes

This lab really showed me how powerful Github Actions can be, especially when reviewing pull requests. It ensures that the pull request adheres to your rules, customizable in the YAML file.


This content originally appeared on DEV Community and was authored by Ahmad


Print Share Comment Cite Upload Translate Updates
APA

Ahmad | Sciencx (2021-11-19T15:42:51+00:00) Github Actions (Lab 9). Retrieved from https://www.scien.cx/2021/11/19/github-actions-lab-9/

MLA
" » Github Actions (Lab 9)." Ahmad | Sciencx - Friday November 19, 2021, https://www.scien.cx/2021/11/19/github-actions-lab-9/
HARVARD
Ahmad | Sciencx Friday November 19, 2021 » Github Actions (Lab 9)., viewed ,<https://www.scien.cx/2021/11/19/github-actions-lab-9/>
VANCOUVER
Ahmad | Sciencx - » Github Actions (Lab 9). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/19/github-actions-lab-9/
CHICAGO
" » Github Actions (Lab 9)." Ahmad | Sciencx - Accessed . https://www.scien.cx/2021/11/19/github-actions-lab-9/
IEEE
" » Github Actions (Lab 9)." Ahmad | Sciencx [Online]. Available: https://www.scien.cx/2021/11/19/github-actions-lab-9/. [Accessed: ]
rf:citation
» Github Actions (Lab 9) | Ahmad | Sciencx | https://www.scien.cx/2021/11/19/github-actions-lab-9/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.