Skip to content
Draft
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
53 changes: 44 additions & 9 deletions .github/workflows/pr-review-companion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,22 @@ permissions:
pull-requests: write
# Authenticate with GCP.
id-token: write
# Report commit status.
statuses: write

jobs:
review:
environment: review
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.pull_requests[0].number
env:
PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }}
PREFIX: pr${{ github.event.workflow_run.pull_requests[0].number }}
STATUS_PATH: repos/${{ github.repository }}/statuses/${{ github.event.workflow_run.pull_requests[0].head.sha }}
STATUS_CONTEXT: pr-review-companion
STATUS_TARGET: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
steps:
- name: "Download artifact"
- name: Download artifact
uses: actions/download-artifact@v5
with:
pattern: build
Expand All @@ -44,11 +52,18 @@ jobs:
- name: Check for artifacts
id: check
if: hashFiles('build/') != ''
run: echo "HAS_ARTIFACT=true" >> "$GITHUB_OUTPUT"

- name: Mark status as pending
if: steps.check.outputs.HAS_ARTIFACT
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "HAS_ARTIFACT=true" >> "$GITHUB_OUTPUT"
PR_NUMBER=`cat build/NR | tr -dc '0-9'`
echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_OUTPUT"
echo "PREFIX=pr$PR_NUMBER" >> "$GITHUB_OUTPUT"
gh api "$STATUS_PATH" \
-f state=pending \
-f context="$STATUS_CONTEXT" \
-f description='Review deployment pending' \
-f target_url="$STATUS_TARGET"

- name: Authenticate with GCP
if: steps.check.outputs.HAS_ARTIFACT
Expand All @@ -67,7 +82,7 @@ jobs:
uses: google-github-actions/upload-cloud-storage@v2
with:
path: "build"
destination: "${{ vars.GCP_BUCKET_NAME }}/${{ steps.check.outputs.PREFIX }}"
destination: "${{ vars.GCP_BUCKET_NAME }}/${{ env.PREFIX }}"
resumable: false
headers: |-
cache-control: no-store
Expand Down Expand Up @@ -99,8 +114,6 @@ jobs:
if: steps.check.outputs.HAS_ARTIFACT
env:
BUILD_OUT_ROOT: ${{ github.workspace }}/build
PREFIX: ${{ steps.check.outputs.PREFIX }}
PR_NUMBER: ${{ steps.check.outputs.PR_NUMBER }}
working-directory: content
run: |
echo "Pull request:"
Expand All @@ -115,3 +128,25 @@ jobs:
--pr-number="$PR_NUMBER" \
--diff-file=$BUILD_OUT_ROOT/DIFF \
$BUILD_OUT_ROOT

- name: Mark status as success
if: steps.check.outputs.HAS_ARTIFACT && success()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api "$STATUS_PATH" \
-f state=success \
-f context="$STATUS_CONTEXT" \
-f description='Review deployment succeeded' \
-f target_url="$STATUS_TARGET"

- name: Mark status as failure
if: steps.check.outputs.HAS_ARTIFACT && failure()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api "$STATUS_PATH" \
-f state=failure \
-f context="$STATUS_CONTEXT" \
-f description='Review deployment failed' \
-f target_url="$STATUS_TARGET"
3 changes: 0 additions & 3 deletions .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ jobs:
echo "Disk usage size of the build"
du -sh $BUILD_OUT_ROOT

# Save the PR number into the build
echo ${{ github.event.number }} > ${BUILD_OUT_ROOT}/NR

# Download the raw diff blob and store that inside the build
# directory.
# The purpose of this is for the PR Review Companion to later
Expand Down