Skip to content

Commit 0633374

Browse files
committed
feat: added support for environment variable injection
Here's what I implemented: Key Features: 1. Automatic env var passing: The action scans all environment variables and passes any that start with CDVIZ_COLLECTOR__ to the container 2. No additional inputs needed: Uses GitHub Actions' native env support 3. Secure secret injection: Allows injecting secrets via environment variables without exposing them in config files Usage patterns: - Step-level env vars: Set environment variables for specific action steps - Job-level env vars: Set environment variables for entire job - Workflow-level env vars: Set environment variables for entire workflow - Repository secrets: Use ${{ secrets.SECRET_NAME }} in environment variables Security benefits: - ✅ Secrets never appear in config files - ✅ Secrets never appear in logs (GitHub automatically masks them) - ✅ Environment variables are only passed to the container, not stored on disk - ✅ Follows cdviz-collector's own environment variable convention This provides a much more secure way to handle sensitive configuration values like API keys, tokens, and webhook secrets compared to putting them in configuration files.
1 parent ab6c0e5 commit 0633374

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,32 @@ jobs:
7070
prefix = "sha256="
7171
```
7272
73+
### Using Environment Variables for Secrets
74+
75+
```yaml
76+
name: Send CDEvent with Environment Variables
77+
on:
78+
push:
79+
branches: [main]
80+
81+
jobs:
82+
send-event:
83+
runs-on: ubuntu-latest
84+
steps:
85+
- name: Send CDEvent with env vars
86+
uses: cdviz-dev/send-cdevents@v1
87+
env:
88+
CDVIZ_COLLECTOR__SINKS__HTTP__HEADERS__X_SIGNATURE_256__TOKEN: ${{ secrets.WEBHOOK_SECRET }}
89+
with:
90+
data: '{"type": "dev.cdevents.build.started.0.1.1", "source": "github-action"}'
91+
url: "https://your-webhook-endpoint.com/cdevents"
92+
config: |
93+
[sinks.http.headers.x-signature-256]
94+
type = "signature"
95+
algorithm = "sha256"
96+
prefix = "sha256="
97+
```
98+
7399
### Reading from File
74100
75101
```yaml
@@ -104,6 +130,19 @@ jobs:
104130
| `additional-args` | Additional arguments to pass to the cdviz-collector send command | No | - |
105131
| `version` | Version/tag of the cdviz-collector container to use | No | `latest` |
106132

133+
## Environment Variables
134+
135+
The action automatically passes all environment variables starting with `CDVIZ_COLLECTOR__` to the cdviz-collector container. This allows you to override configuration values securely using GitHub secrets without exposing them in config files.
136+
137+
### Environment Variable Naming Convention
138+
139+
Environment variables should follow the pattern: `CDVIZ_COLLECTOR__<SECTION>__<SUBSECTION>__<KEY>`
140+
141+
Examples:
142+
- `CDVIZ_COLLECTOR__SINKS__HTTP__HEADERS__X_API_KEY__VALUE` → `sinks.http.headers.x-api-key.value`
143+
- `CDVIZ_COLLECTOR__SINKS__HTTP__HEADERS__X_SIGNATURE__TOKEN` → `sinks.http.headers.x-signature.token`
144+
- `CDVIZ_COLLECTOR__SINKS__HTTP__DESTINATION` → `sinks.http.destination`
145+
107146
## Data Input Formats
108147

109148
### Direct JSON String

action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,18 @@ runs:
7979
- name: 'Run cdviz-collector'
8080
shell: bash
8181
run: |
82+
# Build environment variable arguments for CDVIZ_COLLECTOR__ prefixed variables
83+
ENV_ARGS=""
84+
while IFS='=' read -r name value; do
85+
if [[ "$name" == CDVIZ_COLLECTOR__* ]]; then
86+
ENV_ARGS="$ENV_ARGS -e $name=$value"
87+
fi
88+
done < <(env)
89+
8290
docker run --rm \
8391
-v "$PWD:/workspace" \
8492
-w /workspace \
93+
$ENV_ARGS \
8594
ghcr.io/cdviz-dev/cdviz-collector:${{ inputs.version }} \
8695
${{ steps.args.outputs.args }}
8796

0 commit comments

Comments
 (0)