Automatically Crawl Novel #851
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
# 自动构建(避免编译异常,仅在 staging 分支构建,需手动合并) | |
name: Automatically Crawl Novel | |
on: | |
# 手动触发 | |
workflow_dispatch: | |
# 定时触发 | |
schedule: | |
- cron: '0 17 * * *' | |
jobs: | |
crawl: | |
runs-on: ubuntu-latest | |
# 当仓库隶属组织时,赋予流水线“写权限”以便提交变更 | |
permissions: | |
contents: write | |
steps: | |
- name: Check out repo | |
uses: actions/checkout@v3 | |
with: | |
ref: master | |
fetch-depth: 0 | |
- name: Setup Git Infomation | |
run: |- | |
git config --global user.name "${{ vars._GIT_USER }}" | |
git config --global user.email "${{ vars._GIT_MAIL }}" | |
- name: Setup Deploy Private Key | |
env: | |
DEPLOY_PRIVATE_KEY: ${{ secrets.DEPLOY_PRIVATE_KEY }} | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "$DEPLOY_PRIVATE_KEY" > ~/.ssh/id_rsa | |
chmod 400 ~/.ssh/id_rsa | |
ssh-keyscan github.com >> ~/.ssh/known_hosts | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.8 | |
- name: Configure pip caching | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install Python dependencies | |
run: | | |
python -m pip install -r requirements.txt | |
- name: Crawl | |
run: |- | |
python ./py/onekey.py -g "${{ secrets.CRAWL_PWD }}" -i "${{ secrets.API_ID }}" -k "${{ secrets.API_KEY }}" -a "${{ secrets.GPT_KEY }}" | |
- name: Build | |
run: |- | |
has_update=`git diff | wc -w | awk '{print $1}'` | |
if [ "${has_update}" != "0" ]; then | |
./bin/build.sh | |
fi | |
- name: Commit and push Github page (if changed) | |
run: |- | |
git add -A | |
git commit -m "Updated by Github Bot" || exit 0 | |
git push origin master | |