Skip to content

Commit

Permalink
Fetch & process with github action instead
Browse files Browse the repository at this point in the history
  • Loading branch information
narze committed Sep 29, 2024
1 parent c97b813 commit 0b409c0
Show file tree
Hide file tree
Showing 6 changed files with 279 additions and 203 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/fetch-second-brain.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Fetch Second Brain
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
workflow_dispatch:

jobs:
fetch-second-brain:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22

# Pnpm
- uses: pnpm/action-setup@v2
name: Install pnpm
id: pnpm-install
with:
version: 8
run_install: false
- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install

- name: Fetch Second Brain
run: pnpm run fetch-second-brain

- name: Commit changes
run: |
git config --global user.email "[email protected]"
git config --global user.name "narze's bot"
# Check if there are any changes
if [[ -n "$(git status --porcelain)" ]]; then
# Get list of changed files
CHANGED_FILES=$(git status --porcelain | awk '{print $2}' | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/, /g' -e 's/, $//')
# Commit changes
git add -A
git commit -m "Updated: $CHANGED_FILES"
# Push changes
git push
else
echo "No changes to commit"
fi
4 changes: 2 additions & 2 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig } from "astro/config"
import mdx from "@astrojs/mdx"
import sitemap from "@astrojs/sitemap"
import githubFetchIntegration from "./src/lib/github-fetch-integration"
// import githubFetchIntegration from "./src/lib/github-fetch-integration"
import svelte from "@astrojs/svelte"
import tailwind from "@astrojs/tailwind"

Expand All @@ -28,7 +28,7 @@ export default defineConfig({
integrations: [
mdx(),
sitemap(),
githubFetchIntegration(),
// githubFetchIntegration(),
svelte(),
tailwind(),
],
Expand Down
8 changes: 8 additions & 0 deletions fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {
fetchSecondBrain,
postProcess,
} from "./src/lib/github-fetch-integration"
;(async () => {
await fetchSecondBrain()
await postProcess()
})()
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dev:search": "astro build && pagefind --source dist --bundle-dir pagefind --serve & open http://localhost:1414",
"test": "playwright test",
"start": "astro dev",
"fetch": "tsx fetch.ts",
"build": "run-s -c \"astro build\" build:post",
"build:post": "pagefind --source dist --bundle-dir pagefind",
"preview": "astro preview",
Expand Down
85 changes: 44 additions & 41 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0b409c0

Please sign in to comment.