Skip to content

Commit

Permalink
Merge pull request enriikke#45 from enriikke/working-dir-docs
Browse files Browse the repository at this point in the history
Add documentation for working-dir input
  • Loading branch information
enriikke committed Nov 14, 2020
2 parents 8524589 + 574393f commit bf3ba06
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: CI

on: [push, pull_request]
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ configuration options:
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]
Defaults to the project's root.

### Org or User Pages

Create a repository with the format `<YOUR/ORG USERNAME>.github.io`, push your
Expand Down Expand Up @@ -160,7 +165,7 @@ to work (as mentioned at the beginning). Ultimately, this is what calls `gatsby
Have fun building! ✨

[gatsby-build-docs]: https://www.gatsbyjs.org/docs/gatsby-cli/#build
[github-access-token]: https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line
[github-action-input]: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets#using-encrypted-secrets-in-a-workflow
[github-pages-domain-docs]: https://help.github.com/en/articles/using-a-custom-domain-with-github-pages
[github-repo-secret]: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets#creating-encrypted-secrets
[github-access-token]: https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token
[github-action-input]: https://docs.github.com/en/free-pro-team@latest/actions/creating-actions/metadata-syntax-for-github-actions#inputs
[github-pages-domain-docs]: https://docs.github.com/en/free-pro-team@latest/github/working-with-github-pages/configuring-a-custom-domain-for-your-github-pages-site
[github-repo-secret]: https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets#creating-encrypted-secrets
14 changes: 8 additions & 6 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,23 @@ describe('Gatsby Publish action', () => {

await run()

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

it('calls gatsby build without args', async () => {
inputs['gatsby-args'] = ''

await run()

expect(execSpy).toBeCalledWith('yarn run build', [], {"cwd": "."})
expect(execSpy).toBeCalledWith('yarn run build', [], {cwd: '.'})
})

it('calls gatsby build with args', async () => {
inputs['gatsby-args'] = '--prefix-paths --no-uglify'

await run()

expect(execSpy).toBeCalledWith('yarn run build', ['--', '--prefix-paths', '--no-uglify'], {"cwd": "."})
expect(execSpy).toBeCalledWith('yarn run build', ['--', '--prefix-paths', '--no-uglify'], {cwd: '.'})
})

it('calls gatsby build with working-dir', async () => {
Expand All @@ -109,7 +109,7 @@ describe('Gatsby Publish action', () => {

await run()

expect(execSpy).toBeCalledWith('yarn run build', [], {"cwd": "../gatsby-gh-pages-action"})
expect(execSpy).toBeCalledWith('yarn run build', [], {cwd: '../gatsby-gh-pages-action'})
})

it('calls gatsby build with working-dir and args', async () => {
Expand All @@ -118,7 +118,9 @@ describe('Gatsby Publish action', () => {

await run()

expect(execSpy).toBeCalledWith('yarn run build', ['--', '--prefix-paths', '--no-uglify'], {"cwd": "../gatsby-gh-pages-action"})
expect(execSpy).toBeCalledWith('yarn run build', ['--', '--prefix-paths', '--no-uglify'], {
cwd: '../gatsby-gh-pages-action',
})
})

it('calls gatsby build with wrong working-dir', async () => {
Expand All @@ -127,6 +129,6 @@ describe('Gatsby Publish action', () => {

await run()

expect(execSpy).toBeCalledWith('npm run build', [], {"cwd": "./__tests__"})
expect(execSpy).toBeCalledWith('npm run build', [], {cwd: './__tests__'})
})
})
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ inputs:
description: "Builds your Gatsby site but skips publishing by setting it to `true`. Helpful for testing/debugging Workflows."
required: false
default: false
working-dir:
description: "The directory where your Gatsby source files are at. `gatsby build` will run from this directory."
required: false
default: "."
runs:
using: "node12"
main: "./dist/index.js"
6 changes: 4 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function run(): Promise<void> {
return
}

const workingDir = core.getInput('working-dir') || "."
const workingDir = core.getInput('working-dir') || '.'
const pkgManager = (await ioUtil.exists(`${workingDir}/yarn.lock`)) ? 'yarn' : 'npm'
console.log(`Installing your site's dependencies using ${pkgManager}.`)
await exec.exec(`${pkgManager} install`, [], {cwd: workingDir})
Expand Down Expand Up @@ -67,7 +67,9 @@ async function run(): Promise<void> {
await exec.exec(`git config user.name`, [github.context.actor], {
cwd: `${workingDir}/public`,
})
await exec.exec(`git config user.email`, [`${github.context.actor}@users.noreply.github.com`], {cwd: `${workingDir}/public`})
await exec.exec(`git config user.email`, [`${github.context.actor}@users.noreply.github.com`], {
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}`], {
Expand Down

0 comments on commit bf3ba06

Please sign in to comment.