Skip to content

Import and Commit Content #81

Import and Commit Content

Import and Commit Content #81

Workflow file for this run

name: Import and Commit Content
on:
workflow_dispatch:
workflow_call:
permissions:
contents: write
actions: write
jobs:
import-and-commit:
name: Import content and commit
runs-on: ubuntu-latest
environment:
name: github-pages
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "npm"
# Cache node_modules to avoid reinstalling
- name: Restore node_modules cache
id: node-modules-cache
uses: actions/cache@v4
with:
path: |
node_modules
~/.cache/puppeteer
~/.cache/ms-playwright
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-
- name: Install dependencies
if: steps.node-modules-cache.outputs.cache-hit != 'true'
run: npm ci
- name: Import content
run: npm run import
env:
STADIA_MAPS_API_KEY: ${{ secrets.STADIA_MAPS_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Save node_modules cache if it wasn't cached
- name: Save node_modules cache
if: steps.node-modules-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: |
node_modules
~/.cache/puppeteer
~/.cache/ms-playwright
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
- name: Commit content updates
id: commit
run: |
# Configure git
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# Get meta.json values for commit message
git show HEAD:meta.json > /tmp/old_meta.json 2>/dev/null || echo '{}' > /tmp/old_meta.json
OLD_EVENT_SLUG=$(jq -r '.nextEventSlug // ""' /tmp/old_meta.json)
NEW_COMMIT=$(jq -r '.commitHash' meta.json)
NEW_EVENT_SLUG=$(jq -r '.nextEventSlug // ""' meta.json)
echo "Old event slug: $OLD_EVENT_SLUG"
echo "New event slug: $NEW_EVENT_SLUG"
echo "New commit: $NEW_COMMIT"
# Check for content changes
CONTENT_CHANGES=$(git status --porcelain content/)
# Check if event slug changed (event ended)
EVENT_ENDED=false
if [ -n "$OLD_EVENT_SLUG" ] && [ "$OLD_EVENT_SLUG" != "$NEW_EVENT_SLUG" ]; then
EVENT_ENDED=true
fi
echo "Content changes: ${CONTENT_CHANGES:-none}"
echo "Event ended: $EVENT_ENDED"
# Only commit if actual content changed OR event ended
if [ -n "$CONTENT_CHANGES" ] || [ "$EVENT_ENDED" = true ]; then
# Stage changes
git add content/ meta.json
# Determine commit message
if [ -n "$CONTENT_CHANGES" ]; then
git commit -m "Auto import content from https://github.com/oktechjp/public/commit/$NEW_COMMIT"
else
git commit -m "Auto event end rebuild: $OLD_EVENT_SLUG"
fi
git push
echo "Content updates committed and pushed"
echo "changes_committed=true" >> $GITHUB_OUTPUT
else
echo "No content changes and no event end. Skipping commit."
echo "changes_committed=false" >> $GITHUB_OUTPUT
fi
- name: Trigger build workflow
if: steps.commit.outputs.changes_committed == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'astro.yml',
ref: 'main'
})
console.log('Build workflow triggered successfully')