Skip to content

Commit

Permalink
Merge pull request #18 from nalbam/main
Browse files Browse the repository at this point in the history
chore: Update sync-notion and start-ingestion workflows
  • Loading branch information
nalbam authored Aug 22, 2024
2 parents 9517f7e + 9ebea33 commit 5c8e234
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 63 deletions.
48 changes: 0 additions & 48 deletions .github/workflows/4-sync-notion.yml.stop

This file was deleted.

68 changes: 68 additions & 0 deletions .github/workflows/5-sync-notion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: sync-notion

on:
push:
branches:
- main

schedule:
- cron: "0 20 * * 0-4"

env:
ENABLE_NOTION_SYNC: ${{ vars.ENABLE_NOTION_SYNC }}

NOTION_PAGE_NAME: "nalbam"
NOTION_PAGE_ID: "7aace0412a82431996f61a29225a95ec"

AWS_DEST_PATH: ${{ vars.AWS_DEST_PATH }}

KNOWLEDGE_BASE_ID: ${{ vars.KNOWLEDGE_BASE_ID }}
DATA_SOURCE_ID: ${{ vars.DATA_SOURCE_ID }}

jobs:
sync:
runs-on: ubuntu-latest

steps:
- name: Checkout 🛎️
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Python 3.9 🐍
uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Setup Dependencies
run: pip install python-notion-exporter

- name: Run Notion Exporter
if: env.ENABLE_NOTION_SYNC == 'Yes'
env:
NOTION_TOKEN_V2: ${{ secrets.NOTION_TOKEN_V2 }}
NOTION_FILE_TOKEN: ${{ secrets.NOTION_FILE_TOKEN }}
run: |
python bin/notion_exporter.py
- name: Sync to AWS S3 Data Source
if: env.ENABLE_NOTION_SYNC == 'Yes'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: "us-east-1"
run: |
aws s3 sync --delete \
build/${{ env.NOTION_PAGE_NAME }}/ \
${{ env.AWS_DEST_PATH }}/${{ env.NOTION_PAGE_NAME }}/
- name: Sync to AWS Bedrock Knowledge Base
if: env.ENABLE_NOTION_SYNC == 'Yes'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: "us-east-1"
run: |
aws bedrock-agent start-ingestion-job \
--knowledge-base-id ${{ env.KNOWLEDGE_BASE_ID }} \
--data-source-id ${{ env.DATA_SOURCE_ID }}
11 changes: 7 additions & 4 deletions .github/workflows/6-start-ingestion.yml.stop
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
- cron: "0 21 * * 0-4"

env:
ENABLE_NOTION_SYNC: ${{ vars.ENABLE_NOTION_SYNC }}

KNOWLEDGE_BASE_ID: ${{ vars.KNOWLEDGE_BASE_ID }}
DATA_SOURCE_ID: ${{ vars.DATA_SOURCE_ID }}

Expand All @@ -28,11 +30,12 @@ jobs:
python-version: 3.9

- name: Sync to AWS Bedrock Knowledge Base
run: |
aws bedrock-agent start-ingestion-job \
--knowledge-base-id ${{ env.KNOWLEDGE_BASE_ID }} \
--data-source-id ${{ env.DATA_SOURCE_ID }}
if: env.ENABLE_NOTION_SYNC == 'Yes'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: "us-east-1"
run: |
aws bedrock-agent start-ingestion-job \
--knowledge-base-id ${{ env.KNOWLEDGE_BASE_ID }} \
--data-source-id ${{ env.DATA_SOURCE_ID }}
6 changes: 3 additions & 3 deletions bin/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NOTION_TOKEN = "v02%3Auser_token_or_cookies"
NOTION_TOKEN_V2 = "v02%3Auser_token_or_cookies"
NOTION_FILE_TOKEN = "v02%3Afile_token"

NOTION_PAGE_ID = "0c7c08203a9b4435a4ca07b6454151d7"
NOTION_PAGE_NAME = "notion"
NOTION_PAGE_NAME = "nalbam"
NOTION_PAGE_ID = "7aace0412a82431996f61a29225a95ec"
6 changes: 3 additions & 3 deletions bin/notion_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
from python_notion_exporter import NotionExporter, ExportType, ViewExportType


NOTION_TOKEN = os.getenv("NOTION_TOKEN")
NOTION_TOKEN_V2 = os.getenv("NOTION_TOKEN_V2")
NOTION_FILE_TOKEN = os.getenv("NOTION_FILE_TOKEN")

NOTION_PAGE_ID = os.getenv("NOTION_PAGE_ID", "0c7c08203a9b4435a4ca07b6454151d7")
NOTION_PAGE_NAME = os.getenv("NOTION_PAGE_NAME", "demo")
NOTION_PAGE_ID = os.getenv("NOTION_PAGE_ID", "7aace0412a82431996f61a29225a95ec")


if __name__ == "__main__":
exporter = NotionExporter(
token_v2=NOTION_TOKEN,
token_v2=NOTION_TOKEN_V2,
file_token=NOTION_FILE_TOKEN,
pages={NOTION_PAGE_NAME: NOTION_PAGE_ID},
export_directory="build",
Expand Down
18 changes: 13 additions & 5 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,19 @@ resources:
TimeToLiveSpecification:
AttributeName: expire_at
Enabled: true
# S3Bucket:
# Type: AWS::S3::Bucket
# Properties:
# BucketName:
# Fn::Sub: ${self:provider.environment.BASE_NAME}-${AWS::AccountId}
Tags:
- Key: Project
Value: ${self:provider.environment.BASE_NAME}

S3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName:
Fn::Sub: ${self:provider.environment.BASE_NAME}-${AWS::AccountId}
Tags:
- Key: Project
Value: ${self:provider.environment.BASE_NAME}

# KnowledgeBase:
# Type: AWS::Bedrock::KnowledgeBase
# Properties:
Expand Down

0 comments on commit 5c8e234

Please sign in to comment.