Skip to content

fetch_second_brain

fetch_second_brain #25

name: Fetch Second Brain
on:
repository_dispatch:
types: [fetch_second_brain]
# push:
# branches: [main, master]
pull_request:
branches: [main, master]
workflow_dispatch:
jobs:
fetch-second-brain:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PAT }} # Use PAT for checkout
- uses: actions/setup-node@v4
with:
node-version: 22
# Pnpm
- uses: pnpm/action-setup@v4
name: Install pnpm
id: pnpm-install
with:
version: latest
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@v4
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
- name: Commit and push changes
env:
PAT: ${{ secrets.PAT }}
run: |
git config --global user.email "notbarze@users.noreply.github.com"
git config --global user.name "narze's bot"
# Get the current branch name
BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
# 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 "Changes: $CHANGED_FILES"
# Push changes
git push https://$PAT@github.com/${{ github.repository }}.git HEAD:$BRANCH_NAME
else
echo "No changes to commit"
fi