Skip to content

Commit

Permalink
✨ Add input to pass environment variables to the build (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
armandabric authored Mar 25, 2022
1 parent 0882965 commit 78ce3cf
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Here are all the inputs [deploy-to-vercel-action](https://github.com/BetaHuhn/de
| `ALIAS_DOMAINS` | Alias domain(s) to assign to the deployment (more info [below](#custom-domains)) | **No** | N/A |
| `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 |

## 🛠️ Configuration

Expand Down Expand Up @@ -478,6 +479,38 @@ jobs:
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
```

### Pass environment variables to the build

You can define the build environment variables when using the action:

**.github/workflows/deploy.yml**

```yml
name: Deploy CI
on:
push:
branches: [master]
pull_request:
types: [opened, synchronize, reopened]
jobs:
deploy:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Deploy to Vercel Action
uses: BetaHuhn/deploy-to-vercel-action@v1
with:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
BUILD_ENV: |
FOO="bar"
SOME_TOKEN="${{ secrets.SOME_TOKEN }}"
```

If you have an idea for another use case, [create a discussion](https://github.com/BetaHuhn/deploy-to-vercel-action/discussions/new?category=show-and-tell) and maybe I will add it here!

## 💻 Development
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ inputs:
description: |
When passing meta data to Vercel deployment, trim the commit message to subject only (default: false).
required: false
BUILD_ENV:
description: |
Provide environment variables to the build step.
required: false

outputs:
PREVIEW_URL:
Expand Down
4 changes: 4 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ const context = {
type: 'boolean',
default: false
}),
BUILD_ENV: parser.getInput({
key: 'BUILD_ENV',
type: 'array'
}),
RUNNING_LOCAL: process.env.RUNNING_LOCAL === 'true'
}

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

const init = () => {
Expand Down Expand Up @@ -52,6 +53,11 @@ const init = () => {
})
}

if (BUILD_ENV) {
BUILD_ENV.forEach((item) => {
commandArguments = commandArguments.concat([ '--build-env', item ])
})
}

core.info('Starting deploy with Vercel CLI')
const output = await exec('vercel', commandArguments)
Expand Down

0 comments on commit 78ce3cf

Please sign in to comment.