forked from google/neuroglancer
-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (101 loc) · 4.05 KB
/
deploy_preview.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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,
});