Skip to content

Commit ab6c0e5

Browse files
committed
feat: initialize the action
- start the README - rapp the container version of `cdviz-collector` for a maximum of porta bility
1 parent a10655c commit ab6c0e5

File tree

2 files changed

+296
-0
lines changed

2 files changed

+296
-0
lines changed

README.md

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
# Send CDEvents GitHub Action
2+
3+
A GitHub Action that sends CDEvents using the `cdviz-collector send` subcommand.
4+
5+
## Usage
6+
7+
### Basic Example
8+
9+
```yaml
10+
name: Send CDEvent
11+
on:
12+
push:
13+
branches: [main]
14+
15+
jobs:
16+
send-event:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Send CDEvent
20+
uses: cdviz-dev/send-cdevents@v1
21+
with:
22+
data: '{"type": "dev.cdevents.build.started.0.1.1", "source": "github-action"}'
23+
url: "https://your-webhook-endpoint.com/cdevents"
24+
```
25+
26+
### Advanced Example with Headers
27+
28+
```yaml
29+
name: Send CDEvent with Authentication
30+
on:
31+
push:
32+
branches: [main]
33+
34+
jobs:
35+
send-event:
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Send CDEvent
39+
uses: cdviz-dev/send-cdevents@v1
40+
with:
41+
data: '{"type": "dev.cdevents.build.started.0.1.1", "source": "github-action"}'
42+
url: "https://your-webhook-endpoint.com/cdevents"
43+
headers: |
44+
Authorization: Bearer ${{ secrets.API_TOKEN }}
45+
X-Source: GitHub
46+
```
47+
48+
### Using Configuration Content
49+
50+
```yaml
51+
name: Send CDEvent with Config
52+
on:
53+
push:
54+
branches: [main]
55+
56+
jobs:
57+
send-event:
58+
runs-on: ubuntu-latest
59+
steps:
60+
- name: Send CDEvent with HMAC signature
61+
uses: cdviz-dev/send-cdevents@v1
62+
with:
63+
data: '{"type": "dev.cdevents.build.started.0.1.1", "source": "github-action"}'
64+
url: "https://your-webhook-endpoint.com/cdevents"
65+
config: |
66+
[sinks.http.headers.x-signature-256]
67+
type = "signature"
68+
token = "${{ secrets.WEBHOOK_SECRET }}"
69+
algorithm = "sha256"
70+
prefix = "sha256="
71+
```
72+
73+
### Reading from File
74+
75+
```yaml
76+
name: Send CDEvent from File
77+
on:
78+
push:
79+
branches: [main]
80+
81+
jobs:
82+
send-event:
83+
runs-on: ubuntu-latest
84+
steps:
85+
- name: Checkout
86+
uses: actions/checkout@v4
87+
88+
- name: Send CDEvent
89+
uses: cdviz-dev/send-cdevents@v1
90+
with:
91+
data: '@.github/cdevents/build-started.json'
92+
url: "https://your-webhook-endpoint.com/cdevents"
93+
```
94+
95+
## Inputs
96+
97+
| Input | Description | Required | Default |
98+
|-------|-------------|----------|---------|
99+
| `data` | JSON data to send. Can be direct JSON string, file path (@file.json), or stdin (@-) | Yes | - |
100+
| `url` | HTTP URL to send the data to. When specified, automatically enables the HTTP sink | No | - |
101+
| `config` | TOML configuration content for advanced sink settings | No | - |
102+
| `directory` | Working directory for relative paths | No | - |
103+
| `headers` | Additional HTTP headers for the request (one per line, format: "Header-Name: value") | No | - |
104+
| `additional-args` | Additional arguments to pass to the cdviz-collector send command | No | - |
105+
| `version` | Version/tag of the cdviz-collector container to use | No | `latest` |
106+
107+
## Data Input Formats
108+
109+
### Direct JSON String
110+
```yaml
111+
with:
112+
data: '{"type": "dev.cdevents.build.started.0.1.1", "source": "github-action"}'
113+
```
114+
115+
### From File
116+
```yaml
117+
with:
118+
data: '@path/to/event.json'
119+
```
120+
121+
### From Stdin (for piped data)
122+
```yaml
123+
with:
124+
data: '@-'
125+
```
126+
127+
## Configuration Content Example
128+
129+
You can provide TOML configuration content directly in the action:
130+
131+
```yaml
132+
config: |
133+
[sinks.http.headers.x-signature-256]
134+
type = "signature"
135+
token = "${{ secrets.WEBHOOK_SECRET }}"
136+
algorithm = "sha256"
137+
prefix = "sha256="
138+
139+
[sinks.http.headers.x-custom-header]
140+
type = "static"
141+
value = "custom-value"
142+
```
143+
144+
> **⚠️ Security Note**: Always use GitHub secrets (`${{ secrets.SECRET_NAME }}`) for sensitive information like API keys, tokens, and webhook secrets. Never hardcode sensitive values directly in your workflow files. The action creates a temporary config file with restrictive permissions in the workspace and automatically cleans it up after execution, even if the action fails.
145+
146+
## Examples
147+
148+
### Build Event
149+
```yaml
150+
- name: Send Build Started Event
151+
uses: cdviz-dev/send-cdevents@v1
152+
with:
153+
data: |
154+
{
155+
"context": {
156+
"version": "0.3.0",
157+
"id": "build-${{ github.run_id }}",
158+
"source": "github-actions",
159+
"type": "dev.cdevents.build.started.0.1.1",
160+
"timestamp": "${{ steps.timestamp.outputs.timestamp }}"
161+
},
162+
"subject": {
163+
"id": "${{ github.repository }}",
164+
"source": "${{ github.server_url }}/${{ github.repository }}"
165+
}
166+
}
167+
url: ${{ secrets.CDEVENTS_WEBHOOK_URL }}
168+
```
169+
170+
### Test Event
171+
```yaml
172+
- name: Send Test Started Event
173+
uses: cdviz-dev/send-cdevents@v1
174+
with:
175+
data: |
176+
{
177+
"context": {
178+
"version": "0.3.0",
179+
"id": "test-${{ github.run_id }}",
180+
"source": "github-actions",
181+
"type": "dev.cdevents.test.started.0.1.0",
182+
"timestamp": "${{ steps.timestamp.outputs.timestamp }}"
183+
},
184+
"subject": {
185+
"id": "${{ github.repository }}",
186+
"source": "${{ github.server_url }}/${{ github.repository }}",
187+
"testCase": {
188+
"id": "${{ matrix.test-suite }}",
189+
"name": "${{ matrix.test-suite }}"
190+
}
191+
}
192+
}
193+
url: ${{ secrets.CDEVENTS_WEBHOOK_URL }}
194+
headers: |
195+
Authorization: Bearer ${{ secrets.API_TOKEN }}
196+
X-GitHub-Run-ID: ${{ github.run_id }}
197+
```
198+
199+
## License
200+
201+
This project is licensed under the same license as the cdviz-collector project.

