GitHub创建Github Action流水线来定时执行任务

发布时间 2023-05-17 16:49:46作者: WhoKnows1

1、github Action (工作流)

简单理解就是自动化部署、测试。也就是之前人工手动部署变为现在由机器(服务器)自动部署、测试了。

 

2、新建任务脚本

找一个自己的不重要的仓库(必须是public),创建任务脚本record.sh,脚本就是定期要做的动作

 

#!/usr/bin/env bash
git pull
date_str=$(date '+%Y-%m-%d %H:%M')
echo "${date_str}: Record it" > ./README.md

git add ./README.md
git commit -m "${date_str}"

 

 

3、创建github工作流

 

 

记得修改下面的提交人和提交邮箱哦,其它不用改~

 

# nothing

name: Update regularly every hour

# daily job
on:
    push:
    schedule:
        -
            # every hour
            cron: 0 * * * *

# 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

            # Setup git
            -
                name: Setup Git Infomation
                run: |
                    git config --global user.name 'lxzh'
                    git config --global user.email '1239848066@qq.com'
            # Record (use record.sh or record2.sh)
            -
                name: Recording
                run: |
                    sh ./record.sh
            -
                name: Pushing
                run: |
                    git push https://${{github.actor}}:${{secrets.GITHUB_TOKEN}}@github.com/${{github.repository}}.git HEAD:${{ github.ref }} || echo "No changes to commit"