Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,12 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh workflow run update-pages.yml || true


push-to-wordpress:
needs: release
if: ${{ needs.release.result == 'success' && (github.event_name != 'workflow_dispatch' || inputs.dry_run != true) }}
uses: ./.github/workflows/push-releases.yml
secrets:
WP_PUSH_TOKEN: ${{ secrets.WP_PUSH_TOKEN }}
WP_SITE_URL: ${{ secrets.WP_SITE_URL }}
57 changes: 57 additions & 0 deletions .github/workflows/push-releases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Push releases to WordPress

on:
workflow_call:
secrets:
WP_PUSH_TOKEN:
required: true
WP_SITE_URL:
required: true

jobs:
push:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Validate required secrets
env:
WP_TOKEN: ${{ secrets.WP_PUSH_TOKEN }}
WP_URL: ${{ secrets.WP_SITE_URL }}
run: |
test -n "$WP_TOKEN" || { echo "Missing WP_PUSH_TOKEN"; exit 1; }
test -n "$WP_URL" || { echo "Missing WP_SITE_URL"; exit 1; }

- name: Push releases to WordPress (with retry)
env:
GH_TOKEN: ${{ github.token }}
WP_TOKEN: ${{ secrets.WP_PUSH_TOKEN }}
WP_URL: ${{ secrets.WP_SITE_URL }}
REPO: ${{ github.repository }}
run: |
set -euo pipefail

attempt() {
gh api "repos/$REPO/releases/latest" -H "Accept: application/vnd.github+json" > /tmp/latest.json 2>/dev/null || echo "null" > /tmp/latest.json
gh api "repos/$REPO/releases?per_page=20" -H "Accept: application/vnd.github+json" > /tmp/all.json

PAYLOAD=$(jq -c -n \
--arg repo "$REPO" \
--slurpfile all /tmp/all.json \
--slurpfile latest /tmp/latest.json \
'{repo:$repo, releases:($all[0][0:20]), latest:(if ($latest[0] | type)=="object" and ($latest[0].tag_name != null) then $latest[0] else null end)}')

RESPONSE=$(curl -sS -f \
-H "Content-Type: application/json" \
-H "X-OGR-Token: $WP_TOKEN" \
-X POST \
-d "$PAYLOAD" \
"${WP_URL%/}/wp-json/ogr/v1/push-releases")

echo "$RESPONSE" | jq -r '"Pushed \(.count) releases for \(.repo)"'
}

attempt || {
echo "First push attempt failed, retrying in 10s..."
sleep 10
attempt
}
3 changes: 2 additions & 1 deletion .github/workflows/update-wordpress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ name: Update WordPress on release
on:
release:
types: [published]
workflow_dispatch:

jobs:
push-to-wordpress:
uses: Orinks/orinks-github-releases/.github/workflows/push-releases.yml@master
uses: ./.github/workflows/push-releases.yml
secrets:
WP_PUSH_TOKEN: ${{ secrets.WP_PUSH_TOKEN }}
WP_SITE_URL: ${{ secrets.WP_SITE_URL }}