Skip to content

Commit

Permalink
✨ Add option to change the working directory
Browse files Browse the repository at this point in the history
  • Loading branch information
BetaHuhn committed May 5, 2022
1 parent 8c616da commit 0f891b8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Here are all the inputs [deploy-to-vercel-action](https://github.com/BetaHuhn/de
| `PR_PREVIEW_DOMAIN` | Custom preview domain for PRs (more info [below](#custom-domains)) | **No** | N/A |
| `VERCEL_SCOPE` | Execute commands from a different Vercel team or user | **No** | N/A |
| `BUILD_ENV` | Provide environment variables to the build step | **No** | N/A |
| `WORKING_DIRECTORY` | Working directory for the Vercel CLI | **No** | N/A |

## 🛠️ Configuration

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ inputs:
description: |
Provide environment variables to the build step.
required: false
WORKING_DIRECTORY:
description: |
Working directory for the Vercel CLI
required: false

outputs:
PREVIEW_URL:
Expand Down
3 changes: 3 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ const context = {
type: 'boolean',
default: false
}),
WORKING_DIRECTORY: parser.getInput({
key: 'WORKING_DIRECTORY'
}),
BUILD_ENV: parser.getInput({
key: 'BUILD_ENV',
type: 'array'
Expand Down
6 changes: 3 additions & 3 deletions src/helpers.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const core = require('@actions/core')
const { spawn } = require('child_process')

const execCmd = (command, args) => {
core.debug(`EXEC: "${ command } ${ args }"`)
const execCmd = (command, args, cwd) => {
core.debug(`EXEC: "${ command } ${ args }" in ${ cwd || '.' }`)
return new Promise((resolve, reject) => {
const process = spawn(command, args)
const process = spawn(command, args, { cwd })
let stdout
let stderr

Expand Down
7 changes: 4 additions & 3 deletions src/vercel.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const {
REPOSITORY,
REF,
TRIM_COMMIT_MESSAGE,
BUILD_ENV
BUILD_ENV,
WORKING_DIRECTORY
} = require('./config')

const init = () => {
Expand Down Expand Up @@ -60,7 +61,7 @@ const init = () => {
}

core.info('Starting deploy with Vercel CLI')
const output = await exec('vercel', commandArguments)
const output = await exec('vercel', commandArguments, WORKING_DIRECTORY)
const parsed = output.match(/(?<=https?:\/\/)(.*)/g)[0]

if (!parsed) throw new Error('Could not parse deploymentUrl')
Expand All @@ -77,7 +78,7 @@ const init = () => {
commandArguments.push(`--scope=${ VERCEL_SCOPE }`)
}

const output = await exec('vercel', commandArguments)
const output = await exec('vercel', commandArguments, WORKING_DIRECTORY)

return output
}
Expand Down

0 comments on commit 0f891b8

Please sign in to comment.