Skip to content

Commit 379ad2b

Browse files
committed
Add environment variable support and change fail_on_rejection default to true
- Add VERSIONER_API_KEY and VERSIONER_API_URL environment variable fallback support - Change fail_on_rejection default from false to true for safer deployment guardrails - Update README with environment variable usage example showing all 4 event types - Update action.yml and inputs.ts to reflect new defaults and env var support
1 parent 6197fce commit 379ad2b

3 files changed

Lines changed: 67 additions & 13 deletions

File tree

README.md

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,17 @@ Check the **Actions** tab to see your deployment tracked!
7777

7878
| Input | Required | Default | Description |
7979
|-------|----------|---------|-------------|
80-
| `api_url` || `https://api.versioner.io` | Versioner API endpoint (override for testing or self-hosted) |
81-
| `api_key` || - | Versioner API key (store in GitHub Secrets) |
80+
| `api_url` || `https://api.versioner.io` | Versioner API endpoint (can also use `VERSIONER_API_URL` env var) |
81+
| `api_key` |* | - | Versioner API key (can also use `VERSIONER_API_KEY` env var, store in GitHub Secrets) |
8282
| `product_name` || repo name | Name of the product/service (defaults to repository name) |
8383
| `version` || - | Version identifier (e.g., git SHA, semantic version, build number) |
8484
| `environment` || - | Target environment (required for deployment events, optional for build events) |
8585
| `event_type` || `deployment` | Event type: `build` or `deployment` |
8686
| `status` || `success` | Event status (`success`, `failure`, `in_progress`) |
8787
| `metadata` || `{}` | Additional JSON metadata to attach to the event |
88-
| `fail_on_rejection` || `false` | Fail the workflow if Versioner rejects the deployment (e.g., conflicts, no-deploy windows) |
88+
| `fail_on_rejection` || `true` | Fail the workflow if Versioner rejects the deployment (e.g., conflicts, no-deploy windows) |
89+
90+
\* Required unless provided via `VERSIONER_API_KEY` environment variable
8991

9092
## 📤 Outputs
9193

@@ -99,6 +101,53 @@ Check the **Actions** tab to see your deployment tracked!
99101

100102
## 🔧 Usage Examples
101103

104+
### Using Environment Variables (Recommended for Multiple Events)
105+
106+
Set `VERSIONER_API_KEY` once at the job or workflow level to avoid repeating it:
107+
108+
```yaml
109+
env:
110+
VERSIONER_API_KEY: ${{ secrets.VERSIONER_API_KEY }}
111+
112+
jobs:
113+
deploy:
114+
runs-on: ubuntu-latest
115+
steps:
116+
- name: Build start
117+
uses: versioner-io/versioner-github-action@v1
118+
with:
119+
version: ${{ github.sha }}
120+
event_type: build
121+
status: in_progress
122+
123+
- name: Build application
124+
run: npm run build
125+
126+
- name: Build complete
127+
uses: versioner-io/versioner-github-action@v1
128+
with:
129+
version: ${{ github.sha }}
130+
event_type: build
131+
status: success
132+
133+
- name: Deploy start
134+
uses: versioner-io/versioner-github-action@v1
135+
with:
136+
version: ${{ github.sha }}
137+
environment: production
138+
status: in_progress
139+
140+
- name: Deploy application
141+
run: ./deploy.sh production
142+
143+
- name: Deploy complete
144+
uses: versioner-io/versioner-github-action@v1
145+
with:
146+
version: ${{ github.sha }}
147+
environment: production
148+
status: success
149+
```
150+
102151
### Track a Build (No Deployment)
103152
104153
```yaml
@@ -107,8 +156,7 @@ Check the **Actions** tab to see your deployment tracked!
107156
with:
108157
api_key: ${{ secrets.VERSIONER_API_KEY }}
109158
version: ${{ github.sha }}
110-
event_type: build
111-
# No environment needed - just tracking the build!
159+
event_type: build # No environment needed - just tracking the build!
112160
```
113161
114162
### Track a Deployment

action.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ branding:
88

99
inputs:
1010
api_url:
11-
description: 'Versioner API endpoint URL (defaults to https://api.versioner.io)'
11+
description: 'Versioner API endpoint URL (can also use VERSIONER_API_URL env var, defaults to https://api.versioner.io)'
1212
required: false
13-
default: 'https://api.versioner.io'
13+
default: ''
1414
api_key:
15-
description: 'Versioner API key (store in GitHub Secrets)'
16-
required: true
15+
description: 'Versioner API key (can also use VERSIONER_API_KEY env var, store in GitHub Secrets)'
16+
required: false
17+
default: ''
1718
product_name:
1819
description: 'Name of the product/service (defaults to repository name if not provided)'
1920
required: false
@@ -40,7 +41,7 @@ inputs:
4041
fail_on_rejection:
4142
description: 'Fail the workflow if Versioner rejects the deployment (e.g., conflicts, no-deploy windows)'
4243
required: false
43-
default: 'false'
44+
default: 'true'
4445

4546
outputs:
4647
deployment_id:

src/inputs.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@ import { ActionInputs } from './types'
55
* Get and validate action inputs
66
*/
77
export function getInputs(): ActionInputs {
8-
const apiUrl = core.getInput('api_url', { required: true })
9-
const apiKey = core.getInput('api_key', { required: true })
8+
const apiUrl = core.getInput('api_url', { required: false }) || process.env.VERSIONER_API_URL || 'https://api.versioner.io'
9+
const apiKey = core.getInput('api_key', { required: false }) || process.env.VERSIONER_API_KEY || ''
1010
const productName = core.getInput('product_name', { required: false }) || ''
1111
const version = core.getInput('version', { required: true })
1212
const environment = core.getInput('environment', { required: false }) || ''
1313
const eventType = core.getInput('event_type', { required: false }) || 'deployment'
1414
const status = core.getInput('status', { required: false }) || 'success'
1515
const metadataInput = core.getInput('metadata', { required: false }) || '{}'
16-
const failOnRejectionInput = core.getInput('fail_on_rejection', { required: false }) || 'false'
16+
const failOnRejectionInput = core.getInput('fail_on_rejection', { required: false }) || 'true'
17+
18+
// Validate API key is provided
19+
if (!apiKey) {
20+
throw new Error(`api_key is required (provide via input or VERSIONER_API_KEY environment variable)`)
21+
}
1722

1823
// Validate API URL format
1924
if (!apiUrl.startsWith('http://') && !apiUrl.startsWith('https://')) {

0 commit comments

Comments
 (0)