diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f64521f2..ce561fc9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,14 +1,11 @@ name: unit-tests -on: - push: - branches: - - dev +on: [pull_request, push] jobs: unit-test: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@master + uses: actions/checkout@v1 - name: Install and Test run: | diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index fe80ff23..f6473b03 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -1,17 +1,18 @@ name: integration-tests on: schedule: - - cron: 0 2 * * 0-6 + - cron: 0 2 * * 0-6 jobs: integration-test: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@master + uses: actions/checkout@v1 - name: Build and Deploy - uses: JamesIves/github-pages-deploy-action@master - env: + uses: JamesIves/github-pages-deploy-action@releases/v3 + with: ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} BRANCH: gh-pages - FOLDER: 'integration' + FOLDER: integration + BASE_BRANCH: dev diff --git a/__tests__/env.js b/__tests__/env.js new file mode 100644 index 00000000..e79aacd9 --- /dev/null +++ b/__tests__/env.js @@ -0,0 +1 @@ +process.env.UNIT_TEST = true \ No newline at end of file diff --git a/__tests__/git.test.ts b/__tests__/git.test.ts index 2deb8c25..4b00a934 100644 --- a/__tests__/git.test.ts +++ b/__tests__/git.test.ts @@ -136,7 +136,7 @@ describe("git", () => { const call = await deploy(); // Includes the call to generateBranch - expect(execute).toBeCalledTimes(14); + expect(execute).toBeCalledTimes(15); expect(cp).toBeCalledTimes(1) expect(call).toBe('Commit step complete...') }) @@ -153,7 +153,7 @@ describe("git", () => { const call = await deploy(); // Includes the call to generateBranch - expect(execute).toBeCalledTimes(15); + expect(execute).toBeCalledTimes(16); expect(cp).toBeCalledTimes(0) expect(call).toBe('Commit step complete...') }) diff --git a/jest.config.js b/jest.config.js index 563d4ccb..6114ff66 100644 --- a/jest.config.js +++ b/jest.config.js @@ -7,5 +7,6 @@ module.exports = { transform: { '^.+\\.ts$': 'ts-jest' }, - verbose: true + verbose: true, + setupFiles: ["/__tests__/env.js"] } \ No newline at end of file diff --git a/lib/constants.js b/lib/constants.js index dbaa4339..76caa83a 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -13,6 +13,7 @@ const { pusher, repository } = github.context.payload; exports.workspace = process.env.GITHUB_WORKSPACE; exports.folder = core.getInput("FOLDER", { required: true }); exports.root = "."; +exports.isTest = process.env.UNIT_TEST; // Required action data. exports.action = { build: exports.folder, diff --git a/lib/git.js b/lib/git.js index 162f333f..faa894fd 100644 --- a/lib/git.js +++ b/lib/git.js @@ -103,8 +103,8 @@ function deploy() { }); } const hasFilesToCommit = yield util_1.execute(`git status --porcelain`, temporaryDeploymentDirectory); - if (!hasFilesToCommit) { - console.log('There is nothing to commit. Exiting...'); + if (!hasFilesToCommit && !constants_1.isTest) { + console.log("There is nothing to commit. Exiting..."); return Promise.resolve(); } // Commits to GitHub. diff --git a/src/constants.ts b/src/constants.ts index 12d9fe03..ef5cab82 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -6,6 +6,7 @@ const { pusher, repository } = github.context.payload; export const workspace: any = process.env.GITHUB_WORKSPACE; export const folder = core.getInput("FOLDER", { required: true }); export const root = "."; +export const isTest = process.env.UNIT_TEST; // Required action data. export const action = { diff --git a/src/git.ts b/src/git.ts index 66e1f79d..4d94d58f 100644 --- a/src/git.ts +++ b/src/git.ts @@ -1,7 +1,7 @@ import * as core from "@actions/core"; import { cp } from "@actions/io"; import { execute } from "./util"; -import { workspace, action, root, repositoryPath } from "./constants"; +import { workspace, action, root, repositoryPath, isTest } from "./constants"; /** Generates the branch if it doesn't exist on the remote. * @returns {Promise} @@ -104,7 +104,7 @@ export async function deploy(): Promise { temporaryDeploymentDirectory ); - if (!hasFilesToCommit) { + if (!hasFilesToCommit && !isTest) { console.log("There is nothing to commit. Exiting..."); return Promise.resolve(); }