From df9b898d25dcd82f9c8460e39fc57e8a2213f315 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Thu, 9 Jul 2026 15:09:24 -0300 Subject: [PATCH] ci(deploy): post PR status comments and store deployment info MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At the start of every push-triggered Deploy run: - Find the merged PR associated with the head commit via GitHub API - Post '🚀 Starting production deploy...' on that PR After a successful build: - Write build_production/_deployment-info.json with commit_sha, pr_number, pr_title, repository and timestamp so the WordPress sync handler can post a 'finished' comment after the fragments are updated. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- .github/workflows/deploy.yml | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e7c65cee..f0a45fff 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -14,6 +14,28 @@ jobs: WC_CONSUMER_SECRET: ${{ secrets.WC_CONSUMER_SECRET }} steps: - uses: actions/checkout@v4 + + - name: Find merged PR + id: pr + if: github.event_name == 'push' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + data=$(gh api repos/${{ github.repository }}/commits/${{ github.sha }}/pulls \ + --jq '[.[] | select(.merged_at != null)] | .[0] | {number: .number, title: .title}' \ + 2>/dev/null || echo 'null') + echo "data=$data" >> "$GITHUB_OUTPUT" + + - name: Comment starting deploy on PR + if: steps.pr.outputs.data != 'null' && steps.pr.outputs.data != '' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + pr_number=$(echo '${{ steps.pr.outputs.data }}' | jq -r '.number // empty') + [ -n "$pr_number" ] && gh pr comment "$pr_number" \ + --repo ${{ github.repository }} \ + --body $'🚀 Starting production deploy of site header and footer fragments...' + - uses: actions/setup-node@v4 with: node-version: 20 @@ -22,6 +44,21 @@ jobs: php-version: 8.3 - run: composer i - run: composer prod + + - name: Store deployment info + if: success() + run: | + pr_number=$(echo '${{ steps.pr.outputs.data }}' | jq -r '.number // empty') + pr_title=$(echo '${{ steps.pr.outputs.data }}' | jq -r '.title // ""') + jq -n \ + --arg sha "${{ github.sha }}" \ + --arg repo "${{ github.repository }}" \ + --arg ts "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ + --arg title "$pr_title" \ + --argjson num "${pr_number:-null}" \ + '{commit_sha: $sha, pr_number: $num, pr_title: $title, repository: $repo, timestamp: $ts}' \ + > build_production/_deployment-info.json + - uses: crazy-max/ghaction-github-pages@v4 if: success() env: