Skip to content

Commit

Permalink
Merge pull request enriikke#55 from lukasbach/main
Browse files Browse the repository at this point in the history
Support for custom deploy user (enriikke#54)
  • Loading branch information
enriikke committed Apr 20, 2021
2 parents 0b651bb + aee3492 commit 380689c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,25 @@ configuration options:

- **skip-publish**: Builds your Gatsby site but skips publishing by setting it to `true`,
effectively performing a test of the build process using the live configuration.
Provided as an [input][github-action-input]
Provided as an [input][github-action-input].
Defaults to **false**

- **working-dir**: The directory where your Gatsby source files are at. `gatsby build`
will run from this directory.
Provided as an [input][github-action-input]
Provided as an [input][github-action-input].
Defaults to the project's root.

- **git-config-name**: Provide a custom name that is used to author the git commit, which
is pushed to the deploy branch.
Provided as an [input][github-action-input].
Defaults to the GitHub username of the action actor.

- **git-config-email**: Provide a custom email that is used to author the git commit, which
is pushed to the deploy branch.
Provided as an [input][github-action-input].
Defaults to `{actor}@users.noreply.github.com`, where `{actor}` is the GitHub username
of the action actor.

### Org or User Pages

Create a repository with the format `<YOUR/ORG USERNAME>.github.io`, push your
Expand Down
23 changes: 23 additions & 0 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ beforeAll(() => {
}
})

github.context.actor = 'enrikke'
github.context.ref = 'refs/heads/some-ref'
github.context.sha = '1234567890123456789012345678901234567890'

Expand Down Expand Up @@ -131,4 +132,26 @@ describe('Gatsby Publish action', () => {

expect(execSpy).toBeCalledWith('npm run build', [], {cwd: './__tests__'})
})

it('calls gatsby build with git name and email', async () => {
inputs['gatsby-args'] = ''
inputs['git-config-name'] = 'git-name'
inputs['git-config-email'] = 'git-email'
inputs['skip-publish'] = 'FALSE'

await run()

expect(execSpy).nthCalledWith(4, 'git config user.name', ['git-name'], {cwd: './public'})
expect(execSpy).nthCalledWith(5, 'git config user.email', ['git-email'], {cwd: './public'})
})

it('calls gatsby build without git name and email', async () => {
inputs['gatsby-args'] = ''
inputs['skip-publish'] = 'FALSE'

await run()

expect(execSpy).nthCalledWith(4, 'git config user.name', ['enrikke'], {cwd: './public'})
expect(execSpy).nthCalledWith(5, 'git config user.email', ['enrikke@users.noreply.github.com'], {cwd: './public'})
})
})
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ inputs:
description: "The directory where your Gatsby source files are at. `gatsby build` will run from this directory."
required: false
default: "."
commit-message:
description: "The commit message used for pushing changes to the deploy branch."
required: false
default: ""
git-config-name:
description: "The name under which the deploy commit is pushed to the deploy branch."
required: false
default: ""
git-config-email:
description: "The email adress under which the deploy commit is pushed to the deploy branch."
required: false
default: ""
runs:
using: "node12"
main: "./dist/index.js"
13 changes: 10 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,22 @@ async function run(): Promise<void> {
console.log('You can configure the deploy branch by setting the `deploy-branch` input for this action.')

await exec.exec(`git init`, [], {cwd: `${workingDir}/public`})
await exec.exec(`git config user.name`, [github.context.actor], {

const gitUserName = core.getInput('git-config-name') || github.context.actor
const gitEmail = core.getInput('git-config-email') || `${github.context.actor}@users.noreply.github.com`

await exec.exec(`git config user.name`, [gitUserName], {
cwd: `${workingDir}/public`,
})
await exec.exec(`git config user.email`, [`${github.context.actor}@users.noreply.github.com`], {
await exec.exec(`git config user.email`, [gitEmail], {
cwd: `${workingDir}/public`,
})

await exec.exec(`git add`, ['.'], {cwd: `${workingDir}/public`})
await exec.exec(`git commit`, ['-m', `deployed via Gatsby Publish Action 🎩 for ${github.context.sha}`], {

const commitMessageInput =
core.getInput('commit-message') || `deployed via Gatsby Publish Action 🎩 for ${github.context.sha}`
await exec.exec(`git commit`, ['-m', commitMessageInput], {
cwd: `${workingDir}/public`,
})

Expand Down

0 comments on commit 380689c

Please sign in to comment.