As I just know, the GitHub actions has a function that could execute your scripts automatically. The next will illustrate how to achieve that:|
step_1 You should be familiar with the basic uses of GitHub actions firstly.
step_2 You will make a file and write some codes in it.
name: automatic_punch_in
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
schedule:
- cron: "10 20 * * 1" # 此处设置为每周一的八点十分触发下面的jobs
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
# Runs a single command using the runners shell
- name: set up python
uses: 'actions/setup-python@v2'
with:
python-version: '3.8'
- name: install modules
run: 'pip install -r requirements.txt'
- name: auto checkin
run: python Punch_in_automatically.py
env:
SCKEY: ${{ secrets.SCKEY }} #this codes will make your python scripts could use os.environ.get() get the
If you just want to run your python scripts without any additional variables to use, you don’t need to add env: stuff.
The corresponding code to SCKEY in python is as follows:
user = json.loads(environ["SCKEY"] if 'SCKEY' in environ else '{}')
print(type(user))
assert 'userName' in user and 'passWord' in user
userName = user["userName"]
passWord = user["passWord"]
It is easy to understand that the username and password are secret info. that we don’t want others know that. But we also hope others could use these codes. The above python code just tell you how to use the variables in secrets.
The following will tell you that how to set the secret variables: