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
This commit is contained in:
James Ives 2020-01-14 10:04:59 -05:00 committed by GitHub
parent d3ab8ea1b9
commit 8a621223c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 15 deletions

View File

@ -42,9 +42,35 @@ jobs:
BASE_BRANCH: dev BASE_BRANCH: dev
TARGET_FOLDER: montezuma2 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. # Deploys using the CLEAN option.
integration-clean: integration-clean:
needs: [integration-checkout-v1, integration-checkout-v2] needs: [integration-checkout-v1, integration-checkout-v2, integration-container]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout

View File

@ -96,6 +96,19 @@ jobs:
</p> </p>
</details> </details>
#### 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 📁 ## 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). 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).

View File

@ -7,7 +7,7 @@ jest.mock('@actions/exec', () => ({
describe('execute', () => { describe('execute', () => {
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', './') await execute('echo Montezuma', './')
expect(exec).toBeCalledWith( expect(exec).toBeCalledWith(

View File

@ -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."); 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("./")) { 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.`); 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); yield execute_1.execute(`git init`, constants_1.workspace);
@ -53,9 +52,7 @@ exports.init = init;
*/ */
function switchToBaseBranch() { function switchToBaseBranch() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
yield execute_1.execute(constants_1.action.baseBranch yield execute_1.execute(`git checkout --progress --force ${constants_1.action.baseBranch ? constants_1.action.baseBranch : constants_1.action.defaultBranch}`, constants_1.workspace);
? `git switch ${constants_1.action.baseBranch}`
: `git checkout --progress --force ${constants_1.action.defaultBranch}`, constants_1.workspace);
return Promise.resolve("Switched to the base branch..."); return Promise.resolve("Switched to the base branch...");
}); });
} }
@ -68,7 +65,7 @@ function generateBranch() {
try { try {
console.log(`Creating ${constants_1.action.branch} branch... 🔧`); console.log(`Creating ${constants_1.action.branch} branch... 🔧`);
yield switchToBaseBranch(); 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 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 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); 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. // Commits to GitHub.
yield execute_1.execute(`git add --all .`, temporaryDeploymentDirectory); 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 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); 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. // Cleans up temporary files/folders and restores the git state.

View File

@ -18,7 +18,6 @@ export async function init(): Promise<any> {
} }
if (action.build.startsWith("/") || action.build.startsWith("./")) { if (action.build.startsWith("/") || action.build.startsWith("./")) {
console.log("2");
return core.setFailed( return core.setFailed(
`The deployment folder cannot be prefixed with '/' or './'. Instead reference the folder name directly.` `The deployment folder cannot be prefixed with '/' or './'. Instead reference the folder name directly.`
); );
@ -38,11 +37,11 @@ export async function init(): Promise<any> {
/** Switches to the base branch. /** Switches to the base branch.
* @returns {Promise} * @returns {Promise}
*/ */
export async function switchToBaseBranch() { export async function switchToBaseBranch(): Promise<any> {
await execute( await execute(
action.baseBranch `git checkout --progress --force ${
? `git switch ${action.baseBranch}` action.baseBranch ? action.baseBranch : action.defaultBranch
: `git checkout --progress --force ${action.defaultBranch}`, }`,
workspace workspace
); );
@ -56,7 +55,7 @@ export async function generateBranch(): Promise<any> {
try { try {
console.log(`Creating ${action.branch} branch... 🔧`); console.log(`Creating ${action.branch} branch... 🔧`);
await switchToBaseBranch(); 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 reset --hard`, workspace);
await execute( await execute(
`git commit --allow-empty -m "Initial ${action.branch} commit."`, `git commit --allow-empty -m "Initial ${action.branch} commit."`,
@ -147,7 +146,7 @@ export async function deploy(): Promise<any> {
// Commits to GitHub. // Commits to GitHub.
await execute(`git add --all .`, temporaryDeploymentDirectory); await execute(`git add --all .`, temporaryDeploymentDirectory);
await execute( await execute(
`git switch -c ${temporaryDeploymentBranch}`, `git checkout -b ${temporaryDeploymentBranch}`,
temporaryDeploymentDirectory temporaryDeploymentDirectory
); );
await execute( await execute(