import #5294
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: import | |
on: | |
workflow_dispatch: {} | |
schedule: | |
- cron: "0 */3 * * *" | |
jobs: | |
import: | |
runs-on: ubuntu-latest | |
timeout-minutes: 3 | |
steps: | |
- name: Generate token | |
uses: tibdex/github-app-token@v2 | |
with: | |
app_id: ${{ secrets.MY_APP_ID }} | |
private_key: ${{ secrets.MY_APP_PRIVATE_KEY }} | |
id: generate_token | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ steps.generate_token.outputs.token }} | |
- name: Initialize node & npm | |
uses: ./.github/actions/npm | |
- run: npm run archive-images | |
env: | |
NOTION_API_KEY: ${{ secrets.NOTION_API_KEY }} | |
NOTION_DATABASE_ID: ${{ secrets.NOTION_DATABASE_ID }} | |
IMGUR_CLIENT_ID: ${{ secrets.IMGUR_CLIENT_ID }} | |
IMGUR_CLIENT_SECRET: ${{ secrets.IMGUR_CLIENT_SECRET }} | |
IMGUR_REFRESH_TOKEN: ${{ secrets.IMGUR_REFRESH_TOKEN }} | |
- if: success() | |
uses: ega4432/notion-to-markdown-action@v0 | |
id: import | |
with: | |
output_path: "./src/content/blog" | |
filename_property: "slug" | |
env: | |
NOTION_API_KEY: ${{ secrets.NOTION_API_KEY }} | |
NOTION_DATABASE_ID: ${{ secrets.NOTION_DATABASE_ID }} | |
- if: success() && steps.import.outputs.files_count > 0 | |
run: | | |
find src/content/blog -name "*.md" -type f -exec sh -c 'grep -q "draft: true" "$1" && rm "$1" || sed -i "/^slug:/d" "$1"' sh {} \; | |
- name: Commit & push | |
if: success() && steps.import.outputs.files_count > 0 | |
run: | | |
git config --local user.email "actions@github.com" | |
git config --local user.name "GitHub Actions" | |
git add -Av "*.md" | |
if ! git diff --cached --quiet --exit-code; then | |
git commit -m '[bot] Automatically import contents from Notion' | |
git push | |
fi |