Sync IDF Messages #89
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: Sync IDF Messages | |
on: | |
schedule: | |
- cron: '0 1 * * *' # Runs daily at 1 AM UTC | |
workflow_dispatch: | |
jobs: | |
sync-telegram: | |
runs-on: | |
group: ims-cloud | |
labels: [self-hosted, Linux, X64, Python] | |
environment: Telegram | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Verify session and state files exist locally | |
run: | | |
# Ensure the session file exists in the specified path | |
if [ ! -f "/home/ims/session-file/session_telegram_scraper.session" ]; then | |
echo "Session file not found at /home/ims/session-file!" | |
exit 1 | |
fi | |
echo "Session file found at /home/ims/session-file!" | |
# Ensure the state file exists in the specified path | |
if [ ! -f "/home/ims/session-file/last_message_state.json" ]; then | |
echo "State file not found at /home/ims/session-file!" | |
exit 1 | |
fi | |
echo "State file found at /home/ims/session-file!" | |
shell: bash | |
- name: Copy session file to working directory | |
run: | | |
# Copy the local session file to the expected code directory | |
cp /home/ims/session-file/session_telegram_scraper.session code/telegram/session_telegram_scraper.session | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
- name: Cache Python dependencies | |
uses: actions/cache@v4 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('code/telegram/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install dependencies | |
run: pip install --no-cache-dir -r code/telegram/requirements.txt | |
- name: Run IDF Telegram scraping script | |
env: | |
TELEGRAM_API_ID: ${{ secrets.TELEGRAM_API_ID }} | |
TELEGRAM_API_HASH: ${{ secrets.TELEGRAM_API_HASH }} | |
R2_ACCESS_KEY: ${{ secrets.R2_ACCESS_KEY }} | |
R2_SECRET_KEY: ${{ secrets.R2_SECRET_KEY }} | |
R2_BUCKET_NAME: ${{ secrets.R2_BUCKET_NAME }} | |
R2_ENDPOINT_URL: ${{ secrets.R2_ENDPOINT_URL }} | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
python code/telegram/export_idf_telegram.py | |
- name: Commit and push changes | |
run: | | |
git config --global user.name "${{ secrets.GIT_USER_NAME }}" | |
git config --global user.email "${{ secrets.GIT_USER_EMAIL }}" | |
git add . | |
git commit -m "Sync Telegram messages [$(date -u)]" || echo "No changes to commit" | |
git push | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |