-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GitHub Actions workflows for syncing with Notion
- Loading branch information
Showing
2 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Github to Notion Sync | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
update-notion: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# Step 1: Checkout Repository | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
# Step 2: Setup Node.js | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20' | ||
|
||
# Step 3: Install Dependencies | ||
- name: Install dependencies | ||
run: | | ||
npm install @notionhq/client dotenv | ||
# Step 4: Update Notion Page | ||
- name: Update Notion Page | ||
env: | ||
NOTION_API_KEY: ${{ secrets.NOTION_API_KEY }} | ||
NOTION_PAGE_ID: ${{ secrets.NOTION_PAGE_ID }} | ||
GITHUB_COMMIT_MSG: "${{ github.event.head_commit.message }}" | ||
run: | | ||
node ./project/update-notion.js |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
name: Notion to Github Sync | ||
|
||
on: | ||
schedule: | ||
- cron: '0 * * * *' # Runs every hour | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: write # Ensures write permissions for GITHUB_TOKEN | ||
|
||
jobs: | ||
fetch-notion-content: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# Step 1: Checkout repository | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # Ensures full history for pull/rebase | ||
|
||
# Step 2: Setup Node.js | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20' | ||
|
||
# Step 3: Install dependencies in 'project' directory | ||
- name: Install dependencies | ||
working-directory: ./project | ||
run: npm install | ||
|
||
# Step 4: Fetch Notion Content (Debugging Output) | ||
- name: Fetch Notion Content | ||
working-directory: ./project | ||
env: | ||
NOTION_API_KEY: ${{ secrets.NOTION_API_KEY }} | ||
NOTION_PAGE_ID: ${{ secrets.NOTION_PAGE_ID }} | ||
run: | | ||
echo "Using API Key: ${NOTION_API_KEY:0:4}***" | ||
echo "Using Page ID: ${NOTION_PAGE_ID}" | ||
node notion-sync.js > notion-output.log | ||
echo "Fetched Notion Content:" | ||
cat notion-output.log | ||
# Step 5: Configure Git | ||
- name: Configure Git | ||
run: | | ||
git config user.name "github-actions" | ||
git config user.email "[email protected]" | ||
# Step 6: Pull Remote Changes Before Committing | ||
- name: Pull Remote Changes | ||
run: | | ||
git fetch origin main | ||
git pull --rebase origin main || true | ||
# Step 7: Track Untracked Files and Debug Changes | ||
- name: Track Changes and Debug | ||
run: | | ||
echo "Staging Files for Commit:" | ||
git status | ||
git add -A | ||
git status | ||
# Step 8: Force Commit and Push Changes | ||
- name: Commit and Push Changes | ||
run: | | ||
git commit -m "Update: Fetched new Notion content" --allow-empty | ||
git push origin main | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Step 9: Final Debugging Output | ||
- name: Confirm Push Success | ||
run: | | ||
echo "Latest commit:" | ||
git log -1 |