From 8a621223c07e8f597aede25eb9be0422a2676ac5 Mon Sep 17 00:00:00 2001 From: James Ives Date: Tue, 14 Jan 2020 10:04:59 -0500 Subject: [PATCH] git switch -> git checkout (#121) * Changes * Update git.ts * rsync * Remove apt-get * Update git.ts * Update git.js * Update README.md * Update README.md * Update README.md * Integration Test Addition * README * Update integration.yml * Simplify --- .github/workflows/integration.yml | 28 +++++++++++++++++++++++++++- README.md | 13 +++++++++++++ __tests__/execute.test.ts | 2 +- lib/git.js | 9 +++------ src/git.ts | 13 ++++++------- 5 files changed, 50 insertions(+), 15 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 6f766169..b88ad5df 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -42,9 +42,35 @@ jobs: BASE_BRANCH: dev TARGET_FOLDER: montezuma2 + + # Deploys using a container that requires you to install rsync. + integration-container: + needs: integration-checkout-v2 + runs-on: ubuntu-latest + container: + image: ruby:2.6 + env: + LANG: C.UTF-8 + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install rsync + run: | + apt-get update && apt-get install -y rsync + + - name: Build and Deploy + uses: JamesIves/github-pages-deploy-action@releases/v3-test + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BRANCH: gh-pages + FOLDER: integration + BASE_BRANCH: dev + TARGET_FOLDER: montezuma2 + # Deploys using the CLEAN option. integration-clean: - needs: [integration-checkout-v1, integration-checkout-v2] + needs: [integration-checkout-v1, integration-checkout-v2, integration-container] runs-on: ubuntu-latest steps: - name: Checkout diff --git a/README.md b/README.md index a3537613..3d2ef11f 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,19 @@ jobs:

+#### Using a Container 📦 + +If you use a [container](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idcontainer) in your workflow you may need to run an additional step to install `rsync` as this action depends on it. You can view an example of this below. + +```yml +- name: Install rsync + run: | + apt-get update && apt-get install -y rsync + +- name: Deploy + uses: JamesIves/github-pages-deploy-action@releases/v3 +``` + ## Configuration 📁 The `with` portion of the workflow **must** be configured before the action will work. You can add these in the `with` section found in the examples above. Any `secrets` must be referenced using the bracket syntax and stored in the GitHub repositories `Settings/Secrets` menu. You can learn more about setting environment variables with GitHub actions [here](https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepsenv). diff --git a/__tests__/execute.test.ts b/__tests__/execute.test.ts index 2cad0414..892e222f 100644 --- a/__tests__/execute.test.ts +++ b/__tests__/execute.test.ts @@ -7,7 +7,7 @@ jest.mock('@actions/exec', () => ({ describe('execute', () => { describe('execute', () => { - it('should be called with the correct arguements', async() => { + it('should be called with the correct arguments', async() => { await execute('echo Montezuma', './') expect(exec).toBeCalledWith( diff --git a/lib/git.js b/lib/git.js index a9e8e152..771179dd 100644 --- a/lib/git.js +++ b/lib/git.js @@ -31,7 +31,6 @@ function init() { return core.setFailed("You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy."); } if (constants_1.action.build.startsWith("/") || constants_1.action.build.startsWith("./")) { - console.log("2"); return core.setFailed(`The deployment folder cannot be prefixed with '/' or './'. Instead reference the folder name directly.`); } yield execute_1.execute(`git init`, constants_1.workspace); @@ -53,9 +52,7 @@ exports.init = init; */ function switchToBaseBranch() { return __awaiter(this, void 0, void 0, function* () { - yield execute_1.execute(constants_1.action.baseBranch - ? `git switch ${constants_1.action.baseBranch}` - : `git checkout --progress --force ${constants_1.action.defaultBranch}`, constants_1.workspace); + yield execute_1.execute(`git checkout --progress --force ${constants_1.action.baseBranch ? constants_1.action.baseBranch : constants_1.action.defaultBranch}`, constants_1.workspace); return Promise.resolve("Switched to the base branch..."); }); } @@ -68,7 +65,7 @@ function generateBranch() { try { console.log(`Creating ${constants_1.action.branch} branch... 🔧`); yield switchToBaseBranch(); - yield execute_1.execute(`git switch --orphan ${constants_1.action.branch}`, constants_1.workspace); + yield execute_1.execute(`git checkout --orphan ${constants_1.action.branch}`, constants_1.workspace); yield execute_1.execute(`git reset --hard`, constants_1.workspace); yield execute_1.execute(`git commit --allow-empty -m "Initial ${constants_1.action.branch} commit."`, constants_1.workspace); yield execute_1.execute(`git push ${constants_1.repositoryPath} ${constants_1.action.branch}`, constants_1.workspace); @@ -130,7 +127,7 @@ function deploy() { } // Commits to GitHub. yield execute_1.execute(`git add --all .`, temporaryDeploymentDirectory); - yield execute_1.execute(`git switch -c ${temporaryDeploymentBranch}`, temporaryDeploymentDirectory); + yield execute_1.execute(`git checkout -b ${temporaryDeploymentBranch}`, temporaryDeploymentDirectory); yield execute_1.execute(`git commit -m "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. diff --git a/src/git.ts b/src/git.ts index 8c22d5a0..f6c324b0 100644 --- a/src/git.ts +++ b/src/git.ts @@ -18,7 +18,6 @@ export async function init(): Promise { } if (action.build.startsWith("/") || action.build.startsWith("./")) { - console.log("2"); return core.setFailed( `The deployment folder cannot be prefixed with '/' or './'. Instead reference the folder name directly.` ); @@ -38,11 +37,11 @@ export async function init(): Promise { /** Switches to the base branch. * @returns {Promise} */ -export async function switchToBaseBranch() { +export async function switchToBaseBranch(): Promise { await execute( - action.baseBranch - ? `git switch ${action.baseBranch}` - : `git checkout --progress --force ${action.defaultBranch}`, + `git checkout --progress --force ${ + action.baseBranch ? action.baseBranch : action.defaultBranch + }`, workspace ); @@ -56,7 +55,7 @@ export async function generateBranch(): Promise { try { console.log(`Creating ${action.branch} branch... 🔧`); await switchToBaseBranch(); - await execute(`git switch --orphan ${action.branch}`, workspace); + await execute(`git checkout --orphan ${action.branch}`, workspace); await execute(`git reset --hard`, workspace); await execute( `git commit --allow-empty -m "Initial ${action.branch} commit."`, @@ -147,7 +146,7 @@ export async function deploy(): Promise { // Commits to GitHub. await execute(`git add --all .`, temporaryDeploymentDirectory); await execute( - `git switch -c ${temporaryDeploymentBranch}`, + `git checkout -b ${temporaryDeploymentBranch}`, temporaryDeploymentDirectory ); await execute(