Skip to content

Commit 4b2f84d

Browse files
authored
Version 3 (#44)
* Version 3 Beta * README Updates * More readme updates * lock * Restoring license/contrib * One set of tests * linting * More tests * Finish up unit tests * Update action.yml * Update main.yml * Update README.md * Update README.md * README Changes * Update README.md * Unit testing job * Some more stuff * More cleanup * Update README.md * Unrequired * Update CONTRIBUTING.md * no guess * Using Git Switch as opposed to checkout * Force Commit * Remove git * Some more simplification * Update git.ts * changes * Options * w * Debugging * More debugging * More debugging * Debugging * Debugging * Debugging * Debugging * Debugging * Debugging * Debugging * Debugging * Debugging * Debugging * Debugging * Debugging * Debugging * Debug * Debugging * Another 1 * Update git.ts * Fixes root deployment * Quiet Mode * Quiet * Excluding .github * Update README.md
1 parent ab80c09 commit 4b2f84d

26 files changed

+4151
-133
lines changed

.github/workflows/build.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: unit
2+
on:
3+
push:
4+
branches:
5+
- master
6+
jobs:
7+
unit-test:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@master
12+
13+
- name: Install and Test
14+
run: |
15+
npm install
16+
npm run-script test

.github/workflows/main.yml renamed to .github/workflows/integration.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ jobs:
1414
env:
1515
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
1616
BRANCH: gh-pages
17-
FOLDER: 'test/build'
18-
BUILD_SCRIPT: npm run-script integrationTest
17+
FOLDER: 'integration'

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
npm-debug.log*
66
yarn-debug.log*
77
yarn-error.log*
8-
test/build
8+
9+
node_modules

CONTRIBUTING.md

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
1-
# Contributing
1+
# Contributing
22

3-
When contributing to this repository, please first discuss the change you wish to make via issue,
4-
email, or any other method with the owners of this repository before making a change.
3+
When contributing to this repository, please first discuss the change you wish to make via issue,
4+
email, or any other method with the owners of this repository before making a change.
55

6-
## Pull Request Best Practices
6+
## Pull Request Best Practices
77

8-
1. Ensure that you've tested your feature/change yourself. As the primary focus of this project is deployment, providing a link to a deployed repository using your branch is preferred. You can reference the forked action using your GitHub username, for example `yourname/github-pages-deplpy-action@master`.
9-
2. Make sure you update the README if you've made a change that requires documentation.
8+
1. Ensure that you've tested your feature/change yourself. As the primary focus of this project is deployment, providing a link to a deployed repository using your branch is preferred. You can reference the forked action using your GitHub username, for example `yourname/github-pages-deplpy-action@master`.
9+
2. Make sure you update the README if you've made a change that requires documentation.
1010
3. When making a pull request, highlight any areas that may cause a breaking change so the maintainer can update the version number accordingly on the GitHub marketplace.
11+
12+
# Deploying
13+
14+
In order to deploy and test your own fork of this action, you must commit the required `node_modules` dependencies.
15+
16+
To do this you can follow the instructions below:
17+
18+
```
19+
# comment out in distribution branches
20+
# node_modules/
21+
```
22+
23+
```
24+
$ git checkout -b branchnamehere
25+
$ git commit -a -m "prod dependencies"
26+
```
27+
28+
The `node_modules` folder should _not_ be included when making a pull request.

Dockerfile

-13
This file was deleted.

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
SOFTWARE.

README.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# GitHub Pages Deploy Action :rocket:
22

3-
[![Actions Status](https://github.com/JamesIves/github-pages-deploy-action/workflows/integration/badge.svg)](https://github.com/JamesIves/github-pages-deploy-action/actions) [![View Action](https://img.shields.io/badge/view-action-blue.svg)](https://github.com/marketplace/actions/deploy-to-github-pages) [![Issues](https://img.shields.io/github/issues/JamesIves/github-pages-deploy-action.svg)](https://github.com/JamesIves/github-pages-deploy-action/issues)
3+
[![Build Status](https://github.com/JamesIves/github-pages-deploy-action/workflows/unit/badge.svg)](https://github.com/JamesIves/github-pages-deploy-action/actions) [![Actions Status](https://github.com/JamesIves/github-pages-deploy-action/workflows/integration/badge.svg)](https://github.com/JamesIves/github-pages-deploy-action/actions) [![View Action](https://img.shields.io/badge/view-action-blue.svg?logo=github&color=orange)](https://github.com/marketplace/actions/deploy-to-github-pages) [![Version](https://img.shields.io/github/v/release/JamesIves/github-pages-deploy-action.svg?logo=github)](hhttps://github.com/JamesIves/github-pages-deploy-action/releases)
44

5-
This [GitHub action](https://github.com/features/actions) will handle the building and deploy process of your project to [GitHub Pages](https://pages.github.com/). It can be configured to upload your production-ready code into any branch you'd like, including `gh-pages` and `docs`. This action is built on [Node](https://nodejs.org/en/), which means that you can call any optional build scripts your project requires prior to deploying.
5+
This [GitHub action](https://github.com/features/actions) will handle the deploy process of your project to [GitHub Pages](https://pages.github.com/). It can be configured to upload your production-ready code into any branch you'd like, including `gh-pages` and `docs`.
66

77
## Getting Started :airplane:
88
You can include the action in your workflow to trigger on any event that [GitHub actions supports](https://help.github.com/en/articles/events-that-trigger-workflows). If the remote branch that you wish to deploy to doesn't already exist the action will create it for you. Your workflow will also need to include the `actions/checkout` step before this workflow runs in order for the deployment to work.
@@ -20,13 +20,12 @@ jobs:
2020
uses: actions/checkout@v1
2121

2222
- name: Build and Deploy
23-
uses: JamesIves/github-pages-deploy-action@releases/v2
24-
env:
23+
uses: JamesIves/github-pages-deploy-action@releases/v3
24+
with:
2525
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
2626
BASE_BRANCH: master # The branch the action should deploy from.
2727
BRANCH: gh-pages # The branch the action should deploy to.
2828
FOLDER: build # The folder the action should deploy.
29-
BUILD_SCRIPT: npm install && npm run-script build # The build script the action should run prior to deploying.
3029
```
3130
3231
If you'd like to make it so the workflow only triggers on push events to specific branches then you can modify the `on` section. You'll still need to specify a `BASE_BRANCH` if you're deploying from a branch other than `master`.
@@ -40,20 +39,22 @@ on:
4039

4140
## Configuration 📁
4241

43-
The `env` portion of the workflow **must** be configured before the action will work. You can add these in the `env` 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).
42+
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).
4443

4544
Below you'll find a description of what each option does.
4645

4746
| Key | Value Information | Type | Required |
4847
| ------------- | ------------- | ------------- | ------------- |
4948
| `GITHUB_TOKEN` | In order for GitHub to trigger the rebuild of your page you must provide the action with the repositories provided GitHub token. This can be referenced in the workflow `yml` file by using `${{ secrets.GITHUB_TOKEN }}`. Only required if an access token is **not** provided. **Please note there is currently an issue affecting the use of this token, [you can learn more here](https://github.com/JamesIves/github-pages-deploy-action/issues/5)**. | `secrets` | **Yes** |
5049
| `ACCESS_TOKEN` | Depending on the repository permissions you may need to provide the action with a GitHub personal access token instead of the provided GitHub token in order to deploy. You can [learn more about how to generate one here](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line). **This should be stored as a secret**. | `secrets` | **No** |
51-
| `BRANCH` | This is the branch you wish to deploy to, for example `gh-pages` or `docs`. | `env` | **Yes** |
52-
| `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 `./`**. | `env` | **Yes** |
53-
| `BASE_BRANCH` | The base branch of your repository which you'd like to checkout prior to deploying. This defaults to `master`. | `env` | **No** |
54-
| `BUILD_SCRIPT` | If you require a build script to compile your code prior to pushing it you can add the script here. The Docker container which powers the action runs Node which means `npm` commands are valid. If you're using a static site generator such as Jekyll I'd suggest compiling the code prior to pushing it to your base branch. | `env` | **No** |
55-
| `CNAME` | If you're using a [custom domain](https://help.github.com/en/articles/using-a-custom-domain-with-github-pages), you will need to add the domain name to the `CNAME` environment variable. If you don't do this GitHub will wipe out your domain configuration after each deploy. This value will look something like this: `jives.dev`. | `env` | **No** |
50+
| `BRANCH` | This is the branch you wish to deploy to, for example `gh-pages` or `docs`. | `with` | **Yes** |
51+
| `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 `./`**. | `with` | **Yes** |
52+
| `BASE_BRANCH` | The base branch of your repository which you'd like to checkout prior to deploying. This defaults to `master`. | `with` | **No** |
5653

5754
With the action correctly configured you should see the workflow trigger the deployment under the configured conditions.
5855

56+
### Additional Build Files
57+
58+
This action maintains the full Git history of the deployment branch. Therefore if you're using a custom domain and require a `CNAME` file, or if you require the use of a `.nojekyll` file, you can safely commit these files directly into deployment branch without them being overridden after each deployment.
59+
5960
![Example](screenshot.png)

__tests__/git.test.ts

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
// Initial env variable setup for tests.
2+
process.env["INPUT_FOLDER"] = "build";
3+
4+
import { execute } from "../src/util";
5+
import { init, generateBranch, deploy } from "../src/git";
6+
import {action} from '../src/constants'
7+
import {cp} from '@actions/io';
8+
import _ from 'lodash';
9+
10+
const originalAction = _.cloneDeep(action);
11+
12+
jest.mock("../src/util", () => ({
13+
execute: jest.fn()
14+
}));
15+
16+
jest.mock("@actions/io", () => ({
17+
cp: jest.fn()
18+
}));
19+
20+
describe("git", () => {
21+
afterEach(() => {
22+
_.assignIn(action, originalAction);
23+
});
24+
25+
describe("init", () => {
26+
it("should execute three commands if a GitHub token is provided", async () => {
27+
28+
29+
Object.assign(action, {
30+
build: 'build',
31+
gitHubToken: '123',
32+
pusher: {
33+
name: 'asd',
34+
email: 'as@cat'
35+
}})
36+
37+
const call = await init();
38+
expect(execute).toBeCalledTimes(3);
39+
expect(call).toBe('Initialization step complete...')
40+
});
41+
42+
it("should execute three commands if a Access token is provided", async () => {
43+
44+
Object.assign(action, {
45+
build: 'build',
46+
accessToken: '123',
47+
pusher: {
48+
name: 'asd',
49+
email: 'as@cat'
50+
}})
51+
52+
const call = await init();
53+
54+
expect(execute).toBeCalledTimes(3);
55+
expect(call).toBe('Initialization step complete...')
56+
});
57+
58+
it("should fail if there is no provided GitHub Token or Access Token", async () => {
59+
Object.assign(action, {
60+
build: 'build',
61+
pusher: {
62+
name: 'asd',
63+
email: 'as@cat'
64+
}})
65+
66+
const call = await init()
67+
68+
expect(execute).toBeCalledTimes(0);
69+
expect(call).toBe('Initialization step complete...')
70+
})
71+
72+
it("should fail if the build folder begins with a /", async () => {
73+
Object.assign(action, {
74+
accessToken: '123',
75+
build: '/',
76+
pusher: {
77+
name: 'asd',
78+
email: 'as@cat'
79+
}})
80+
81+
const call = await init()
82+
83+
expect(execute).toBeCalledTimes(0);
84+
expect(call).toBe('Initialization step complete...')
85+
})
86+
87+
it("should fail if the build folder begins with a ./", async () => {
88+
Object.assign(action, {
89+
accessToken: '123',
90+
build: './',
91+
pusher: {
92+
name: 'asd',
93+
email: 'as@cat'
94+
}})
95+
96+
const call = await init()
97+
98+
expect(execute).toBeCalledTimes(0);
99+
expect(call).toBe('Initialization step complete...')
100+
})
101+
102+
it("should not fail if root is used", async () => {
103+
Object.assign(action, {
104+
accessToken: '123',
105+
build: '.',
106+
pusher: {
107+
name: 'asd',
108+
email: 'as@cat'
109+
}})
110+
111+
const call = await init()
112+
113+
expect(execute).toBeCalledTimes(3);
114+
expect(call).toBe('Initialization step complete...')
115+
})
116+
});
117+
118+
describe('generateBranch', () => {
119+
it('should execute five commands', async () => {
120+
const call = await generateBranch();
121+
expect(execute).toBeCalledTimes(6);
122+
expect(call).toBe('Deployment branch creation step complete...')
123+
})
124+
})
125+
126+
describe('deploy', () => {
127+
it('should execute five commands', async () => {
128+
Object.assign(action, {
129+
build: 'build',
130+
gitHubToken: '123',
131+
pusher: {
132+
name: 'asd',
133+
email: 'as@cat'
134+
}})
135+
136+
const call = await deploy();
137+
138+
// Includes the call to generateBranch
139+
expect(execute).toBeCalledTimes(14);
140+
expect(cp).toBeCalledTimes(1)
141+
expect(call).toBe('Commit step complete...')
142+
})
143+
144+
it('should execute six commands if root is used', async () => {
145+
Object.assign(action, {
146+
build: '.',
147+
gitHubToken: '123',
148+
pusher: {
149+
name: 'asd',
150+
email: 'as@cat'
151+
}})
152+
153+
const call = await deploy();
154+
155+
// Includes the call to generateBranch
156+
expect(execute).toBeCalledTimes(15);
157+
expect(cp).toBeCalledTimes(0)
158+
expect(call).toBe('Commit step complete...')
159+
})
160+
})
161+
});

__tests__/util.test.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {execute} from '../src/util';
2+
import {exec} from '@actions/exec';
3+
4+
jest.mock('@actions/exec', () => ({
5+
exec: jest.fn()
6+
}))
7+
8+
describe('util', () => {
9+
describe('execute', () => {
10+
it('should be called with the correct arguements', async() => {
11+
await execute('echo Montezuma', './')
12+
13+
expect(exec).toBeCalledWith(
14+
"echo Montezuma", [], {
15+
cwd: "./",
16+
listeners: {
17+
stdout: expect.any(Function)
18+
}
19+
}
20+
)
21+
});
22+
})
23+
})

action.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: 'Deploy to GitHub Pages'
2-
description: 'This action will handle the building and deploying process of your project to GitHub Pages.'
2+
description: 'This action will handle the deployment process of your project to GitHub Pages.'
33
author: 'James Ives <[email protected]>'
44
runs:
5-
using: 'docker'
6-
image: 'Dockerfile'
5+
using: 'node12'
6+
main: 'lib/main.js'
77
branding:
88
icon: 'git-commit'
99
color: 'orange'

0 commit comments

Comments
 (0)