Deploy Telethon #1
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: Deploy Telethon | |
on: | |
schedule: | |
- cron: '*/30 * * * *' # 每 30 分钟运行一次 | |
push: | |
branches: | |
- master | |
workflow_dispatch: # 添加这一行以支持手动触发 | |
jobs: | |
run-telethon-bot: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.9' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Decrypt Telethon session file | |
env: | |
API_ID: ${{ secrets.API_ID }} | |
SESSION_PASSWORD: ${{ secrets.SESSION_PASSWORD }} | |
run: | | |
openssl aes-256-cbc -d -pbkdf2 -in "${{ secrets.API_ID }}session_name.session.enc" -out "${{ secrets.API_ID }}session_name.session" -pass pass:"${{ secrets.SESSION_PASSWORD }}" | |
- name: Get previous workflow run ID | |
uses: actions/github-script@v6 | |
id: get-previous-run-id | |
with: | |
script: | | |
const runs = await github.rest.actions.listWorkflowRuns({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: 'main.yml', | |
per_page: 1, | |
status: 'success', | |
}); | |
if (runs.data.workflow_runs.length > 0) { | |
core.setOutput('run_id', runs.data.workflow_runs[0].id); | |
} else { | |
core.setFailed('No previous successful workflow run found'); | |
} | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: last_read_message | |
path: . | |
run-id: ${{ steps.get-previous-run-id.outputs.run_id }} | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
continue-on-error: true | |
- name: Display structure of downloaded files | |
run: ls -R | |
- name: Check for last_read_message_id.json | |
run: | | |
if [ -f last_read_message_id.json ]; then | |
echo "last_read_message_id.json exists." | |
else | |
echo "last_read_message_id.json does not exist." | |
fi | |
- name: Run Telethon script | |
env: | |
API_ID: ${{ secrets.API_ID }} | |
API_HASH: ${{ secrets.API_HASH }} | |
PHONE_NUMBER: ${{ secrets.PHONE_NUMBER }} | |
WORK_BOT_ID: ${{ secrets.WORK_BOT_ID }} | |
WORK_CHAT_ID: ${{ secrets.WORK_CHAT_ID }} | |
PUBLIC_BOT_ID: ${{ secrets.PUBLIC_BOT_ID }} | |
WAREHOUSE_CHAT_ID: ${{ secrets.WAREHOUSE_CHAT_ID }} | |
run: | | |
python hello.py | |
- name: Check if last_read_message_id.json was created | |
run: | | |
if [ -f last_read_message_id.json ]; then | |
echo "last_read_message_id.json was created." | |
else | |
echo "last_read_message_id.json was not created." | |
fi | |
- name: Upload last_read_message_id.json artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: last_read_message | |
path: last_read_message_id.json | |