Skip to content

Sync Notion to Google Tasks #133

Sync Notion to Google Tasks

Sync Notion to Google Tasks #133

name: Sync Notion to Google Tasks
on:
workflow_dispatch:
schedule:
- cron: '0 11,15,22 * * *'
jobs:
sync-notion:
name: Sync Notion to Google Tasks
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' # Only execute on the main branch
steps:
- name: Checkout Repository
uses: actions/checkout@v3
# 1) Ensure Python 3.10
- name: Ensure Python 3.10 in PATH (install if missing)
shell: bash
run: |
if command -v python3.10 &>/dev/null; then
echo "Python 3.10 is already installed at $(command -v python3.10)."
else
echo "Python 3.10 not found. Installing..."
sudo apt-get update
sudo apt-get install -y software-properties-common
sudo add-apt-repository -y ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install -y python3.10
fi
# Ensure Python 3.10 is available in PATH
if command -v python3.10 &>/dev/null; then
echo "$(dirname "$(command -v python3.10)")" >> $GITHUB_PATH
else
echo "ERROR: Python 3.10 installation failed."
exit 1
fi
# 2) Ensure Poetry
- name: Ensure Poetry in PATH (install if missing)
shell: bash
run: |
if command -v poetry &>/dev/null; then
echo "Poetry is already installed at $(command -v poetry)."
else
echo "Poetry not found. Installing..."
curl -sSL https://install.python-poetry.org | python3.10 -
# Add Poetry's bin directory to PATH for the current session
export PATH="$HOME/.local/bin:$PATH"
fi
# Ensure Poetry is available in PATH
if command -v poetry &>/dev/null; then
echo "$(dirname "$(command -v poetry)")" >> $GITHUB_PATH
else
echo "ERROR: Poetry not found after installation."
exit 1
fi
# 3) Validate Dependencies
- name: Validate Dependencies
shell: bash
run: |
echo "=== Checking Python 3.10 ==="
command -v python3.10 || { echo "Python 3.10 not found"; exit 1; }
python3.10 --version
echo "=== Checking Poetry ==="
command -v poetry || { echo "Poetry not found"; exit 1; }
poetry --version
echo "=== Running poetry check ==="
poetry check
working-directory: ${{ github.workspace }}
# 4) Configure Poetry environment to use Python 3.10
- name: Set Poetry Env to Python 3.10
shell: bash
run: |
poetry env use python3.10
working-directory: ${{ github.workspace }}
# 5) Install Dependencies
- name: Install Dependencies
shell: bash
run: |
poetry install
working-directory: ${{ github.workspace }}
# 6) Install jq for JSON parsing
- name: Install jq
shell: bash
run: sudo apt-get install -y jq
# 7) Retrieve last successful sync time
- name: Retrieve last successful sync time
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
OWNER="MarcChen"
REPO="Notion2GoogleTasks"
WORKFLOW_FILE="sync_notion_to_google.yml"
# Fetch last successful run details
last_successful_run=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$OWNER/$REPO/actions/workflows/$WORKFLOW_FILE/runs?status=success&per_page=1")
# Extract created_at timestamp
created_at=$(echo "$last_successful_run" | jq -r '.workflow_runs[0].created_at')
# Set default if no previous successful run
if [[ "$created_at" == "null" || -z "$created_at" ]]; then
created_at="2020-01-01T00:00:00Z"
fi
echo "LAST_SUCCESSFUL_SYNC=$created_at" >> $GITHUB_ENV
# 8) Generate Google API Token
- name: Generate Google API Token
shell: bash
run: |
poetry run python services/google_task/config/config_creds.py --save_dir .
working-directory: ${{ github.workspace }}
env:
GOOGLE_ACCESS_TOKEN: ${{ secrets.GOOGLE_ACCESS_TOKEN }}
GOOGLE_REFRESH_TOKEN: ${{ secrets.GOOGLE_REFRESH_TOKEN }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
# 9) Sync Notion to Google Tasks
- name: Sync Notion to Google Tasks
shell: bash
run: |
export TOKEN_PATH="${{ github.workspace }}/token.json"
poetry run python main.py
working-directory: ${{ github.workspace }}
env:
NOTION_API: ${{ secrets.NOTION_API }}
DATABASE_ID: ${{ secrets.DATABASE_ID }}
PROJECT_ROOT: ${{ github.workspace }}
FREE_MOBILE_USER_ID: ${{ secrets.FREE_MOBILE_USER_ID }}
FREE_MOBILE_API_KEY: ${{ secrets.FREE_MOBILE_API_KEY }}
LAST_SUCCESSFUL_SYNC: ${{ env.LAST_SUCCESSFUL_SYNC }}