|
1 | | -import * as github from "@actions/github"; |
2 | | -import * as githubCore from '@actions/core'; |
3 | | -import S3 from "../s3Client"; |
4 | | -import s3UploadDirectory from "../utils/s3UploadDirectory"; |
5 | | -import validateEnvVars from "../utils/validateEnvVars"; |
6 | | -import checkBucketExists from "../utils/checkBucketExists"; |
7 | | -import githubClient from "../githubClient"; |
8 | | -import deactivateDeployments from "../utils/deactivateDeployments"; |
9 | | -import { ReposCreateDeploymentResponseData } from "@octokit/types"; |
| 1 | +import * as github from '@actions/github' |
| 2 | +import * as githubCore from '@actions/core' |
| 3 | +import S3 from '../s3Client' |
| 4 | +import s3UploadDirectory from '../utils/s3UploadDirectory' |
| 5 | +import validateEnvVars from '../utils/validateEnvVars' |
| 6 | +import checkBucketExists from '../utils/checkBucketExists' |
| 7 | +import githubClient from '../githubClient' |
| 8 | +import deactivateDeployments from '../utils/deactivateDeployments' |
| 9 | +import { ReposCreateDeploymentResponseData } from '@octokit/types' |
10 | 10 |
|
11 | | -export const requiredEnvVars = [ |
12 | | - "AWS_ACCESS_KEY_ID", |
13 | | - "AWS_SECRET_ACCESS_KEY", |
14 | | - "GITHUB_TOKEN", |
15 | | -]; |
| 11 | +export const requiredEnvVars = ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'GITHUB_TOKEN'] |
16 | 12 |
|
17 | 13 | export default async (bucketName: string, uploadDirectory: string, environmentPrefix: string) => { |
18 | | - const websiteUrl = `https://s3.amazonaws.com/${bucketName}/index.html`; |
19 | | - const { repo } = github.context; |
20 | | - const branchName = github.context.payload.pull_request!.head.ref; |
| 14 | + const websiteUrl = `https://s3.amazonaws.com/${bucketName}/index.html` |
| 15 | + const { repo } = github.context |
| 16 | + const branchName = github.context.payload.pull_request!.head.ref |
21 | 17 |
|
22 | | - console.log("PR Updated"); |
| 18 | + console.log('PR Updated') |
23 | 19 |
|
24 | | - validateEnvVars(requiredEnvVars); |
| 20 | + validateEnvVars(requiredEnvVars) |
25 | 21 |
|
26 | | - const bucketExists = await checkBucketExists(bucketName); |
| 22 | + const bucketExists = await checkBucketExists(bucketName) |
27 | 23 |
|
28 | | - if (!bucketExists) { |
29 | | - console.log("S3 bucket does not exist. Creating..."); |
30 | | - await S3.createBucket({ Bucket: bucketName }).promise(); |
| 24 | + if (!bucketExists) { |
| 25 | + console.log('S3 bucket does not exist. Creating...') |
| 26 | + await S3.createBucket({ Bucket: bucketName }).promise() |
31 | 27 |
|
32 | | - console.log("Configuring bucket website..."); |
33 | | - await S3.putBucketWebsite({ |
34 | | - Bucket: bucketName, |
35 | | - WebsiteConfiguration: { |
36 | | - IndexDocument: { Suffix: "index.html" }, |
37 | | - ErrorDocument: { Key: "index.html" }, |
38 | | - }, |
39 | | - }).promise(); |
40 | | - } else { |
41 | | - console.log("S3 Bucket already exists. Skipping creation..."); |
42 | | - } |
| 28 | + console.log('Configuring bucket website...') |
| 29 | + await S3.putBucketWebsite({ |
| 30 | + Bucket: bucketName, |
| 31 | + WebsiteConfiguration: { |
| 32 | + IndexDocument: { Suffix: 'index.html' }, |
| 33 | + ErrorDocument: { Key: 'index.html' } |
| 34 | + } |
| 35 | + }).promise() |
| 36 | + } else { |
| 37 | + console.log('S3 Bucket already exists. Skipping creation...') |
| 38 | + } |
43 | 39 |
|
44 | | - await deactivateDeployments(repo, environmentPrefix); |
| 40 | + await deactivateDeployments(repo, environmentPrefix) |
45 | 41 |
|
46 | | - const deployment = await githubClient.repos.createDeployment({ |
47 | | - ...repo, |
48 | | - ref: `refs/heads/${branchName}`, |
49 | | - environment: `${environmentPrefix || 'PR-'}${github.context.payload.pull_request!.number}`, |
50 | | - auto_merge: false, |
51 | | - transient_environment: true, |
52 | | - required_contexts: [], |
53 | | - }); |
| 42 | + const deployment = await githubClient.repos.createDeployment({ |
| 43 | + ...repo, |
| 44 | + ref: `refs/heads/${branchName}`, |
| 45 | + environment: `${environmentPrefix || 'PR-'}${github.context.payload.pull_request!.number}`, |
| 46 | + auto_merge: false, |
| 47 | + transient_environment: true, |
| 48 | + required_contexts: [] |
| 49 | + }) |
54 | 50 |
|
55 | | - if (isSuccessResponse(deployment.data)) { |
56 | | - await githubClient.repos.createDeploymentStatus({ |
57 | | - ...repo, |
58 | | - deployment_id: deployment.data.id, |
59 | | - state: "in_progress", |
60 | | - }); |
| 51 | + if (isSuccessResponse(deployment.data)) { |
| 52 | + await githubClient.repos.createDeploymentStatus({ |
| 53 | + ...repo, |
| 54 | + deployment_id: deployment.data.id, |
| 55 | + state: 'in_progress' |
| 56 | + }) |
61 | 57 |
|
62 | | - console.log("Uploading files..."); |
63 | | - await s3UploadDirectory(bucketName, uploadDirectory); |
| 58 | + console.log('Uploading files...') |
| 59 | + await s3UploadDirectory(bucketName, uploadDirectory) |
64 | 60 |
|
65 | | - await githubClient.repos.createDeploymentStatus({ |
66 | | - ...repo, |
67 | | - deployment_id: deployment.data.id, |
68 | | - state: "success", |
69 | | - environment_url: websiteUrl, |
70 | | - }); |
| 61 | + await githubClient.repos.createDeploymentStatus({ |
| 62 | + ...repo, |
| 63 | + deployment_id: deployment.data.id, |
| 64 | + state: 'success', |
| 65 | + environment_url: websiteUrl |
| 66 | + }) |
71 | 67 |
|
72 | | - githubCore.setOutput('websiteUrl', websiteUrl); |
| 68 | + githubCore.setOutput('websiteUrl', websiteUrl) |
73 | 69 |
|
74 | | - console.log(`Website URL: ${websiteUrl}`); |
75 | | - } |
76 | | -}; |
| 70 | + console.log(`Website URL: ${websiteUrl}`) |
| 71 | + } |
| 72 | +} |
77 | 73 |
|
78 | | -function isSuccessResponse( |
79 | | - object: any |
80 | | -): object is ReposCreateDeploymentResponseData { |
81 | | - return "id" in object; |
| 74 | +function isSuccessResponse(object: any): object is ReposCreateDeploymentResponseData { |
| 75 | + return 'id' in object |
82 | 76 | } |
0 commit comments