Skip to content

Commit

Permalink
Deploy Production Code for Commit 1bca7e0 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesIves committed Nov 18, 2021
1 parent 1bca7e0 commit dbe7868
Show file tree
Hide file tree
Showing 77 changed files with 970 additions and 345 deletions.
52 changes: 26 additions & 26 deletions lib/constants.js
Expand Up @@ -35,55 +35,55 @@ var TestFlag;
})(TestFlag = exports.TestFlag || (exports.TestFlag = {}));
/* Required action data that gets initialized when running within the GitHub Actions environment. */
exports.action = {
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'
folder: (0, core_1.getInput)('folder'),
branch: (0, core_1.getInput)('branch'),
commitMessage: (0, core_1.getInput)('commit-message'),
dryRun: !(0, util_1.isNullOrUndefined)((0, core_1.getInput)('dry-run'))
? (0, core_1.getInput)('dry-run').toLowerCase() === 'true'
: false,
clean: !util_1.isNullOrUndefined(core_1.getInput('clean'))
? core_1.getInput('clean').toLowerCase() === 'true'
clean: !(0, util_1.isNullOrUndefined)((0, core_1.getInput)('clean'))
? (0, core_1.getInput)('clean').toLowerCase() === 'true'
: false,
cleanExclude: (core_1.getInput('clean-exclude') || '')
cleanExclude: ((0, core_1.getInput)('clean-exclude') || '')
.split('\n')
.filter(l => l !== ''),
hostname: process.env.GITHUB_SERVER_URL
? util_1.stripProtocolFromUrl(process.env.GITHUB_SERVER_URL)
? (0, util_1.stripProtocolFromUrl)(process.env.GITHUB_SERVER_URL)
: 'github.com',
isTest: TestFlag.NONE,
email: !util_1.isNullOrUndefined(core_1.getInput('git-config-email'))
? core_1.getInput('git-config-email')
email: !(0, util_1.isNullOrUndefined)((0, core_1.getInput)('git-config-email'), true)
? (0, core_1.getInput)('git-config-email')
: pusher && pusher.email
? pusher.email
: `${process.env.GITHUB_ACTOR || 'github-pages-deploy-action'}@users.noreply.${process.env.GITHUB_SERVER_URL
? util_1.stripProtocolFromUrl(process.env.GITHUB_SERVER_URL)
? (0, util_1.stripProtocolFromUrl)(process.env.GITHUB_SERVER_URL)
: 'github.com'}`,
name: !util_1.isNullOrUndefined(core_1.getInput('git-config-name'))
? core_1.getInput('git-config-name')
name: !(0, util_1.isNullOrUndefined)((0, core_1.getInput)('git-config-name'))
? (0, core_1.getInput)('git-config-name')
: pusher && pusher.name
? pusher.name
: process.env.GITHUB_ACTOR
? process.env.GITHUB_ACTOR
: 'GitHub Pages Deploy Action',
repositoryName: !util_1.isNullOrUndefined(core_1.getInput('repository-name'))
? core_1.getInput('repository-name')
repositoryName: !(0, util_1.isNullOrUndefined)((0, core_1.getInput)('repository-name'))
? (0, 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'
token: (0, core_1.getInput)('token'),
singleCommit: !(0, util_1.isNullOrUndefined)((0, core_1.getInput)('single-commit'))
? (0, core_1.getInput)('single-commit').toLowerCase() === 'true'
: false,
silent: !util_1.isNullOrUndefined(core_1.getInput('silent'))
? core_1.getInput('silent').toLowerCase() === 'true'
silent: !(0, util_1.isNullOrUndefined)((0, core_1.getInput)('silent'))
? (0, core_1.getInput)('silent').toLowerCase() === 'true'
: false,
sshKey: util_1.isNullOrUndefined(core_1.getInput('ssh-key'))
sshKey: (0, util_1.isNullOrUndefined)((0, core_1.getInput)('ssh-key'))
? false
: !util_1.isNullOrUndefined(core_1.getInput('ssh-key')) &&
core_1.getInput('ssh-key').toLowerCase() === 'true'
: !(0, util_1.isNullOrUndefined)((0, core_1.getInput)('ssh-key')) &&
(0, core_1.getInput)('ssh-key').toLowerCase() === 'true'
? true
: core_1.getInput('ssh-key'),
targetFolder: core_1.getInput('target-folder'),
: (0, core_1.getInput)('ssh-key'),
targetFolder: (0, core_1.getInput)('target-folder'),
workspace: process.env.GITHUB_WORKSPACE || ''
};
/** Status codes for the action. */
Expand Down
2 changes: 1 addition & 1 deletion lib/execute.js
Expand Up @@ -26,7 +26,7 @@ let output = '';
function execute(cmd, cwd, silent) {
return __awaiter(this, void 0, void 0, function* () {
output = '';
yield exec_1.exec(cmd, [], {
yield (0, exec_1.exec)(cmd, [], {
// Silences the input unless the INPUT_DEBUG flag is set.
silent,
cwd,
Expand Down
63 changes: 32 additions & 31 deletions lib/git.js
Expand Up @@ -24,38 +24,38 @@ const util_1 = require("./util");
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 config user.name "${action.name}"`, action.workspace, action.silent);
yield execute_1.execute(`git config user.email "${action.email}"`, action.workspace, action.silent);
(0, core_1.info)(`Deploying using ${action.tokenType}… 🔑`);
(0, core_1.info)('Configuring git…');
yield (0, execute_1.execute)(`git config user.name "${action.name}"`, action.workspace, action.silent);
yield (0, execute_1.execute)(`git config user.email "${action.email ? action.email : '<>'}"`, action.workspace, action.silent);
try {
if ((process.env.CI && !action.sshKey) || action.isTest) {
/* Ensures that previously set Git configs do not interfere with the deployment.
Only runs in the GitHub Actions CI environment if a user is not using an SSH key.
*/
yield execute_1.execute(`git config --local --unset-all http.https://${action.hostname}/.extraheader`, action.workspace, action.silent);
yield (0, execute_1.execute)(`git config --local --unset-all http.https://${action.hostname}/.extraheader`, action.workspace, action.silent);
}
if (action.isTest === constants_1.TestFlag.UNABLE_TO_UNSET_GIT_CONFIG) {
throw new Error();
}
}
catch (_a) {
core_1.info('Unable to unset previous git config authentication as it may not exist, continuing…');
(0, core_1.info)('Unable to unset previous git config authentication as it may not exist, continuing…');
}
try {
yield execute_1.execute(`git remote rm origin`, action.workspace, action.silent);
yield (0, execute_1.execute)(`git remote rm origin`, action.workspace, action.silent);
if (action.isTest === constants_1.TestFlag.UNABLE_TO_REMOVE_ORIGIN) {
throw new Error();
}
}
catch (_b) {
core_1.info('Attempted to remove origin but failed, continuing…');
(0, core_1.info)('Attempted to remove origin but failed, continuing…');
}
yield execute_1.execute(`git remote add origin ${action.repositoryPath}`, action.workspace, action.silent);
core_1.info('Git configured… 🔧');
yield (0, execute_1.execute)(`git remote add origin ${action.repositoryPath}`, action.workspace, action.silent);
(0, core_1.info)('Git configured… 🔧');
}
catch (error) {
throw new Error(`There was an error initializing the repository: ${util_1.suppressSensitiveInformation(error.message, action)} ❌`);
throw new Error(`There was an error initializing the repository: ${(0, util_1.suppressSensitiveInformation)((0, util_1.extractErrorMessage)(error), action)} ❌`);
}
});
}
Expand All @@ -67,17 +67,17 @@ function deploy(action) {
const temporaryDeploymentBranch = `github-pages-deploy-action/${Math.random()
.toString(36)
.substr(2, 9)}`;
core_1.info('Starting to commit changes…');
(0, core_1.info)('Starting to commit changes…');
try {
const commitMessage = !util_1.isNullOrUndefined(action.commitMessage)
const commitMessage = !(0, util_1.isNullOrUndefined)(action.commitMessage)
? action.commitMessage
: `Deploying to ${action.branch}${process.env.GITHUB_SHA
? ` from @ ${process.env.GITHUB_REPOSITORY}@${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} refs/heads/${action.branch}`, action.workspace, action.silent));
yield worktree_1.generateWorktree(action, temporaryDeploymentDirectory, branchExists);
(yield (0, execute_1.execute)(`git ls-remote --heads ${action.repositoryPath} refs/heads/${action.branch}`, action.workspace, action.silent));
yield (0, 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 @@ -86,14 +86,14 @@ function deploy(action) {
}
}
if (action.targetFolder) {
core_1.info(`Creating target folder if it doesn't already exist… 📌`);
yield io_1.mkdirP(`${temporaryDeploymentDirectory}/${action.targetFolder}`);
(0, core_1.info)(`Creating target folder if it doesn't already exist… 📌`);
yield (0, io_1.mkdirP)(`${temporaryDeploymentDirectory}/${action.targetFolder}`);
}
/*
Pushes all of the build files into the deployment directory.
Allows the user to specify the root if '.' is provided.
rsync is used to prevent file duplication. */
yield execute_1.execute(`rsync -q -av --checksum --progress ${action.folderPath}/. ${action.targetFolder
yield (0, execute_1.execute)(`rsync -q -av --checksum --progress ${action.folderPath}/. ${action.targetFolder
? `${temporaryDeploymentDirectory}/${action.targetFolder}`
: temporaryDeploymentDirectory} ${action.clean
? `--delete ${excludes} ${!fs_1.default.existsSync(`${action.folderPath}/CNAME`)
Expand All @@ -105,7 +105,7 @@ function deploy(action) {
? `--exclude ${temporaryDeploymentDirectory}`
: ''}`, action.workspace, action.silent);
if (action.singleCommit) {
yield execute_1.execute(`git add --all .`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent);
yield (0, execute_1.execute)(`git add --all .`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent);
}
// Use git status to check if we have something to commit.
// Special case is singleCommit with existing history, when
Expand All @@ -114,34 +114,35 @@ function deploy(action) {
const checkGitStatus = branchExists && action.singleCommit
? `git diff origin/${action.branch}`
: `git status --porcelain`;
core_1.info(`Checking if there are files to commit…`);
(0, core_1.info)(`Checking if there are files to commit…`);
const hasFilesToCommit = action.isTest & constants_1.TestFlag.HAS_CHANGED_FILES ||
(yield execute_1.execute(checkGitStatus, `${action.workspace}/${temporaryDeploymentDirectory}`, true // This output is always silenced due to the large output it creates.
(yield (0, execute_1.execute)(checkGitStatus, `${action.workspace}/${temporaryDeploymentDirectory}`, true // This output is always silenced due to the large output it creates.
));
if ((!action.singleCommit && !hasFilesToCommit) ||
// Ignores the case where single commit is true with a target folder to prevent incorrect early exiting.
(action.singleCommit && !action.targetFolder && !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 (0, execute_1.execute)(`git add --all .`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent);
yield (0, execute_1.execute)(`git checkout -b ${temporaryDeploymentBranch}`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent);
yield (0, execute_1.execute)(`git commit -m "${commitMessage}" --quiet --no-verify`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent);
if (!action.dryRun) {
yield execute_1.execute(`git push --force ${action.repositoryPath} ${temporaryDeploymentBranch}:${action.branch}`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent);
yield (0, 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… 📦`);
(0, core_1.info)(`Changes committed to the ${action.branch} branch… 📦`);
return constants_1.Status.SUCCESS;
}
catch (error) {
throw new Error(`The deploy step encountered an error: ${util_1.suppressSensitiveInformation(error.message, action)} ❌`);
throw new Error(`The deploy step encountered an error: ${(0, util_1.suppressSensitiveInformation)((0, util_1.extractErrorMessage)(error), action)} ❌`);
}
finally {
// Cleans up temporary files/folders and restores the git state.
core_1.info('Running post deployment cleanup jobs… 🗑️');
yield execute_1.execute(`git checkout -B ${temporaryDeploymentBranch}`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent);
yield execute_1.execute(`git worktree remove ${temporaryDeploymentDirectory} --force`, action.workspace, action.silent);
yield io_1.rmRF(temporaryDeploymentDirectory);
(0, core_1.info)('Running post deployment cleanup jobs… 🗑️');
yield (0, execute_1.execute)(`git checkout -B ${temporaryDeploymentBranch}`, `${action.workspace}/${temporaryDeploymentDirectory}`, action.silent);
yield (0, execute_1.execute)(`chmod -R 777 ${temporaryDeploymentDirectory}`, action.workspace, action.silent);
yield (0, execute_1.execute)(`git worktree remove ${temporaryDeploymentDirectory} --force`, action.workspace, action.silent);
yield (0, io_1.rmRF)(temporaryDeploymentDirectory);
}
});
}
Expand Down
26 changes: 13 additions & 13 deletions lib/lib.js
Expand Up @@ -22,7 +22,7 @@ function run(configuration) {
return __awaiter(this, void 0, void 0, function* () {
let status = constants_1.Status.RUNNING;
try {
core_1.info(`
(0, core_1.info)(`
GitHub Pages Deploy Action 🚀
🚀 Getting Started Guide: https://github.com/marketplace/actions/deploy-to-github-pages
Expand All @@ -31,32 +31,32 @@ function run(configuration) {
📣 Maintained by James Ives: https://jamesiv.es
💖 Support: https://github.com/sponsors/JamesIves`);
core_1.info('Checking configuration and starting deployment… 🚦');
(0, core_1.info)('Checking configuration and starting deployment… 🚦');
const settings = Object.assign({}, configuration);
// Defines the repository/folder paths and token types.
// Also verifies that the action has all of the required parameters.
settings.folderPath = util_1.generateFolderPath(settings);
util_1.checkParameters(settings);
settings.repositoryPath = util_1.generateRepositoryPath(settings);
settings.tokenType = util_1.generateTokenType(settings);
settings.folderPath = (0, util_1.generateFolderPath)(settings);
(0, util_1.checkParameters)(settings);
settings.repositoryPath = (0, util_1.generateRepositoryPath)(settings);
settings.tokenType = (0, util_1.generateTokenType)(settings);
if (settings.sshKey) {
yield ssh_1.configureSSH(settings);
yield (0, ssh_1.configureSSH)(settings);
}
yield git_1.init(settings);
status = yield git_1.deploy(settings);
yield (0, git_1.init)(settings);
status = yield (0, git_1.deploy)(settings);
}
catch (error) {
status = constants_1.Status.FAILED;
core_1.setFailed(error.message);
(0, core_1.setFailed)((0, util_1.extractErrorMessage)(error));
}
finally {
core_1.info(`${status === constants_1.Status.FAILED
(0, core_1.info)(`${status === constants_1.Status.FAILED
? 'Deployment failed! ❌'
: status === constants_1.Status.SUCCESS
? 'Completed deployment successfully! ✅'
: 'There is nothing to commit. Exiting early… 📭'}`);
core_1.exportVariable('deployment_status', status);
core_1.setOutput('deployment-status', status);
(0, core_1.exportVariable)('deployment_status', status);
(0, core_1.setOutput)('deployment-status', status);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/main.js
Expand Up @@ -6,4 +6,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("./constants");
const lib_1 = __importDefault(require("./lib"));
// Runs the action within the GitHub actions environment.
lib_1.default(constants_1.action);
(0, lib_1.default)(constants_1.action);

0 comments on commit dbe7868

Please sign in to comment.