Skip to content

Commit

Permalink
Merge pull request #27 from brokenhandsio/documents-options
Browse files Browse the repository at this point in the history
Add option to choose index and error documents
  • Loading branch information
ptoffy authored Sep 9, 2024
2 parents f95ff0b + 5edf608 commit beb77af
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ inputs:
environment-prefix:
description: "Prefix of the GitHub Deployment Environment. The PR number will be appended to this value."
required: false
index-document:
description: "Index document for the S3 bucket. Defaults to index.html."
required: false
error-document:
description: "Error document for the S3 bucket. Defaults to error.html."
required: false
runs:
using: "node20"
main: "dist/index.js"
19 changes: 11 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63977,7 +63977,7 @@ const githubClient_1 = __importDefault(__nccwpck_require__(261));
const deactivateDeployments_1 = __importDefault(__nccwpck_require__(5066));
const client_s3_1 = __nccwpck_require__(9250);
exports.requiredEnvVars = ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'GITHUB_TOKEN'];
exports["default"] = (bucketName, bucketRegion, uploadDirectory, environmentPrefix) => __awaiter(void 0, void 0, void 0, function* () {
exports["default"] = (bucketName, bucketRegion, uploadDirectory, environmentPrefix, indexDocument, errorDocument) => __awaiter(void 0, void 0, void 0, function* () {
const websiteUrl = `http://${bucketName}.s3-website.${bucketRegion}.amazonaws.com/`;
const { repo } = github.context;
const branchName = github.context.payload.pull_request.head.ref;
Expand Down Expand Up @@ -64019,8 +64019,8 @@ exports["default"] = (bucketName, bucketRegion, uploadDirectory, environmentPref
const putBucketWebsiteRequest = {
Bucket: bucketName,
WebsiteConfiguration: {
IndexDocument: { Suffix: 'index.html' },
ErrorDocument: { Key: 'index.html' }
IndexDocument: { Suffix: indexDocument },
ErrorDocument: { Key: errorDocument }
}
};
const putBucketWebsiteCommand = new client_s3_1.PutBucketWebsiteCommand(putBucketWebsiteRequest);
Expand Down Expand Up @@ -64100,7 +64100,7 @@ const deactivateDeployments_1 = __importDefault(__nccwpck_require__(5066));
const dayjs_1 = __importDefault(__nccwpck_require__(7401));
const client_s3_1 = __nccwpck_require__(9250);
exports.requiredEnvVars = ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'GITHUB_TOKEN'];
exports["default"] = (bucketName, bucketRegion, uploadDirectory, environmentPrefix) => __awaiter(void 0, void 0, void 0, function* () {
exports["default"] = (bucketName, bucketRegion, uploadDirectory, environmentPrefix, indexDocument, errorDocument) => __awaiter(void 0, void 0, void 0, function* () {
const websiteUrl = `http://${bucketName}.s3-website.${bucketRegion}.amazonaws.com/`;
const { repo } = github.context;
const branchName = github.context.ref;
Expand Down Expand Up @@ -64140,8 +64140,8 @@ exports["default"] = (bucketName, bucketRegion, uploadDirectory, environmentPref
const putBucketWebsiteRequest = {
Bucket: bucketName,
WebsiteConfiguration: {
IndexDocument: { Suffix: 'index.html' },
ErrorDocument: { Key: 'index.html' }
IndexDocument: { Suffix: indexDocument },
ErrorDocument: { Key: errorDocument }
}
};
const putBucketWebsiteCommand = new client_s3_1.PutBucketWebsiteCommand(putBucketWebsiteRequest);
Expand Down Expand Up @@ -64252,11 +64252,14 @@ const prUpdatedAction_1 = __importDefault(__nccwpck_require__(8092));
const uploadAction_1 = __importDefault(__nccwpck_require__(9695));
const dayjs_1 = __importDefault(__nccwpck_require__(7401));
const main = () => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b;
try {
const bucketPrefix = core.getInput('bucket-prefix');
const bucketRegion = core.getInput('bucket-region');
const folderToCopy = core.getInput('folder-to-copy');
const environmentPrefix = core.getInput('environment-prefix');
const indexDocument = (_a = core.getInput('index-document')) !== null && _a !== void 0 ? _a : 'index.html';
const errorDocument = (_b = core.getInput('error-document')) !== null && _b !== void 0 ? _b : 'error.html';
const githubEventName = github.context.eventName;
if (githubEventName === 'pull_request') {
const prNumber = github.context.payload.pull_request.number;
Expand All @@ -64267,7 +64270,7 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
case 'opened':
case 'reopened':
case 'synchronize':
yield (0, prUpdatedAction_1.default)(bucketName, bucketRegion, folderToCopy, environmentPrefix);
yield (0, prUpdatedAction_1.default)(bucketName, bucketRegion, folderToCopy, environmentPrefix, indexDocument, errorDocument);
break;
case 'closed':
yield (0, prClosedAction_1.default)(bucketName, environmentPrefix);
Expand All @@ -64279,7 +64282,7 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
}
else {
const bucketName = `${bucketPrefix}-${(0, dayjs_1.default)().format('DD-MM-YYYY-hh-mma')}`;
yield (0, uploadAction_1.default)(bucketName, bucketRegion, folderToCopy, environmentPrefix);
yield (0, uploadAction_1.default)(bucketName, bucketRegion, folderToCopy, environmentPrefix, indexDocument, errorDocument);
}
}
catch (error) {
Expand Down
10 changes: 5 additions & 5 deletions src/actions/prUpdatedAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import githubClient from '../githubClient'
import deactivateDeployments from '../utils/deactivateDeployments'
import {
GetResponseDataTypeFromEndpointMethod,
} from '@octokit/types';
} from '@octokit/types';
import { CreateBucketRequest, CreateBucketCommand, PutBucketOwnershipControlsCommand, PutBucketOwnershipControlsRequest, PutPublicAccessBlockCommand, PutBucketWebsiteCommand } from '@aws-sdk/client-s3';

export const requiredEnvVars = ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'GITHUB_TOKEN']

type ReposCreateDeploymentResponseData = GetResponseDataTypeFromEndpointMethod<
typeof githubClient.rest.repos.createDeployment
typeof githubClient.rest.repos.createDeployment
>;

export default async (bucketName: string, bucketRegion: string, uploadDirectory: string, environmentPrefix: string) => {
export default async (bucketName: string, bucketRegion: string, uploadDirectory: string, environmentPrefix: string, indexDocument: string, errorDocument: string) => {
const websiteUrl = `http://${bucketName}.s3-website.${bucketRegion}.amazonaws.com/`
const { repo } = github.context
const branchName = github.context.payload.pull_request!.head.ref
Expand Down Expand Up @@ -68,8 +68,8 @@ export default async (bucketName: string, bucketRegion: string, uploadDirectory:
const putBucketWebsiteRequest = {
Bucket: bucketName,
WebsiteConfiguration: {
IndexDocument: { Suffix: 'index.html' },
ErrorDocument: { Key: 'index.html' }
IndexDocument: { Suffix: indexDocument },
ErrorDocument: { Key: errorDocument }
}
}
const putBucketWebsiteCommand = new PutBucketWebsiteCommand(putBucketWebsiteRequest)
Expand Down
11 changes: 6 additions & 5 deletions src/actions/uploadAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ import githubClient from '../githubClient'
import deactivateDeployments from '../utils/deactivateDeployments'
import {
GetResponseDataTypeFromEndpointMethod,
} from '@octokit/types';import dayjs from 'dayjs'
} from '@octokit/types';
import dayjs from 'dayjs'
import { CreateBucketRequest, CreateBucketCommand, PutBucketOwnershipControlsCommand, PutBucketOwnershipControlsRequest, PutPublicAccessBlockCommand, PutBucketWebsiteCommand } from '@aws-sdk/client-s3';

export const requiredEnvVars = ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'GITHUB_TOKEN']

type ReposCreateDeploymentResponseData = GetResponseDataTypeFromEndpointMethod<
typeof githubClient.rest.repos.createDeployment
typeof githubClient.rest.repos.createDeployment
>;

export default async (bucketName: string, bucketRegion: string, uploadDirectory: string, environmentPrefix: string) => {
export default async (bucketName: string, bucketRegion: string, uploadDirectory: string, environmentPrefix: string, indexDocument: string, errorDocument: string) => {
const websiteUrl = `http://${bucketName}.s3-website.${bucketRegion}.amazonaws.com/`
const { repo } = github.context
const branchName = github.context.ref
Expand Down Expand Up @@ -66,8 +67,8 @@ export default async (bucketName: string, bucketRegion: string, uploadDirectory:
const putBucketWebsiteRequest = {
Bucket: bucketName,
WebsiteConfiguration: {
IndexDocument: { Suffix: 'index.html' },
ErrorDocument: { Key: 'index.html' }
IndexDocument: { Suffix: indexDocument },
ErrorDocument: { Key: errorDocument }
}
}
const putBucketWebsiteCommand = new PutBucketWebsiteCommand(putBucketWebsiteRequest)
Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const main = async () => {
const bucketRegion = core.getInput('bucket-region')
const folderToCopy = core.getInput('folder-to-copy')
const environmentPrefix = core.getInput('environment-prefix')
const indexDocument = core.getInput('index-document') ?? 'index.html'
const errorDocument = core.getInput('error-document') ?? 'error.html'

const githubEventName = github.context.eventName
if (githubEventName === 'pull_request') {
Expand All @@ -24,7 +26,7 @@ const main = async () => {
case 'opened':
case 'reopened':
case 'synchronize':
await prUpdatedAction(bucketName, bucketRegion, folderToCopy, environmentPrefix)
await prUpdatedAction(bucketName, bucketRegion, folderToCopy, environmentPrefix, indexDocument, errorDocument)
break

case 'closed':
Expand All @@ -38,7 +40,7 @@ const main = async () => {
} else {
const bucketName = `${bucketPrefix}-${dayjs().format('DD-MM-YYYY-hh-mma')}`

await uploadAction(bucketName, bucketRegion, folderToCopy, environmentPrefix)
await uploadAction(bucketName, bucketRegion, folderToCopy, environmentPrefix, indexDocument, errorDocument)
}
} catch (error) {
console.log(error)
Expand Down

0 comments on commit beb77af

Please sign in to comment.