排序并发送邮件 #510
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: 排序并发送邮件 | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '30 22 * * *' | |
jobs: | |
setup-and-test: | |
runs-on: ubuntu-latest # 使用 Ubuntu 环境 | |
steps: | |
- name: 检出代码库 | |
uses: actions/checkout@v4 | |
with: | |
persist-credentials: true # 确保能够推送更改 | |
- name: 设置 Git | |
run: | | |
git config user.name "NowScott" | |
git config user.email "[email protected]" | |
- name: 设置 Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.x' | |
- name: 安装 Chrome 和 ChromeDriver | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y wget unzip | |
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb | |
sudo dpkg -i google-chrome-stable_current_amd64.deb || sudo apt-get -f install -y | |
wget -N https://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip | |
unzip chromedriver_linux64.zip -d /usr/local/bin/ | |
- name: 安装 Python 依赖 | |
run: | | |
python -m pip install --upgrade pip | |
pip install selenium webdriver-manager chromedriver-autoinstaller | |
- name: 运行 news_sorter.py | |
run: | | |
python src/news_sorter.py | |
- name: 设置环境变量并运行 main.py | |
env: | |
SENDING_ACCOUNT: ${{ secrets.SENDING_ACCOUNT }} | |
SENDING_PASSWORD: ${{ secrets.SENDING_PASSWORD }} | |
SERVER: ${{ secrets.SERVER }} | |
NOTION_API_KEY: ${{ secrets.NOTION_API_KEY }} | |
NOTION_DATABASE_ID: ${{ secrets.NOTION_DATABASE_ID }} | |
run: | | |
python src/main.py | |
- name: 提交更改 | |
run: | | |
git add news_archive/ # 添加所有未跟踪的文件 | |
echo "添加文件后的 Git 状态:" | |
git status | |
git diff --cached --exit-code news_archive/ || ( | |
DATE=$(TZ="Asia/Shanghai" date "+%Y-%m-%d %H:%M:%S") | |
echo "正在提交更改..." | |
git commit -m "更新新闻文件于 $DATE" | |
git push origin main | |
echo '更新成功' | |
) |