Skip to content

Commit

Permalink
Deploy Production Code for Commit a725730 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesIves committed Dec 14, 2020
1 parent a725730 commit ae11479
Show file tree
Hide file tree
Showing 14,638 changed files with 151 additions and 2,792,219 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
36 changes: 16 additions & 20 deletions lib/constants.d.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
export declare enum TestFlag {
NONE = 0,
HAS_CHANGED_FILES = 2,
HAS_REMOTE_BRANCH = 4
}
export interface ActionInterface {
/** Deployment access token. */
accessToken?: string | null;
/** The base branch that the deploy should be made from. */
baseBranch?: string;
/** The branch that the action should deploy to. */
branch: string;
/** git push with --dry-run */
dryRun?: boolean | null;
/** If your project generates hashed files on build you can use this option to automatically delete them from the deployment branch with each deploy. This option can be toggled on by setting it to true. */
clean?: boolean | null;
/** If you need to use CLEAN but you'd like to preserve certain files or folders you can use this option. */
cleanExclude?: string | string[];
/** If you need to customize the commit message for an integration you can do so. */
commitMessage?: string;
/** The default branch of the deployment. Similar to baseBranch if you're using this action as a module. */
defaultBranch?: string;
/** The git config email. */
email?: string;
/** The folder to deploy. */
folder: string;
/** The auto generated folder path. */
folderPath?: string;
/** GitHub deployment token. */
gitHubToken?: string | null;
/** Determines if the action is running in test mode or not. */
isTest?: boolean | null;
/** Removes files from LFS if toggled to allow normal deployment. */
lfs?: boolean | null;
/** Determines test scenarios the action is running in. */
isTest: TestFlag;
/** The git config name. */
name?: string;
/** Determines if the workspace should be stashed/restored prior to comitting. */
preserve?: boolean | null;
/** The repository path, for example JamesIves/github-pages-deploy-action. */
repositoryName?: string;
/** The fully qualified repositpory path, this gets auto generated if repositoryName is provided. */
Expand All @@ -41,33 +36,34 @@ export interface ActionInterface {
ssh?: boolean | null;
/** If you'd like to push the contents of the deployment folder into a specific directory on the deployment branch you can specify it here. */
targetFolder?: string;
/** The token type, ie ssh/github token/access token, this gets automatically generated. */
/** Deployment token. */
token?: string | null;
/** The token type, ie ssh/token, this gets automatically generated. */
tokenType?: string;
/** The folder where your deployment project lives. */
workspace: string;
}
/** The minimum required values to run the action as a node module. */
export interface NodeActionInterface {
/** Deployment access token. */
accessToken?: string | null;
/** The branch that the action should deploy to. */
branch: string;
/** The folder to deploy. */
folder: string;
/** GitHub deployment token. */
gitHubToken?: string | null;
/** The repository path, for example JamesIves/github-pages-deploy-action. */
repositoryName: string;
/** GitHub deployment token. */
token?: string | null;
/** Determines if the action should run in silent mode or not. */
silent: boolean;
/** Set to true if you're using an ssh client in your build step. */
ssh?: boolean | null;
/** The folder where your deployment project lives. */
workspace: string;
isTest: TestFlag;
}
export declare const action: ActionInterface;
/** Types for the required action parameters. */
export declare type RequiredActionParameters = Pick<ActionInterface, 'accessToken' | 'gitHubToken' | 'ssh' | 'branch' | 'folder'>;
export declare type RequiredActionParameters = Pick<ActionInterface, 'token' | 'ssh' | 'branch' | 'folder' | 'isTest'>;
/** Status codes for the action. */
export declare enum Status {
SUCCESS = "success",
Expand Down
27 changes: 13 additions & 14 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,49 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Status = exports.action = void 0;
exports.Status = exports.action = exports.TestFlag = void 0;
const core_1 = require("@actions/core");
const github = __importStar(require("@actions/github"));
const util_1 = require("./util");
const { pusher, repository } = github.context.payload;
/* Flags to signal different scenarios to test cases */
var TestFlag;
(function (TestFlag) {
TestFlag[TestFlag["NONE"] = 0] = "NONE";
TestFlag[TestFlag["HAS_CHANGED_FILES"] = 2] = "HAS_CHANGED_FILES";
TestFlag[TestFlag["HAS_REMOTE_BRANCH"] = 4] = "HAS_REMOTE_BRANCH"; // Assume remote repository has existing commits
})(TestFlag = exports.TestFlag || (exports.TestFlag = {}));
/* Required action data that gets initialized when running within the GitHub Actions environment. */
exports.action = {
accessToken: core_1.getInput('ACCESS_TOKEN'),
baseBranch: core_1.getInput('BASE_BRANCH'),
folder: core_1.getInput('FOLDER'),
branch: core_1.getInput('BRANCH'),
commitMessage: core_1.getInput('COMMIT_MESSAGE'),
dryRun: !util_1.isNullOrUndefined(core_1.getInput('DRY_RUN'))
? core_1.getInput('DRY_RUN').toLowerCase() === 'true'
: false,
clean: !util_1.isNullOrUndefined(core_1.getInput('CLEAN'))
? core_1.getInput('CLEAN').toLowerCase() === 'true'
: false,
cleanExclude: core_1.getInput('CLEAN_EXCLUDE'),
defaultBranch: process.env.GITHUB_SHA ? process.env.GITHUB_SHA : 'master',
isTest: process.env.UNIT_TEST
? process.env.UNIT_TEST.toLowerCase() === 'true'
: false,
lfs: !util_1.isNullOrUndefined(core_1.getInput('LFS'))
? core_1.getInput('LFS').toLowerCase() === 'true'
: false,
isTest: TestFlag.NONE,
email: !util_1.isNullOrUndefined(core_1.getInput('GIT_CONFIG_EMAIL'))
? core_1.getInput('GIT_CONFIG_EMAIL')
: pusher && pusher.email
? pusher.email
: `${process.env.GITHUB_ACTOR || 'github-pages-deploy-action'}@users.noreply.github.com`,
gitHubToken: core_1.getInput('GITHUB_TOKEN'),
name: !util_1.isNullOrUndefined(core_1.getInput('GIT_CONFIG_NAME'))
? core_1.getInput('GIT_CONFIG_NAME')
: pusher && pusher.name
? pusher.name
: process.env.GITHUB_ACTOR
? process.env.GITHUB_ACTOR
: 'GitHub Pages Deploy Action',
preserve: !util_1.isNullOrUndefined(core_1.getInput('PRESERVE'))
? core_1.getInput('PRESERVE').toLowerCase() === 'true'
: false,
repositoryName: !util_1.isNullOrUndefined(core_1.getInput('REPOSITORY_NAME'))
? core_1.getInput('REPOSITORY_NAME')
: repository && repository.full_name
? repository.full_name
: process.env.GITHUB_REPOSITORY,
token: core_1.getInput('TOKEN'),
singleCommit: !util_1.isNullOrUndefined(core_1.getInput('SINGLE_COMMIT'))
? core_1.getInput('SINGLE_COMMIT').toLowerCase() === 'true'
: false,
Expand Down
2 changes: 0 additions & 2 deletions lib/git.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ActionInterface, Status } from './constants';
export declare function init(action: ActionInterface): Promise<void | Error>;
export declare function switchToBaseBranch(action: ActionInterface): Promise<void>;
export declare function generateBranch(action: ActionInterface): Promise<void>;
export declare function deploy(action: ActionInterface): Promise<Status>;
110 changes: 21 additions & 89 deletions lib/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.deploy = exports.generateBranch = exports.switchToBaseBranch = exports.init = void 0;
exports.deploy = exports.init = void 0;
const core_1 = require("@actions/core");
const io_1 = require("@actions/io");
const fs_1 = __importDefault(require("fs"));
const constants_1 = require("./constants");
const execute_1 = require("./execute");
const worktree_1 = require("./worktree");
const util_1 = require("./util");
/* Initializes git in the workspace. */
function init(action) {
return __awaiter(this, void 0, void 0, function* () {
try {
core_1.info(`Deploying using ${action.tokenType}… 🔑`);
core_1.info('Configuring git…');
yield execute_1.execute(`git init`, action.workspace, action.silent);
yield execute_1.execute(`git config user.name "${action.name}"`, action.workspace, action.silent);
yield execute_1.execute(`git config user.email "${action.email}"`, action.workspace, action.silent);
try {
yield execute_1.execute(`git remote rm origin`, action.workspace, action.silent);
if (action.isTest) {
throw new Error();
}
}
catch (_a) {
core_1.info('Attempted to remove origin but failed, continuing…');
}
yield execute_1.execute(`git remote add origin ${action.repositoryPath}`, action.workspace, action.silent);
if (action.preserve) {
core_1.info(`Stashing workspace changes… ⬆️`);
yield execute_1.execute(`git stash`, action.workspace, action.silent);
}
yield execute_1.execute(`git fetch --no-recurse-submodules`, action.workspace, action.silent);
core_1.info('Git configured… 🔧');
}
catch (error) {
Expand All @@ -51,37 +36,6 @@ function init(action) {
});
}
exports.init = init;
/* Switches to the base branch. */
function switchToBaseBranch(action) {
return __awaiter(this, void 0, void 0, function* () {
try {
yield execute_1.execute(`git checkout --progress --force ${action.baseBranch ? action.baseBranch : action.defaultBranch}`, action.workspace, action.silent);
}
catch (error) {
throw new Error(`There was an error switching to the base branch: ${util_1.suppressSensitiveInformation(error.message, action)} ❌`);
}
});
}
exports.switchToBaseBranch = switchToBaseBranch;
/* Generates the branch if it doesn't exist on the remote. */
function generateBranch(action) {
return __awaiter(this, void 0, void 0, function* () {
try {
core_1.info(`Creating the ${action.branch} branch…`);
yield switchToBaseBranch(action);
yield execute_1.execute(`git checkout --orphan ${action.branch}`, action.workspace, action.silent);
yield execute_1.execute(`git reset --hard`, action.workspace, action.silent);
yield execute_1.execute(`git commit --no-verify --allow-empty -m "Initial ${action.branch} commit"`, action.workspace, action.silent);
yield execute_1.execute(`git push --force ${action.repositoryPath} ${action.branch}`, action.workspace, action.silent);
yield execute_1.execute(`git fetch`, action.workspace, action.silent);
core_1.info(`Created the ${action.branch} branch… 🔧`);
}
catch (error) {
throw new Error(`There was an error creating the deployment branch: ${util_1.suppressSensitiveInformation(error.message, action)} ❌`);
}
});
}
exports.generateBranch = generateBranch;
/* Runs the necessary steps to make the deployment. */
function deploy(action) {
return __awaiter(this, void 0, void 0, function* () {
Expand All @@ -93,33 +47,11 @@ function deploy(action) {
try {
const commitMessage = !util_1.isNullOrUndefined(action.commitMessage)
? action.commitMessage
: `Deploying to ${action.branch} from ${action.baseBranch} ${process.env.GITHUB_SHA ? `@ ${process.env.GITHUB_SHA}` : ''} 🚀`;
/*
Checks to see if the remote exists prior to deploying.
If the branch doesn't exist it gets created here as an orphan.
*/
const branchExists = yield execute_1.execute(`git ls-remote --heads ${action.repositoryPath} ${action.branch} | wc -l`, action.workspace, action.silent);
if (!branchExists && !action.isTest) {
yield generateBranch(action);
}
// Checks out the base branch to begin the deployment process.
yield switchToBaseBranch(action);
yield execute_1.execute(`git fetch ${action.repositoryPath}`, action.workspace, action.silent);
if (action.lfs) {
// Migrates data from LFS so it can be comitted the "normal" way.
core_1.info(`Migrating from Git LFS… ⚓`);
yield execute_1.execute(`git lfs migrate export --include="*" --yes`, action.workspace, action.silent);
}
if (action.preserve) {
core_1.info(`Applying stashed workspace changes… ⬆️`);
try {
yield execute_1.execute(`git stash apply`, action.workspace, action.silent);
}
catch (_a) {
core_1.info('Unable to apply from stash, continuing…');
}
}
yield execute_1.execute(`git worktree add --checkout ${temporaryDeploymentDirectory} origin/${action.branch}`, action.workspace, action.silent);
: `Deploying to ${action.branch}${process.env.GITHUB_SHA ? ` from @ ${process.env.GITHUB_SHA}` : ''} 🚀`;
// Checks to see if the remote exists prior to deploying.
const branchExists = action.isTest & constants_1.TestFlag.HAS_REMOTE_BRANCH ||
(yield execute_1.execute(`git ls-remote --heads ${action.repositoryPath} ${action.branch} | wc -l`, action.workspace, action.silent));
yield worktree_1.generateWorktree(action, temporaryDeploymentDirectory, branchExists);
// Ensures that items that need to be excluded from the clean job get parsed.
let excludes = '';
if (action.clean && action.cleanExclude) {
Expand All @@ -131,7 +63,7 @@ function deploy(action) {
excludes += `--exclude ${item} `;
}
}
catch (_b) {
catch (_a) {
core_1.info('There was an error parsing your CLEAN_EXCLUDE items. Please refer to the README for more details. ❌');
}
}
Expand All @@ -154,26 +86,26 @@ function deploy(action) {
: ''} --exclude .ssh --exclude .git --exclude .github ${action.folderPath === action.workspace
? `--exclude ${temporaryDeploymentDirectory}`
: ''}`, action.workspace, action.silent);
const hasFilesToCommit = yield execute_1.execute(`git status --porcelain`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent);
if (!hasFilesToCommit && !action.isTest) {
// Use git status to check if we have something to commit.
// Special case is singleCommit with existing history, when
// we're really interested if the diff against the upstream branch
// changed.
const checkGitStatus = branchExists && action.singleCommit
? `git diff origin/${action.branch}`
: `git status --porcelain`;
const hasFilesToCommit = action.isTest & constants_1.TestFlag.HAS_CHANGED_FILES ||
(yield execute_1.execute(checkGitStatus, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent));
if (!hasFilesToCommit) {
return constants_1.Status.SKIPPED;
}
// Commits to GitHub.
yield execute_1.execute(`git add --all .`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent);
yield execute_1.execute(`git checkout -b ${temporaryDeploymentBranch}`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent);
yield execute_1.execute(`git commit -m "${commitMessage}" --quiet --no-verify`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent);
yield execute_1.execute(`git push --force ${action.repositoryPath} ${temporaryDeploymentBranch}:${action.branch}`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent);
core_1.info(`Changes committed to the ${action.branch} branch… 📦`);
if (action.singleCommit) {
yield execute_1.execute(`git fetch ${action.repositoryPath}`, action.workspace, action.silent);
yield execute_1.execute(`git checkout --orphan ${action.branch}-temp`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent);
yield execute_1.execute(`git add --all .`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent);
yield execute_1.execute(`git commit -m "${commitMessage}" --quiet --no-verify`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent);
yield execute_1.execute(`git branch -M ${action.branch}-temp ${action.branch}`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent);
yield execute_1.execute(`git push origin ${action.branch} --force`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent);
core_1.info('Cleared git history… 🚿');
if (!action.dryRun) {
yield execute_1.execute(`git push --force ${action.repositoryPath} ${temporaryDeploymentBranch}:${action.branch}`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent);
}
yield execute_1.execute(`git checkout --progress --force ${action.defaultBranch}`, action.workspace, action.silent);
core_1.info(`Changes committed to the ${action.branch} branch… 📦`);
return constants_1.Status.SUCCESS;
}
catch (error) {
Expand Down

0 comments on commit ae11479

Please sign in to comment.