13. How can I automate things on GitHub#

We can use bash scripts on GitHub as GitHub Actions.

13.1. Let’s recall the course utils#

We can test it on the URI JupyterHub

To log in, Look in your e-mail for an e-mail about jupyterhub access

this is not secure or backed up

Warning

do not use the Jupyter hub server for any sensitive work (it is not secure) or as the only place for any work (it is not backed up; if something goes poorly data could be lost)

We can start with the courseutils

git clone https://github.com/introcompsys/courseutils.git
Cloning into 'courseutils'...
remote: Enumerating objects: 79, done.
remote: Counting objects: 100% (79/79), done.
remote: Compressing objects: 100% (51/51), done.
remote: Total 79 (delta 39), reused 59 (delta 25), pack-reused 0
Unpacking objects: 100% (79/79), done.

And then cd and install it

cd courseutils/
pip install .
Defaulting to user installation because normal site-packages is not writeable
Processing /mnt/homes4celsrs/brownsarahm/courseutils
  Preparing metadata (setup.py) ... done
Requirement already satisfied: Click in /mnt/homes4celsrs/brownsarahm/.local/lib/python3.6/site-packages (from syscourseutils==0.2.0) (8.0.4)
Requirement already satisfied: pandas in /usr/local/lib64/python3.6/site-packages (from syscourseutils==0.2.0) (1.0.3)
Requirement already satisfied: lxml in /mnt/homes4celsrs/brownsarahm/.local/lib/python3.6/site-packages (from syscourseutils==0.2.0) (4.9.1)
Requirement already satisfied: numpy in /usr/local/lib64/python3.6/site-packages (from syscourseutils==0.2.0) (1.19.5)
Requirement already satisfied: requests in /usr/lib/python3.6/site-packages (from syscourseutils==0.2.0) (2.21.0)
Requirement already satisfied: importlib-metadata in /usr/local/lib/python3.6/site-packages (from Click->syscourseutils==0.2.0) (4.8.3)
Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.6/site-packages (from pandas->syscourseutils==0.2.0) (2019.3)
Requirement already satisfied: python-dateutil>=2.6.1 in /usr/lib/python3.6/site-packages (from pandas->syscourseutils==0.2.0) (2.8.0)
Requirement already satisfied: idna<2.9,>=2.5 in /usr/lib/python3.6/site-packages (from requests->syscourseutils==0.2.0) (2.8)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/lib/python3.6/site-packages (from requests->syscourseutils==0.2.0) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3.6/site-packages (from requests->syscourseutils==0.2.0) (2019.3.9)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/lib/python3.6/site-packages (from requests->syscourseutils==0.2.0) (1.24.1)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.6/site-packages (from python-dateutil>=2.6.1->pandas->syscourseutils==0.2.0) (1.15.0)
Requirement already satisfied: typing-extensions>=3.6.4 in /usr/local/lib/python3.6/site-packages (from importlib-metadata->Click->syscourseutils==0.2.0) (3.7.4.3)
Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.6/site-packages (from importlib-metadata->Click->syscourseutils==0.2.0) (3.1.0)
Building wheels for collected packages: syscourseutils
  Building wheel for syscourseutils (setup.py) ... done
  Created wheel for syscourseutils: filename=syscourseutils-0.2.0-py3-none-any.whl size=3955 sha256=4721a1f1b878d3cd67fa4f5f23445cc6ed967135bd2c20f7245907a295815019
  Stored in directory: /tmp/pip-ephem-wheel-cache-yigr4d0i/wheels/59/c1/9a/20014d9884280647cef49c48abdc4fda76f1d452ca9110a7ad
Successfully built syscourseutils
Installing collected packages: syscourseutils
Successfully installed syscourseutils-0.2.0
sysgetassignment --date 2022-10-19

By default it gets the prepare for class tasks for that date

- [ ] On Windows, install Putty ( we will use this Monday)
2. Get ready for class by creating `networking.md` in your KWL repo with notes about what you know about networking
3. Add an issue on your KWL repo titled "Self Reflection 10/24" (there will be time on Monday for this, but giving you warning so you have time to think about it). Tag @brownsarahm on this issue.
```{index} networking.md
```
```
- [ ] Are you where you want to be in this course?
- [ ] Have you been getting feedback on your work?
- [ ] If not, what could help you get back on track?
- [ ] What if any concepts are you most struggling with?
```
sysgetassignment --date 2022-10-19 --type practice
- [ ] Make your script form class a nested loop to check for all 3 types of files
- [ ] Make a script that gets the updates to the course site and creates a single `todo-YYYY-MM-DD.md` file that has the review, prepare, and practice tasks in it  for each date that does not already exist in a `todo/` folder outside of your KWL repo. Save the script as `gathertasks.sh`


```{index} checker.sh
```
```{index} gathertasks.sh
```

13.2. Writing GitHub Action as bash script practice#

GitHub Actions allow us to run code on GitHub’s servers.

As a first script, we can put the following YAML content in.

on:
  workflow_dispatch

jobs:
  check-contents:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2

    # Install dependencies
    - name: Set up Python 3.8
      uses: actions/setup-python@v1
      with:
        python-version: 3.8

    - name: Install checker
      run: |
        pip install git+https://github.com/introcompsys/courseutils@main


    - name: check
      run: |
        pwd

The first two keys are configuration information.

  • on tells GitHub what triggers this action

  • jobs lists the things it has to do

In this case, we will trigger by the a button and our job is named check-contents

The next two things are settings for this job; first that it runs on ubuntu and then a list of steps to complete.

For each step (beginning with a -) we can give it a name (optional) and then either uses to choose something from the GitHub Action Marketplace or run to enter bash commands.

The first two steps are from the marketplace: checkout the repo and setup python.

Then we install the courseutils directly via git and the last step prints the working directory.

To use the action, add it as a file to .github/workflows/get_assignment.yml

Then run it and check the output

Then we can modify the script by replacing the pwd with the steps we actually need.

- name: check
  run: |
    sysgetassignment --date 2022-10-19 | gh issue create --title "review" --body-file -
  env:
    GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

This gets the todos from last week and creates an issue.

The env allows the GitHub action bot to actually edit the repo (make an issue)

13.3. Preview SSH#

13.4. Review today’s class#

  1. Review the notes

  2. Update your Get Assignments action to use the current date. Once the notes are posted, run it to get today’s tasks.

13.5. Prepare for Next Class#

  1. preview ssh materials

  2. Review your networking notes before class on Wednesday

13.6. More Practice#

  1. Brainstorm three potential uses for GitHub actions in actions.md