image update action #97
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: image update action | |
# on 触发条件 | |
on: | |
# 定时触发 | |
schedule: | |
# UTC时间与北京时间8小时时差 | |
# UTC时间 18点执行一次,即UTC+8北京时间 2点执行一次 | |
- cron: '0 18 * * *' | |
# 监听 git push 到指定分支时触发 | |
push: | |
branches: | |
- main | |
# 人工触发 | |
workflow_dispatch: | |
inputs: | |
begin_date: | |
description: 'begin_date' | |
required: false | |
type: string | |
end_date: | |
description: 'end_date' | |
required: false | |
type: string | |
env: | |
# 需要用到本地时间 | |
TZ: Asia/Shanghai | |
jobs: | |
build: | |
# 指定执行系统环境 | |
runs-on: ubuntu-latest | |
permissions: | |
# 为这个 Job 新增了写权限 | |
contents: write | |
# 执行的步骤 | |
steps: | |
# 拉取分支代码 | |
- name: checkout out | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.ref }} | |
# 安装 Python 环境 | |
- name: set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.9 | |
# 缓存pip全局缓存目录 | |
cache: 'pip' | |
# 爬取壁纸 | |
- name: crawl bing image | |
run: | | |
python -m pip install --upgrade pip | |
if [ -f requirements.txt ]; then pip install -r requirements.txt -i http://pypi.doubanio.com/simple --trusted-host pypi.doubanio.com; fi | |
python code/action.py ${{ github.event.inputs.begin_date }} ${{ github.event.inputs.end_date }} | |
# 提交文件 | |
- name: commit and push | |
run: | | |
git config --local user.name 'github-actions' | |
git config --local user.email '[email protected]' | |
git add . | |
git commit -m "$(git config user.name) Auto Update At `TZ=UTC-8 date +%Y-%m-%d\ %H:%M:%S`" | |
git push | |
continue-on-error: true | |
- name: check on failures | |
if: steps.commit.outputs.status == 'failure' | |
run: exit 1 | |
# deploy: | |
# needs: build | |
# permissions: | |
# pages: write | |
# id-token: write | |
# environment: | |
# name: my-pages | |
# url: ${{ steps.deployment.outputs.page_url }} | |
# runs-on: ubuntu-latest | |
# steps: | |
# - name: upload | |
# uses: actions/upload-pages-artifact@v3 | |
# with: | |
# path: ./docs/_site | |
# name: my-pages | |
# retention-days: 1 | |
# - name: deploy | |
# id: deployment | |
# uses: actions/deploy-pages@v4 |