From 13d4254076b3ac28af66775a0bffe7b81cb62146 Mon Sep 17 00:00:00 2001 From: Orinks <38449772+Orinks@users.noreply.github.com> Date: Thu, 5 Mar 2026 04:55:49 +0000 Subject: [PATCH 1/3] fix(ci): make nightly wordpress sync reliable and locally reusable --- .github/workflows/build.yml | 9 ++++ .github/workflows/push-releases.yml | 71 ++++++++++++++++++++++++++ .github/workflows/update-wordpress.yml | 3 +- 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/push-releases.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b695029..5940df8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 }} diff --git a/.github/workflows/push-releases.yml b/.github/workflows/push-releases.yml new file mode 100644 index 0000000..50fb688 --- /dev/null +++ b/.github/workflows/push-releases.yml @@ -0,0 +1,71 @@ +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 + + python3 - <<'PYEOF' + import json, os, urllib.request + + with open('/tmp/latest.json') as f: + latest = json.load(f) + + with open('/tmp/all.json') as f: + all_releases = json.load(f) + + payload = json.dumps({ + 'repo': os.environ['REPO'], + 'releases': all_releases[:20], + 'latest': latest if isinstance(latest, dict) and latest.get('tag_name') else None, + }).encode() + + req = urllib.request.Request( + os.environ['WP_URL'].rstrip('/') + '/wp-json/ogr/v1/push-releases', + data=payload, + headers={ + 'Content-Type': 'application/json', + 'X-OGR-Token': os.environ['WP_TOKEN'], + }, + method='POST', + ) + with urllib.request.urlopen(req, timeout=30) as r: + body = json.load(r) + print(f"Pushed {body['count']} releases for {body['repo']}") + PYEOF + } + + attempt || { + echo "First push attempt failed, retrying in 10s..." + sleep 10 + attempt + } diff --git a/.github/workflows/update-wordpress.yml b/.github/workflows/update-wordpress.yml index 71b625c..f601430 100644 --- a/.github/workflows/update-wordpress.yml +++ b/.github/workflows/update-wordpress.yml @@ -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 }} From 514a3bde02001b4aaa6700a005133e791ab49194 Mon Sep 17 00:00:00 2001 From: Orinks <38449772+Orinks@users.noreply.github.com> Date: Thu, 5 Mar 2026 04:56:24 +0000 Subject: [PATCH 2/3] fix(ci): correct heredoc formatting in wordpress push workflow --- .github/workflows/push-releases.yml | 48 ++++++++++++++--------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/.github/workflows/push-releases.yml b/.github/workflows/push-releases.yml index 50fb688..fad2523 100644 --- a/.github/workflows/push-releases.yml +++ b/.github/workflows/push-releases.yml @@ -34,34 +34,34 @@ jobs: 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 - python3 - <<'PYEOF' - import json, os, urllib.request +python3 - <<'PYEOF' +import json, os, urllib.request - with open('/tmp/latest.json') as f: - latest = json.load(f) +with open('/tmp/latest.json') as f: + latest = json.load(f) - with open('/tmp/all.json') as f: - all_releases = json.load(f) +with open('/tmp/all.json') as f: + all_releases = json.load(f) - payload = json.dumps({ - 'repo': os.environ['REPO'], - 'releases': all_releases[:20], - 'latest': latest if isinstance(latest, dict) and latest.get('tag_name') else None, - }).encode() +payload = json.dumps({ + 'repo': os.environ['REPO'], + 'releases': all_releases[:20], + 'latest': latest if isinstance(latest, dict) and latest.get('tag_name') else None, +}).encode() - req = urllib.request.Request( - os.environ['WP_URL'].rstrip('/') + '/wp-json/ogr/v1/push-releases', - data=payload, - headers={ - 'Content-Type': 'application/json', - 'X-OGR-Token': os.environ['WP_TOKEN'], - }, - method='POST', - ) - with urllib.request.urlopen(req, timeout=30) as r: - body = json.load(r) - print(f"Pushed {body['count']} releases for {body['repo']}") - PYEOF +req = urllib.request.Request( + os.environ['WP_URL'].rstrip('/') + '/wp-json/ogr/v1/push-releases', + data=payload, + headers={ + 'Content-Type': 'application/json', + 'X-OGR-Token': os.environ['WP_TOKEN'], + }, + method='POST', +) +with urllib.request.urlopen(req, timeout=30) as r: + body = json.load(r) +print(f"Pushed {body['count']} releases for {body['repo']}") +PYEOF } attempt || { From 13abeba270fc997460a29e4015abaf71dd76a1bc Mon Sep 17 00:00:00 2001 From: Orinks <38449772+Orinks@users.noreply.github.com> Date: Thu, 5 Mar 2026 04:56:43 +0000 Subject: [PATCH 3/3] fix(ci): simplify wordpress push payload/post logic --- .github/workflows/push-releases.yml | 42 ++++++++++------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/.github/workflows/push-releases.yml b/.github/workflows/push-releases.yml index fad2523..81666b2 100644 --- a/.github/workflows/push-releases.yml +++ b/.github/workflows/push-releases.yml @@ -34,34 +34,20 @@ jobs: 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 -python3 - <<'PYEOF' -import json, os, urllib.request - -with open('/tmp/latest.json') as f: - latest = json.load(f) - -with open('/tmp/all.json') as f: - all_releases = json.load(f) - -payload = json.dumps({ - 'repo': os.environ['REPO'], - 'releases': all_releases[:20], - 'latest': latest if isinstance(latest, dict) and latest.get('tag_name') else None, -}).encode() - -req = urllib.request.Request( - os.environ['WP_URL'].rstrip('/') + '/wp-json/ogr/v1/push-releases', - data=payload, - headers={ - 'Content-Type': 'application/json', - 'X-OGR-Token': os.environ['WP_TOKEN'], - }, - method='POST', -) -with urllib.request.urlopen(req, timeout=30) as r: - body = json.load(r) -print(f"Pushed {body['count']} releases for {body['repo']}") -PYEOF + 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 || {