Last active
August 12, 2024 09:01
-
-
Save prutya/0d4ffa6d1d5205d2292d297a31c16bda to your computer and use it in GitHub Desktop.
Scheduled content update in a GitHub repository that triggers a static website build and publishes the result to Cloudflare Pages
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
name: Update Content on schedule | |
on: | |
schedule: | |
- cron: "13 0,12 * * *" | |
workflow_dispatch: {} | |
jobs: | |
trigger-update-content: | |
runs-on: ubuntu-latest | |
timeout-minutes: 5 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Dispatch the Update Content workflow | |
env: | |
# A Github Personal Access Token with access to the repository | |
# that has the follwing permissions: | |
# ✅ Read and Write access to actions | |
GH_TOKEN: ${{ secrets.GITHUB_PAT_ACTIONS }} | |
run: | | |
gh workflow run "Update Content" --ref main |
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
name: Update Content | |
on: | |
workflow_dispatch: {} | |
jobs: | |
download-content: | |
runs-on: ubuntu-latest | |
timeout-minutes: 5 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
# A Github Personal Access Token with access to the repository | |
# that has the follwing permissions: | |
# ✅ Read and Write access to code | |
token: ${{ secrets.GITHUB_PAT_CONTENT }} | |
- name: Setup pnpm | |
uses: pnpm/action-setup@v4 | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: .node-version | |
cache: pnpm | |
- name: Install node modules | |
run: | | |
pnpm --version | |
pnpm install --frozen-lockfile | |
- name: Download articles content from Notion | |
env: | |
NOTION_KEY: "${{ secrets.NOTION_KEY }}" | |
NOTION_ARTICLES_DATABASE_ID: "${{ secrets.NOTION_ARTICLES_DATABASE_ID }}" | |
run: | | |
pnpm download-articles | |
- name: Download bookmarks content from Notion | |
env: | |
NOTION_KEY: ${{ secrets.NOTION_KEY }} | |
NOTION_BOOKMARKS_DATABASE_ID: ${{ secrets.NOTION_BOOKMARKS_DATABASE_ID }} | |
run: | | |
pnpm download-bookmarks | |
- name: Configure Git | |
run: | | |
git config --global user.email "${{ secrets.GIT_USER_EMAIL }}" | |
git config --global user.name "${{ secrets.GIT_USER_NAME }}" | |
- name: Check if anything changed | |
id: check-changes | |
run: | | |
if [ -n "$(git status --porcelain)" ]; then | |
echo "There are changes" | |
echo "HAS_CHANGED=true" >> $GITHUB_OUTPUT | |
else | |
echo "There are no changes" | |
echo "HAS_CHANGED=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Commit changes | |
if: steps.check-changes.outputs.HAS_CHANGED == 'true' | |
run: | | |
git add ./src/content | |
git add ./public | |
git commit -m "Automatic content update commit" | |
git push |
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
name: Push | |
on: | |
push: | |
branches: [main] | |
workflow_dispatch: {} | |
jobs: | |
deploy-cloudflare-pages: | |
runs-on: ubuntu-latest | |
timeout-minutes: 5 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup pnpm | |
uses: pnpm/action-setup@v4 | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: .node-version | |
cache: pnpm | |
- name: Install node modules | |
run: | | |
pnpm --version | |
pnpm install --frozen-lockfile | |
- name: Build the App | |
run: | | |
pnpm build | |
- name: Publish Cloudflare Pages | |
env: | |
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
run: | | |
pnpm wrangler pages deploy ./out --project-name ${{ secrets.CLOUDFLARE_PROJECT_NAME }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment