diff --git a/.github/workflows/portfolio-preview-deploy.yml b/.github/workflows/portfolio-preview-deploy.yml index cd451a9..3715729 100644 --- a/.github/workflows/portfolio-preview-deploy.yml +++ b/.github/workflows/portfolio-preview-deploy.yml @@ -3,6 +3,11 @@ name: Deploy Portfolio Preview on: workflow_dispatch: inputs: + source_ref: + description: "Source branch, tag, or SHA to build. Use the PR branch for preview." + required: false + default: "" + type: string preview_repository: description: "Preview hosting repository in owner/name format." required: true @@ -34,13 +39,14 @@ permissions: pull-requests: write concurrency: - group: portfolio-preview-${{ github.ref }} + group: portfolio-preview-${{ inputs.source_ref || github.ref_name }} cancel-in-progress: true jobs: preview: runs-on: ubuntu-latest env: + SOURCE_REF: ${{ inputs.source_ref || github.ref_name }} PREVIEW_REPOSITORY: ${{ inputs.preview_repository }} PREVIEW_BRANCH: ${{ inputs.preview_branch }} PREVIEW_BASE: ${{ inputs.preview_base }} @@ -49,6 +55,14 @@ jobs: steps: - name: Checkout source uses: actions/checkout@v4 + with: + ref: ${{ env.SOURCE_REF }} + + - name: Capture source revision + id: source + run: | + echo "ref=$SOURCE_REF" >> "$GITHUB_OUTPUT" + echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" - name: Setup Node uses: actions/setup-node@v4 @@ -82,6 +96,8 @@ jobs: - name: Deploy dist to preview repository env: PORTFOLIO_PREVIEW_TOKEN: ${{ secrets.PORTFOLIO_PREVIEW_TOKEN }} + SOURCE_REF: ${{ steps.source.outputs.ref }} + SOURCE_SHA: ${{ steps.source.outputs.sha }} run: | set -euo pipefail @@ -103,8 +119,8 @@ jobs: cat > _preview/preview-metadata.json <> "$GITHUB_STEP_SUMMARY" else - git -C _preview commit -m "Deploy preview for ${GITHUB_REPOSITORY}@${GITHUB_SHA::7}" + git -C _preview commit -m "Deploy preview for ${GITHUB_REPOSITORY}@${SOURCE_SHA::7}" git -C _preview push origin "$PREVIEW_BRANCH" fi - name: Publish preview link env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE_REF: ${{ steps.source.outputs.ref }} + SOURCE_SHA: ${{ steps.source.outputs.sha }} run: | { echo "## Portfolio Preview" @@ -132,8 +150,8 @@ jobs: echo "- Preview URL: $PREVIEW_URL" echo "- Preview repository: $PREVIEW_REPOSITORY" echo "- Preview branch: $PREVIEW_BRANCH" - echo "- Source branch: $GITHUB_REF_NAME" - echo "- Source SHA: $GITHUB_SHA" + echo "- Source ref: $SOURCE_REF" + echo "- Source SHA: $SOURCE_SHA" } >> "$GITHUB_STEP_SUMMARY" if [ -n "$PR_NUMBER" ]; then @@ -146,7 +164,7 @@ jobs: '', process.env.PREVIEW_URL, '', - 'Source: ' + process.env.GITHUB_REF_NAME + ' @ ' + process.env.GITHUB_SHA.slice(0, 7) + 'Source: ' + process.env.SOURCE_REF + ' @ ' + process.env.SOURCE_SHA.slice(0, 7) ].join('\n'); fs.writeFileSync(process.env.COMMENT_FILE, JSON.stringify({ body })); " diff --git a/README.md b/README.md index bf44eee..6ed291c 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ Preview: https://vikramsh2002.github.io/My-Portfolio-Preview/ The preview workflow is configurable through manual inputs: ```text +source_ref preview_repository preview_branch preview_base @@ -88,6 +89,12 @@ preview_url pr_number ``` +For PR previews, run the workflow from `main` and set `source_ref` to the PR branch, for example: + +```text +portfolio-sync/26572564684-1 +``` + It requires this repository secret: ```text diff --git a/portfolio-v2/docs/portfolio-sync.md b/portfolio-v2/docs/portfolio-sync.md index b04f850..cff1aac 100644 --- a/portfolio-v2/docs/portfolio-sync.md +++ b/portfolio-v2/docs/portfolio-sync.md @@ -76,7 +76,7 @@ For generated project PRs, use the `Deploy Portfolio Preview` workflow before me The preview workflow: -- Builds the selected branch from this repository. +- Builds the configured `source_ref` from this repository. - Uses `VITE_BASE=/My-Portfolio-Preview/`. - Pushes only the compiled `portfolio-v2/dist` files to the preview repository. - Writes the preview link in the workflow summary. @@ -84,6 +84,8 @@ The preview workflow: This keeps the live portfolio separate from preview testing. +For a generated project PR, run the preview workflow from `main` and set `source_ref` to the generated PR branch. This avoids accidentally rebuilding `main` and thinking the project update is missing. + ## Email Alerts Email alerts use Resend when these repository secrets are configured: