Revise http error #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy Preview | |
# Trigger the workflow on push to ak-merge-upstream and via manual dispatch | |
on: | |
push: | |
branches: | |
- ak-merge-upstream | |
workflow_dispatch: | |
inputs: | |
pr_id: | |
description: 'Pull Request ID' | |
required: false | |
default: 'manual' | |
type: string | |
commit_sha: | |
description: 'Commit SHA to Deploy' | |
required: false | |
default: '' | |
type: string | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
# 1. Set Deployment Variables | |
- name: "Set Deployment Variables" | |
id: vars | |
run: | | |
pr_id="${{ github.event.inputs.pr_id }}" | |
pr_id=${pr_id:-manual} | |
commit_sha="${{ github.event.inputs.commit_sha }}" | |
commit_sha=${commit_sha:-$GITHUB_SHA} | |
echo "pr_id=${pr_id}" >> $GITHUB_OUTPUT | |
echo "commit_sha=${commit_sha}" >> $GITHUB_OUTPUT | |
# 2. (Optional) Debug Deployment Variables | |
- name: "Debug Deployment Variables" | |
run: | | |
echo "PR ID: ${{ steps.vars.outputs.pr_id }}" | |
echo "Commit SHA: ${{ steps.vars.outputs.commit_sha }}" | |
# 3. Create a Pending Commit Status | |
- name: "Create commit status - Pending" | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const commitId = "${{ steps.vars.outputs.commit_sha }}"; | |
const prId = "${{ steps.vars.outputs.pr_id }}"; | |
const runId = "${{ github.run_id }}"; | |
await github.rest.repos.createCommitStatus({ | |
context: "client-preview", | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
sha: commitId, | |
state: "pending", | |
description: prId === 'manual' | |
? `Creating manual preview` | |
: `Creating preview for PR #${prId}`, | |
target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`, | |
}); | |
# 4. Checkout the Specific Commit | |
- name: Checkout repository at specific commit | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ steps.vars.outputs.commit_sha }} | |
# 5. Download the Build Artifact | |
- name: Download build artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: client | |
path: dist/client | |
run-id: ${{ github.run_id }} # Adjust if artifacts are from a different run | |
# 6. Configure AWS Credentials | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: us-east-2 # Update if your region is different | |
# 7. Upload to S3 Using the Secret and pr_id | |
- name: Upload to S3 | |
run: | | |
aws s3 sync dist/client/ ${{ secrets.CLOUDFRONT_DEPLOYMENT_LOCATION }}/staging/pr${{ steps.vars.outputs.pr_id }}/ | |
# 8. Update Commit Status to Success | |
- name: "Update commit status - Success" | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const commitId = "${{ steps.vars.outputs.commit_sha }}"; | |
const prId = "${{ steps.vars.outputs.pr_id }}"; | |
const targetUrl = prId === 'manual' | |
? `https://your-cloudfront-domain.com/manual` // Replace with your actual CloudFront URL for manual deployments | |
: `https://your-cloudfront-domain.com/pr${prId}`; // Replace with your actual CloudFront URL for PR previews | |
const description = `Preview deployed to S3: ${targetUrl}`; | |
await github.rest.repos.createCommitStatus({ | |
context: "client-preview", | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
sha: commitId, | |
state: "success", | |
target_url: targetUrl, | |
description: description, | |
}); |