function deploy() {
    return __awaiter(this, void 0, void 0, function* () {
        const temporaryDeploymentDirectory = "gh-action-temp-deployment-folder";
        const temporaryDeploymentBranch = "gh-action-temp-deployment-branch";
        /*
            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 ${constants_1.repositoryPath} ${constants_1.action.branch} | wc -l`, constants_1.workspace);
        if (!branchExists) {
            console.log("Deployment branch does not exist. Creating....");
            yield generateBranch();
        }
        // Checks out the base branch to begin the deployment process.
        yield switchToBaseBranch();
        yield execute_1.execute(`git fetch ${constants_1.repositoryPath}`, constants_1.workspace);
        yield execute_1.execute(`git worktree add --checkout ${temporaryDeploymentDirectory} origin/${constants_1.action.branch}`, constants_1.workspace);
        // Ensures that items that need to be excluded from the clean job get parsed.
        let excludes = "";
        if (constants_1.action.clean && constants_1.action.cleanExclude) {
            try {
                const excludedItems = JSON.parse(constants_1.action.cleanExclude);
                excludedItems.forEach((item) => (excludes += `--exclude ${item} `));
            }
            catch (_a) {
                console.log("There was an error parsing your CLEAN_EXCLUDE items. Please refer to the README for more details. ❌");
            }
        }
        /*
          Pushes all of the build files into the deployment directory.
          Allows the user to specify the root if '.' is provided.
          rysync is used to prevent file duplication. */
        yield execute_1.execute(`rsync -q -av --progress ${constants_1.action.build}/. ${constants_1.action.targetFolder
            ? `${temporaryDeploymentDirectory}/${constants_1.action.targetFolder}`
            : temporaryDeploymentDirectory} ${constants_1.action.clean
            ? `--delete ${excludes} --exclude CNAME --exclude .nojekyll`
            : ""}  --exclude .git --exclude .github ${constants_1.action.build === constants_1.root ? `--exclude ${temporaryDeploymentDirectory}` : ""}`, constants_1.workspace);
        const hasFilesToCommit = yield execute_1.execute(`git status --porcelain`, temporaryDeploymentDirectory);
        if (!hasFilesToCommit && !constants_1.isTest) {
            console.log("There is nothing to commit. Exiting... ✅");
            return Promise.resolve();
        }
        // Commits to GitHub.
        yield execute_1.execute(`git add --all .`, temporaryDeploymentDirectory);
        yield execute_1.execute(`git checkout -b ${temporaryDeploymentBranch}`, temporaryDeploymentDirectory);
        yield execute_1.execute(`git commit -m "${constants_1.action.commitMessage
            ? constants_1.action.commitMessage
            : `Deploying to ${constants_1.action.branch} from ${constants_1.action.baseBranch}`} ${process.env.GITHUB_SHA} 🚀" --quiet`, temporaryDeploymentDirectory);
        yield execute_1.execute(`git push --force ${constants_1.repositoryPath} ${temporaryDeploymentBranch}:${constants_1.action.branch}`, temporaryDeploymentDirectory);
        // Cleans up temporary files/folders and restores the git state.
        console.log("Running post deployment cleanup jobs... 🔧");
        yield execute_1.execute(`rm -rf ${temporaryDeploymentDirectory}`, constants_1.workspace);
        yield execute_1.execute(`git checkout --progress --force ${constants_1.action.defaultBranch}`, constants_1.workspace);
        return Promise.resolve("Commit step complete...");
    });
}
/** Runs the necessary steps to make the deployment.
 * @returns {Promise}
 */
