# This is a basic workflow to help you get started with Actions
name: vpn
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
#pull_request:
#branches: [ main ]
schedule:
- cron: '40 0/2 * * *'
# 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
- name: Checkout
uses: actions/checkout@v2
# Runs a single command using the runners shell
- name: 'Set up Python'
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: 'Install requirements'
run: pip install -r ./Spider/requirements.txt
- name: 'Working'
run:
python ./Spider/vpn.py
- name: commit
run: |
git config --global user.email 3196@qq.com
git config --global user.name ndt
git add .
git commit -m "update" -a
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
代码解释:
第一行name: 随便可以设置,就是你的action名字 on: 触发条件,我这里设置的是push操作一旦发生就出发 jobs: Github Actions的层级关系是这样的: workflow/jobs/steps/action。 注意将action和Github Actions中的Actions区分开来,二者是不同的概念,action就表示最低level的动作,Actions就是Github给我们提供的一个功能的名字而已。 steps:和jobs类似。可以看到steps由若干个step组成,每个step都可以设置name uses:这个表示使用别人预先设置好的Actions,比如因为我代码中要用到python,所以就用了actions/setup-python@v1来设置python环境,不用我自己设置了。 run: 表示具体运行什么命令行代码 可以看到,我首先在名字为Update paper list里运行了python脚本 之后对github文件夹做了commit(commit 一定先在仓库里创建README) 最后使用别人的actions把更新后的代码再次push到github 最后一行github_token这个设置方法是进入你在个人设置页面(即Settings,不是仓库里的Settings),选择Developer settings>Personal access tokens>Generate new token,设置名字为GITHUB_TOKEN,然后勾选repo,admin:repo_hook,workflow等选项,最后点击Generate token即可。