Automatically remove hashed files (#63)

* Adding a CLEAN option

* Summary

* Clean

* Tests etc

* Update git.js
This commit is contained in:
James Ives 2019-11-22 09:58:00 -05:00 committed by GitHub
parent 3d79fb5ce1
commit 1c579cbd85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 19 additions and 55 deletions

View File

@ -50,6 +50,7 @@ Below you'll find a description of what each option does.
| `BRANCH` | This is the branch you wish to deploy to, for example `gh-pages` or `docs`. | `with` | **Yes** |
| `FOLDER` | The folder in your repository that you want to deploy. If your build script compiles into a directory named `build` you'd put it here. **Folder paths cannot have a leading `/` or `./`**. If you wish to deploy the root directory you can place a `.` here. | `with` | **Yes** |
| `BASE_BRANCH` | The base branch of your repository which you'd like to checkout prior to deploying. This defaults to `master`. | `with` | **No** |
| `CLEAN` | 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`. | `with` | **No** |
With the action correctly configured you should see the workflow trigger the deployment under the configured conditions.

View File

@ -4,7 +4,6 @@ process.env["INPUT_FOLDER"] = "build";
import { execute } from "../src/util";
import { init, generateBranch, deploy } from "../src/git";
import {action} from '../src/constants'
import {cp} from '@actions/io';
import _ from 'lodash';
const originalAction = _.cloneDeep(action);
@ -13,10 +12,6 @@ jest.mock("../src/util", () => ({
execute: jest.fn()
}));
jest.mock("@actions/io", () => ({
cp: jest.fn()
}));
describe("git", () => {
afterEach(() => {
_.assignIn(action, originalAction);
@ -135,26 +130,8 @@ describe("git", () => {
const call = await deploy();
// Includes the call to generateBranch
expect(execute).toBeCalledTimes(15);
expect(cp).toBeCalledTimes(1)
expect(call).toBe('Commit step complete...')
})
it('should execute six commands if root is used', async () => {
Object.assign(action, {
build: '.',
gitHubToken: '123',
pusher: {
name: 'asd',
email: 'as@cat'
}})
const call = await deploy();
// Includes the call to generateBranch
expect(execute).toBeCalledTimes(16);
expect(cp).toBeCalledTimes(0)
expect(call).toBe('Commit step complete...')
})
})

View File

@ -24,6 +24,7 @@ exports.action = {
accessToken: core.getInput("ACCESS_TOKEN"),
branch: core.getInput("BRANCH"),
baseBranch: core.getInput("BASE_BRANCH") || "master",
clean: core.getInput("CLEAN"),
pusher
};
// Repository path used for commits/pushes.

View File

@ -17,7 +17,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const io_1 = require("@actions/io");
const util_1 = require("./util");
const constants_1 = require("./constants");
/** Generates the branch if it doesn't exist on the remote.
@ -91,17 +90,9 @@ function deploy() {
yield util_1.execute(`git worktree add --checkout ${temporaryDeploymentDirectory} origin/${constants_1.action.branch}`, constants_1.workspace);
/*
Pushes all of the build files into the deployment directory.
Allows the user to specify the root if '.' is provided. */
if (constants_1.action.build === constants_1.root) {
// rsync is executed here so the .git and temporary deployment directories don't get duplicated.
yield util_1.execute(`rsync -q -av --progress ${constants_1.action.build}/. ${temporaryDeploymentDirectory} --exclude .git --exclude .github --exclude ${temporaryDeploymentDirectory}`, constants_1.workspace);
}
else {
yield io_1.cp(`${constants_1.action.build}/.`, temporaryDeploymentDirectory, {
recursive: true,
force: true
});
}
Allows the user to specify the root if '.' is provided.
rysync is used to prevent file duplication. */
yield util_1.execute(`rsync -q -av --progress ${constants_1.action.build}/. ${temporaryDeploymentDirectory} ${constants_1.action.clean ? `--delete --exclude CNAME --exclude .nojekyll` : ""} --exclude .git --exclude .github ${constants_1.action.build === constants_1.root ? `--exclude ${temporaryDeploymentDirectory}` : ""}`, constants_1.workspace);
const hasFilesToCommit = yield util_1.execute(`git status --porcelain`, temporaryDeploymentDirectory);
if (!hasFilesToCommit && !constants_1.isTest) {
console.log("There is nothing to commit. Exiting...");

View File

@ -34,8 +34,7 @@
"dependencies": {
"@actions/core": "^1.0.0",
"@actions/exec": "^1.0.1",
"@actions/github": "^1.1.0",
"@actions/io": "^1.0.1"
"@actions/github": "^1.1.0"
},
"devDependencies": {
"@types/jest": "^24.0.23",

View File

@ -19,6 +19,7 @@ export const action = {
accessToken: core.getInput("ACCESS_TOKEN"),
branch: core.getInput("BRANCH"),
baseBranch: core.getInput("BASE_BRANCH") || "master",
clean: core.getInput("CLEAN"),
pusher
};

View File

@ -1,5 +1,4 @@
import * as core from "@actions/core";
import { cp } from "@actions/io";
import { execute } from "./util";
import { workspace, action, root, repositoryPath, isTest } from "./constants";
@ -85,19 +84,18 @@ export async function deploy(): Promise<any> {
/*
Pushes all of the build files into the deployment directory.
Allows the user to specify the root if '.' is provided. */
if (action.build === root) {
// rsync is executed here so the .git and temporary deployment directories don't get duplicated.
Allows the user to specify the root if '.' is provided.
rysync is used to prevent file duplication. */
await execute(
`rsync -q -av --progress ${action.build}/. ${temporaryDeploymentDirectory} --exclude .git --exclude .github --exclude ${temporaryDeploymentDirectory}`,
`rsync -q -av --progress ${
action.build
}/. ${temporaryDeploymentDirectory} ${
action.clean ? `--delete --exclude CNAME --exclude .nojekyll` : ""
} --exclude .git --exclude .github ${
action.build === root ? `--exclude ${temporaryDeploymentDirectory}` : ""
}`,
workspace
);
} else {
await cp(`${action.build}/.`, temporaryDeploymentDirectory, {
recursive: true,
force: true
});
}
const hasFilesToCommit = await execute(
`git status --porcelain`,

View File

@ -17,10 +17,6 @@
"@octokit/graphql" "^2.0.1"
"@octokit/rest" "^16.15.0"
"@actions/io@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@actions/io/-/io-1.0.1.tgz#81a9418fe2bbdef2d2717a8e9f85188b9c565aca"
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.5.5":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.5.5.tgz#bc0782f6d69f7b7d49531219699b988f669a8f9d"