demo功能

定时设置每小时的30分时,将当前时间写入txt文件中,将更新的txt文件重新上传github仓库中

python文件

1
2
3
4
5
6
7
import datetime

now = datetime.datetime.now() + datetime.timedelta(hours=8)
current_time = now.strftime("%Y-%m-%d %H:%M:%S")

with open("demo/nowtime.txt", "w") as f:
f.write(current_time)

配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
name: test

on:
schedule:
# 设置定时启动的时间
- cron: '30 * * * *'

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

# 设置python3.9环境
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9

# 设置运行的python文件的路径
- name: run python
run: python demo/test.py

# 将运行结束后修改的文件暂存提交
- name: update repo
run: |
git config --global user.email 623156869@qq.com
git config --global user.name LinRS1999
git add .
git commit -m "update time"

# 推送至仓库
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}