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
65 changes: 60 additions & 5 deletions .github/workflows/prepare-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ on:
description: 'Whether the consumer is a monorepo (workspace-aware prepare/publish/message)'
type: boolean
required: true
pull-request:
description: 'Pull request number to prepare a preview build for.'
required: false
type: number
branch:
description: 'Branch in this repository to prepare a preview build for, instead of a pull request.'
required: false
type: string
default: ''
rename-after-install-and-build:
description: 'Whether packages are renamed to the preview build scope after (true) or before (false) the install and build steps.'
type: boolean
Expand All @@ -42,19 +51,55 @@ jobs:
runs-on: ubuntu-latest
outputs:
IS_FORK: ${{ steps.is-fork.outputs.IS_FORK }}
REF_SHA: ${{ steps.ref-sha.outputs.REF_SHA }}
steps:
- uses: actions/checkout@v6

- name: Validate inputs
env:
PR_NUMBER: ${{ inputs.pull-request || github.event.issue.number }}
BRANCH: ${{ inputs.branch }}
run: |
if [[ -n "$PR_NUMBER" && -n "$BRANCH" ]]; then
echo "::error::Provide either a pull request number or a branch, not both."
exit 1
fi

if [[ -z "$PR_NUMBER" && -z "$BRANCH" ]]; then
echo "::error::Provide a pull request number or a branch."
exit 1
fi

if [[ -n "$BRANCH" ]] && ! git check-ref-format "refs/heads/${BRANCH}"; then
echo "::error::Invalid branch name."
exit 1
fi

- name: Determine whether this PR is from a fork
id: is-fork
run: echo "IS_FORK=$(gh pr view --json isCrossRepository --jq '.isCrossRepository' "${PR_NUMBER}" )" >> "$GITHUB_OUTPUT"
run: |
if [[ -z "$PR_NUMBER" ]]; then
echo "IS_FORK=false" >> "$GITHUB_OUTPUT"
else
echo "IS_FORK=$(gh pr view --json isCrossRepository --jq '.isCrossRepository' "${PR_NUMBER}" )" >> "$GITHUB_OUTPUT"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.issue.number }}
PR_NUMBER: ${{ inputs.pull-request || github.event.issue.number }}

- name: Resolve the branch to a commit
id: ref-sha
if: ${{ inputs.branch != '' }}
run: |
remote_ref="$(git ls-remote --exit-code origin "refs/heads/${BRANCH}")"
echo "REF_SHA=$(cut -f1 <<< "${remote_ref}")" >> "$GITHUB_OUTPUT"
env:
BRANCH: ${{ inputs.branch }}

react-to-comment:
name: React to comment
needs: is-fork-pull-request
if: ${{ needs.is-fork-pull-request.outputs.IS_FORK == 'false' }}
if: ${{ github.event.comment.id && needs.is-fork-pull-request.outputs.IS_FORK == 'false' }}
runs-on: ubuntu-latest
steps:
- name: Add reaction to trigger comment
Expand All @@ -69,16 +114,26 @@ jobs:

build-preview:
name: Build preview
needs: react-to-comment
needs: is-fork-pull-request
if: ${{ needs.is-fork-pull-request.outputs.IS_FORK == 'false' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6

- name: Check out pull request
if: ${{ inputs.branch == '' }}
run: gh pr checkout "${PR_NUMBER}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.issue.number }}
PR_NUMBER: ${{ inputs.pull-request || github.event.issue.number }}

- name: Check out branch
if: ${{ inputs.branch != '' }}
run: |
git fetch --depth=1 origin "${REF_SHA}"
git checkout --detach "${REF_SHA}"
env:
REF_SHA: ${{ needs.is-fork-pull-request.outputs.REF_SHA }}

- name: Checkout and setup environment
uses: MetaMask/action-checkout-and-setup@v3
Expand Down
17 changes: 16 additions & 1 deletion .github/workflows/publish-preview-oidc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ name: Publish Preview Builds (OIDC)
on:
workflow_call:
inputs:
pull-request:
description: 'Pull request number to publish a preview build for. Mutually exclusive with "branch".'
required: false
type: number
branch:
description: 'Branch in this repository to publish a preview build for. Mutually exclusive with "pull-request".'
required: false
type: string
default: ''
npm-scope:
description: 'Target NPM scope for preview packages'
type: string
Expand Down Expand Up @@ -58,6 +67,8 @@ jobs:
name: Build
uses: ./.github/workflows/prepare-preview.yml
with:
pull-request: ${{ inputs.pull-request }}
branch: ${{ inputs.branch }}
Comment thread
Mrtenz marked this conversation as resolved.
Resolved
npm-scope: ${{ inputs.npm-scope }}
source-scope: ${{ inputs.source-scope }}
build-command: ${{ inputs.build-command }}
Expand Down Expand Up @@ -200,8 +211,12 @@ jobs:
fi
fi

- name: Add build preview to the job summary
run: cat preview-build-message.txt >> "$GITHUB_STEP_SUMMARY"

- name: Post build preview in comment
if: ${{ inputs.pull-request }}
run: gh pr comment "${PR_NUMBER}" --body-file preview-build-message.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.issue.number }}
PR_NUMBER: ${{ inputs.pull-request }}
Loading