Merge pull request #11 from openteams-ai/update-pkg-bench #17
This file contains hidden or 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: Publish to WordPress | |
| on: | |
| push: | |
| branches: [main] | |
| paths: ['posts/**'] | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 # Need previous commit to detect changed files | |
| - uses: astral-sh/setup-uv@v4 | |
| - name: Install dependencies | |
| run: uv sync | |
| - name: Detect changed articles | |
| id: changed | |
| run: | | |
| # Directly-changed post files (added or modified) | |
| DIRECT=$(git diff --name-only --diff-filter=AM HEAD~1 HEAD -- 'posts/*.md' 'posts/*.qmd') | |
| # Posts whose images changed: map posts/images/<slug>/... back to posts/<slug>.{md,qmd} | |
| IMAGE_CHANGES=$(git diff --name-only --diff-filter=AM HEAD~1 HEAD -- 'posts/images/**') | |
| FROM_IMAGES=() | |
| while IFS= read -r img; do | |
| [ -z "$img" ] && continue | |
| slug=$(echo "$img" | awk -F/ '{print $3}') | |
| [ -z "$slug" ] && continue | |
| for ext in md qmd; do | |
| if [ -f "posts/$slug.$ext" ]; then | |
| FROM_IMAGES+=("posts/$slug.$ext") | |
| break | |
| fi | |
| done | |
| done <<< "$IMAGE_CHANGES" | |
| IMAGE_POSTS="" | |
| if [ ${#FROM_IMAGES[@]} -gt 0 ]; then | |
| IMAGE_POSTS=$(printf '%s\n' "${FROM_IMAGES[@]}") | |
| fi | |
| FILES=$(printf '%s\n%s\n' "$DIRECT" "$IMAGE_POSTS" | sed '/^$/d' | sort -u) | |
| echo "files<<EOF" >> "$GITHUB_OUTPUT" | |
| echo "$FILES" >> "$GITHUB_OUTPUT" | |
| echo "EOF" >> "$GITHUB_OUTPUT" | |
| - name: Publish articles | |
| if: steps.changed.outputs.files != '' | |
| env: | |
| WP_TOKEN: ${{ secrets.WP_TOKEN }} | |
| WP_API_URL: ${{ secrets.WP_API_URL }} | |
| WP_USERNAME: ${{ secrets.WP_USERNAME }} | |
| SLACK_PUBLISH_WEBHOOK: ${{ secrets.SLACK_PUBLISH_WEBHOOK }} | |
| run: | | |
| while IFS= read -r file; do | |
| [ -z "$file" ] && continue | |
| echo "Publishing: $file" | |
| uv run scripts/wordpress/publish.py --status publish "$file" | |
| done <<< "${{ steps.changed.outputs.files }}" |