action.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: 'Send CDEvents'
2+
description: 'Send CDEvents using cdviz-collector send subcommand'
3+
author: 'cdviz-dev'
4+
5+
branding:
6+
icon: 'send'
7+
color: 'blue'
8+
9+
inputs:
10+
data:
11+
description: 'JSON data to send to the sink. Can be direct JSON string, file path (@file.json), or stdin (@-)'
12+
required: true
13+
url:
14+
description: 'HTTP URL to send the data to. When specified, automatically enables the HTTP sink'
15+
required: false
16+
config:
17+
description: 'TOML configuration content for advanced sink settings'
18+
required: false
19+
directory:
20+
description: 'Working directory for relative paths'
21+
required: false
22+
headers:
23+
description: 'Additional HTTP headers for the request (one per line, format: "Header-Name: value")'
24+
required: false
25+
additional-args:
26+
description: 'Additional arguments to pass to the cdviz-collector send command'
27+
required: false
28+
version:
29+
description: 'Version/tag of the cdviz-collector container to use'
30+
required: false
31+
default: 'latest'
32+
33+
runs:
34+
using: 'composite'
35+
steps:
36+
- name: 'Create secure config file'
37+
shell: bash
38+
if: ${{ inputs.config != '' }}
39+
run: |
40+
# Create config file with restrictive permissions
41+
umask 077
42+
cat > .cdviz-config-${{ github.run_id }}.toml << 'EOF'
43+
${{ inputs.config }}
44+
EOF
45+
46+
- name: 'Build command arguments'
47+
shell: bash
48+
id: args
49+
run: |
50+
ARGS="send --data '${{ inputs.data }}'"
51+
52+
if [ -n "${{ inputs.url }}" ]; then
53+
ARGS="$ARGS --url '${{ inputs.url }}'"
54+
fi
55+
56+
if [ -n "${{ inputs.config }}" ]; then
57+
ARGS="$ARGS --config '.cdviz-config-${{ github.run_id }}.toml'"
58+
fi
59+
60+
if [ -n "${{ inputs.directory }}" ]; then
61+
ARGS="$ARGS --directory '${{ inputs.directory }}'"
62+
fi
63+
64+
if [ -n "${{ inputs.headers }}" ]; then
65+
while IFS= read -r header; do
66+
if [ -n "$header" ]; then
67+
ARGS="$ARGS --header '$header'"
68+
fi
69+
done <<< '${{ inputs.headers }}'
70+
fi
71+
72+
if [ -n "${{ inputs.additional-args }}" ]; then
73+
ARGS="$ARGS ${{ inputs.additional-args }}"
74+
fi
75+
76+
echo "args=$ARGS" >> $GITHUB_OUTPUT
77+
echo "Command to execute: cdviz-collector $ARGS"
78+
79+
- name: 'Run cdviz-collector'
80+
shell: bash
81+
run: |
82+
docker run --rm \
83+
-v "$PWD:/workspace" \
84+
-w /workspace \
85+
ghcr.io/cdviz-dev/cdviz-collector:${{ inputs.version }} \
86+
${{ steps.args.outputs.args }}
87+
88+
- name: 'Clean up config file'
89+
shell: bash
90+
if: ${{ always() && inputs.config != '' }}
91+
run: |
92+
if [ -f ".cdviz-config-${{ github.run_id }}.toml" ]; then
93+
rm -f ".cdviz-config-${{ github.run_id }}.toml"
94+
echo "Cleaned up temporary config file"
95+
fi

0 commit comments

Comments
 (0)