update workflows

This commit is contained in:
Muhan Li 2022-03-27 04:16:16 +08:00
parent 1b525d77cb
commit a14e4afda7
6 changed files with 82 additions and 41 deletions

3
.github/trigger.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"trigger": 0
}

View File

@ -6,8 +6,7 @@ on:
- "**"
pull_request:
branches:
- main
- dev
- "**"
jobs:
build:

68
.github/workflows/data.yml vendored Normal file
View File

@ -0,0 +1,68 @@
name: Update Calendar Data
on:
workflow_dispatch:
schedule:
- cron: "0 * * * *"
push:
branches:
- "**"
jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
fetch-depth: 2
- name: Set up Python environment
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Run crawler
shell: bash
run: python crawler.py
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Go Build
run: go build -o . main
- name: Generate ICS
run: ./main
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
file_pattern: docs/*.html docs/*.ics data/*.txt
commit_message: update calendar data automatically
commit_user_name: bugstop
commit_user_email: github@umm.one
- name: Get last commit message
id: last-commit-message
run: |
echo "::set-output name=msg::$(git log -1 --pretty=%s)"
- name: Update README
uses: stefanzweifel/git-auto-commit-action@v4
with:
file_pattern: README.md
commit_message: ${{ steps.last-commit-message.outputs.msg }}
commit_user_name: bugstop
commit_user_email: github@umm.one
commit_options: '--amend --no-edit'
push_options: '--force'
skip_fetch: true

View File

@ -1,34 +0,0 @@
name: ICS Generator
on:
pull_request:
push:
branches:
- "**"
jobs:
commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Go Build
run: go build -o . main
- name: Generate ICS
run: ./main
- uses: stefanzweifel/git-auto-commit-action@v4
with:
file_pattern: docs/*.html docs/*.ics
commit_message: generate .ics file automatically
commit_user_name: bugstep
commit_user_email: github@isaacx.com

View File

@ -2,7 +2,7 @@
subscription link of public holidays in mainland China
> data updated at: March 27, 2022
> Calendar data updated at: March 27, 2022.
## Demo

View File

@ -1,6 +1,6 @@
import os
import re
from datetime import datetime
from datetime import datetime, timezone, timedelta
from typing import Iterator, Tuple
import requests
@ -24,16 +24,16 @@ def main():
with open(file, 'w') as f:
f.write(
f"{comments[0]} ({datetime.now().strftime('%-m/%-d/%Y')})\n"
f"{comments[0]} ({beijing_time().strftime('%-m/%-d/%Y')})\n"
f"{comments[1]}\n\n// source: {link}\n\n{holidays}"
)
update_info = "> data updated at: "
update_info = "> Calendar data updated at: "
with open('./README.md', 'r') as f:
content = f.read().split('\n')
for i in range(len(content)):
if content[i].startswith(update_info):
content[i] = update_info + datetime.now().strftime("%B %-d, %Y")
content[i] = update_info + beijing_time().strftime("%B %-d, %Y")
with open('./README.md', 'w') as f:
f.write('\n'.join(content))
@ -102,5 +102,10 @@ def source() -> Iterator[Tuple[str, str]]:
yield match.group('year'), match.group('link')
def beijing_time() -> datetime:
utc_time = datetime.utcnow().replace(tzinfo=timezone.utc)
return utc_time.astimezone(timezone(timedelta(hours=8)))
if __name__ == '__main__':
main()