Runs the necessary steps to make the deployment.
@returns {Promise}
Runs the necessary steps to make the deployment . @returns { Promise }
function deploy() {
    return __awaiter(this, void 0, void 0, function* () {
        const temporaryDeploymentDirectory = "gh-action-temp-deployment-folder";
        const temporaryDeploymentBranch = "gh-action-temp-deployment-branch";
        const branchExists = yield execute_1.execute(`git ls-remote --heads ${constants_1.repositoryPath} ${constants_1.action.branch} | wc -l`, constants_1.workspace);
        if (!branchExists) {
            console.log("Deployment branch does not exist. Creating....");
            yield generateBranch();
        }
        yield switchToBaseBranch();
        yield execute_1.execute(`git fetch ${constants_1.repositoryPath}`, constants_1.workspace);
        yield execute_1.execute(`git worktree add --checkout ${temporaryDeploymentDirectory} origin/${constants_1.action.branch}`, constants_1.workspace);
        let excludes = "";
        if (constants_1.action.clean && constants_1.action.cleanExclude) {
            try {
                const excludedItems = JSON.parse(constants_1.action.cleanExclude);
                excludedItems.forEach((item) => (excludes += `--exclude ${item} `));
            }
            catch (_a) {
                console.log("There was an error parsing your CLEAN_EXCLUDE items. Please refer to the README for more details. ❌");
            }
        }
        yield execute_1.execute(`rsync -q -av --progress ${constants_1.action.build}/. ${constants_1.action.targetFolder
            ? `${temporaryDeploymentDirectory}/${constants_1.action.targetFolder}`
            : temporaryDeploymentDirectory} ${constants_1.action.clean
            ? `--delete ${excludes} --exclude CNAME --exclude .nojekyll`
            : ""}  --exclude .git --exclude .github ${constants_1.action.build === constants_1.root ? `--exclude ${temporaryDeploymentDirectory}` : ""}`, constants_1.workspace);
        const hasFilesToCommit = yield execute_1.execute(`git status --porcelain`, temporaryDeploymentDirectory);
        if (!hasFilesToCommit && !constants_1.isTest) {
            console.log("There is nothing to commit. Exiting... ✅");
            return Promise.resolve();
        }
        yield execute_1.execute(`git add --all .`, temporaryDeploymentDirectory);
        yield execute_1.execute(`git checkout -b ${temporaryDeploymentBranch}`, temporaryDeploymentDirectory);
        yield execute_1.execute(`git commit -m "${constants_1.action.commitMessage
            ? constants_1.action.commitMessage
            : `Deploying to ${constants_1.action.branch} from ${constants_1.action.baseBranch}`} ${process.env.GITHUB_SHA} 🚀" --quiet`, temporaryDeploymentDirectory);
        yield execute_1.execute(`git push --force ${constants_1.repositoryPath} ${temporaryDeploymentBranch}:${constants_1.action.branch}`, temporaryDeploymentDirectory);
        console.log("Running post deployment cleanup jobs... 🔧");
        yield execute_1.execute(`rm -rf ${temporaryDeploymentDirectory}`, constants_1.workspace);
        yield execute_1.execute(`git checkout --progress --force ${constants_1.action.defaultBranch}`, constants_1.workspace);
        return Promise.resolve("Commit step complete...");
    });
}
function deploy ( ) { return __awaiter ( this , void 0 , void 0 , function * ( ) { const temporaryDeploymentDirectory = "gh-action-temp-deployment-folder" ; const temporaryDeploymentBranch = "gh-action-temp-deployment-branch" ; const branchExists = yield execute_1 . execute ( ` ${ constants_1 . repositoryPath } ${ constants_1 . action . branch } ` , constants_1 . workspace ) ; if ( ! branchExists ) { console . log ( "Deployment branch does not exist. Creating...." ) ; yield generateBranch ( ) ; } yield switchToBaseBranch ( ) ; yield execute_1 . execute ( ` ${ constants_1 . repositoryPath } ` , constants_1 . workspace ) ; yield execute_1 . execute ( ` ${ temporaryDeploymentDirectory } ${ constants_1 . action . branch } ` , constants_1 . workspace ) ; let excludes = "" ; if ( constants_1 . action . clean && constants_1 . action . cleanExclude ) { try { const excludedItems = JSON . parse ( constants_1 . action . cleanExclude ) ; excludedItems . forEach ( ( item ) => ( excludes += ` ${ item } ` ) ) ; } catch ( _a ) { console . log ( "There was an error parsing your CLEAN_EXCLUDE items. Please refer to the README for more details. ❌"); } } yield execute_1 . execute ( ` ${ constants_1 . action . build } ${ constants_1 . action . targetFolder ? ` ${ temporaryDeploymentDirectory } ${ constants_1 . action . targetFolder } ` : temporaryDeploymentDirectory } ${ constants_1 . action . clean ? ` ${ excludes } ` : "" } ${ constants_1 . action . build === constants_1 . root ? ` ${ temporaryDeploymentDirectory } ` : "" } ` , constants_1 . workspace ) ; const hasFilesToCommit = yield execute_1 . execute ( ` ` , temporaryDeploymentDirectory ) ; if ( ! hasFilesToCommit && ! constants_1 . isTest ) { console . log ( "There is nothing to commit. Exiting... ✅"); return Promise . resolve ( ) ; } yield execute_1 . execute ( ` ` , temporaryDeploymentDirectory ) ; yield execute_1 . execute ( ` ${ temporaryDeploymentBranch } ` , temporaryDeploymentDirectory ) ; yield execute_1 . execute ( ` ${ constants_1 . action . commitMessage ? constants_1 . action . commitMessage : ` ${ constants_1 . action . branch } ${ constants_1 . action . baseBranch } ` } ${ process . env . GITHUB_SHA } t e poraryDeploymentDirectory); yield execute_1 . execute ( ` ${ constants_1 . repositoryPath } ${ temporaryDeploymentBranch } ${ constants_1 . action . branch } ` , temporaryDeploymentDirectory ) ; console . log ( "Running post deployment cleanup jobs... 🔧"); yield execute_1 . execute ( ` ${ temporaryDeploymentDirectory } ` , constants_1 . workspace ) ; yield execute_1 . execute ( ` ${ constants_1 . action . defaultBranch } ` , constants_1 . workspace ) ; return Promise . resolve ( "Commit step complete..." ) ; } ) ; }
Runs the necessary steps to make the deployment.
Runs the necessary steps to make the deployment .
/*
            Checks to see if the remote exists prior to deploying.
            If the branch doesn't exist it gets created here as an orphan.
          */ // Checks out the base branch to begin the deployment process. // Ensures that items that need to be excluded from the clean job get parsed. /*
          Pushes all of the build files into the deployment directory.
          Allows the user to specify the root if '.' is provided.
          rysync is used to prevent file duplication. */ // Commits to GitHub. // Cleans up temporary files/folders and restores the git state.