Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ updates:
- "docker"
commit-message:
prefix: "chore"
include: "scope"
include: "scope"
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI

on:
push:
branches: [main, develop]
pull_request:
branches: [main]
workflow_dispatch:

jobs:
validate-action:
name: Validate GitHub Action
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Validate Action
uses: mpalmer/action-validator@v1.5.0
with:
path: action.yml

format-check:
name: Format Check (dprint)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup dprint
uses: dprint/check@v2.2

validate-shell:
name: Validate Shell Scripts
runs-on: ubuntu-latest
if: ${{ hashFiles('**/*.sh') != '' }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: ShellCheck
uses: ludeeus/action-shellcheck@master
with:
scandir: "."
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Test Send CDEvents Action

on:
push:
branches: [ main, develop ]
branches: [main, develop]
pull_request:
branches: [ main ]
branches: [main]
workflow_dispatch:

env:
Expand Down Expand Up @@ -124,7 +124,7 @@ jobs:
- name: Test with file input
uses: ./
with:
data: '@test-event.json'
data: "@test-event.json"

- name: Clean up
if: always()
Expand Down Expand Up @@ -186,7 +186,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
version: ['latest']
version: ["latest"]
steps:
- name: Checkout
uses: actions/checkout@v5
Expand All @@ -195,4 +195,4 @@ jobs:
uses: ./
with:
data: ${{ env.VALID_CDEVENT }}
version: ${{ matrix.version }}
version: ${{ matrix.version }}
21 changes: 21 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[tools]
dprint = "latest"
bun = "latest"

[tasks.format]
description = "Format code using dprint"
run = "dprint fmt"

[tasks.check]
description = "Check code formatting and run all validations (like CI)"
run = [
"echo '=== Checking code formatting with dprint ==='",
"dprint check",
"echo '=== Validating action.yml ==='",
"bunx @action-validator/core action.yml",
"echo '=== All checks completed ==='",
]

[tasks.ci]
description = "Run all CI checks locally"
alias = "check"
36 changes: 21 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,25 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Send CDEvent
uses: cdviz-dev/send-cdevents@v1
with:
data: '@.github/cdevents/build-started.json'
data: "@.github/cdevents/build-started.json"
url: "https://your-webhook-endpoint.com/cdevents"
```

## Inputs

| Input | Description | Required | Default |
|-------|-------------|----------|---------|
| `data` | JSON data to send. Can be direct JSON string, file path (@file.json), or stdin (@-) | Yes | - |
| `url` | HTTP URL to send the data to. When specified, automatically enables the HTTP sink | No | - |
| `config` | TOML configuration content for advanced sink settings | No | - |
| `directory` | Working directory for relative paths | No | - |
| `headers` | Additional HTTP headers for the request (one per line, format: "Header-Name: value") | No | - |
| `additional-args` | Additional arguments to pass to the cdviz-collector send command | No | - |
| `version` | Version/tag of the cdviz-collector container to use | No | `latest` |
| Input | Description | Required | Default |
| ----------------- | ------------------------------------------------------------------------------------ | -------- | -------- |
| `data` | JSON data to send. Can be direct JSON string, file path (@file.json), or stdin (@-) | Yes | - |
| `url` | HTTP URL to send the data to. When specified, automatically enables the HTTP sink | No | - |
| `config` | TOML configuration content for advanced sink settings | No | - |
| `directory` | Working directory for relative paths | No | - |
| `headers` | Additional HTTP headers for the request (one per line, format: "Header-Name: value") | No | - |
| `additional-args` | Additional arguments to pass to the cdviz-collector send command | No | - |
| `version` | Version/tag of the cdviz-collector container to use | No | `latest` |

## Environment Variables

Expand All @@ -139,28 +139,32 @@ The action automatically passes all environment variables starting with `CDVIZ_C
Environment variables should follow the pattern: `CDVIZ_COLLECTOR__<SECTION>__<SUBSECTION>__<KEY>`

Examples:

- `CDVIZ_COLLECTOR__SINKS__HTTP__HEADERS__X_API_KEY__VALUE` → `sinks.http.headers.x-api-key.value`
- `CDVIZ_COLLECTOR__SINKS__HTTP__HEADERS__X_SIGNATURE__TOKEN` → `sinks.http.headers.x-signature.token`
- `CDVIZ_COLLECTOR__SINKS__HTTP__DESTINATION` → `sinks.http.destination`

## Data Input Formats

### Direct JSON String

```yaml
with:
data: '{"type": "dev.cdevents.build.started.0.1.1", "source": "github-action"}'
```

### From File

```yaml
with:
data: '@path/to/event.json'
data: "@path/to/event.json"
```

### From Stdin (for piped data)

```yaml
with:
data: '@-'
data: "@-"
```

## Configuration Content Example
Expand All @@ -174,7 +178,7 @@ config: |
token = "${{ secrets.WEBHOOK_SECRET }}"
algorithm = "sha256"
prefix = "sha256="

[sinks.http.headers.x-custom-header]
type = "static"
value = "custom-value"
Expand All @@ -185,6 +189,7 @@ config: |
## Examples

### Build Event

```yaml
- name: Send Build Started Event
uses: cdviz-dev/send-cdevents@v1
Expand All @@ -207,6 +212,7 @@ config: |
```

### Test Event

```yaml
- name: Send Test Started Event
uses: cdviz-dev/send-cdevents@v1
Expand Down Expand Up @@ -237,4 +243,4 @@ config: |

## License

This project is licensed under the same license as the cdviz-collector project.
This project is licensed under the same license as the cdviz-collector project.
60 changes: 30 additions & 30 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,82 +1,82 @@
name: 'Send CDEvents'
description: 'Send CDEvents using cdviz-collector send subcommand'
author: 'cdviz-dev'
name: "Send CDEvents"
description: "Send CDEvents using cdviz-collector send subcommand"
author: "cdviz-dev"

branding:
icon: 'send'
color: 'blue'
icon: "send"
color: "blue"

inputs:
data:
description: 'JSON data to send to the sink. Can be direct JSON string, file path (@file.json), or stdin (@-)'
description: "JSON data to send to the sink. Can be direct JSON string, file path (@file.json), or stdin (@-)"
required: true
url:
description: 'HTTP URL to send the data to. When specified, automatically enables the HTTP sink'
description: "HTTP URL to send the data to. When specified, automatically enables the HTTP sink"
required: false
config:
description: 'TOML configuration content for advanced sink settings'
description: "TOML configuration content for advanced sink settings"
required: false
directory:
description: 'Working directory for relative paths'
description: "Working directory for relative paths"
required: false
headers:
description: 'Additional HTTP headers for the request (one per line, format: "Header-Name: value")'
required: false
additional-args:
description: 'Additional arguments to pass to the cdviz-collector send command'
description: "Additional arguments to pass to the cdviz-collector send command"
required: false
version:
description: 'Version/tag of the cdviz-collector container to use'
description: "Version/tag of the cdviz-collector container to use"
required: false
default: 'latest'
default: "latest"

runs:
using: 'composite'
using: "composite"
steps:
- name: 'Create secure config file'
- name: "Create secure config file"
shell: bash
if: ${{ inputs.config != '' }}
run: |
# Create config file with restrictive permissions
umask 077
# Create config file with readable permissions for container
cat > .cdviz-config-${{ github.run_id }}.toml << 'EOF'
${{ inputs.config }}
EOF

- name: 'Build command arguments'
# Set permissions to be readable by container (644)
chmod 644 .cdviz-config-${{ github.run_id }}.toml
- name: "Build command arguments"
shell: bash
id: args
run: |
ARGS="send --data '${{ inputs.data }}'"

if [ -n "${{ inputs.url }}" ]; then
ARGS="$ARGS --url '${{ inputs.url }}'"
fi

if [ -n "${{ inputs.config }}" ]; then
ARGS="$ARGS --config '.cdviz-config-${{ github.run_id }}.toml'"
fi

if [ -n "${{ inputs.directory }}" ]; then
ARGS="$ARGS --directory '${{ inputs.directory }}'"
fi

if [ -n "${{ inputs.headers }}" ]; then
while IFS= read -r header; do
if [ -n "$header" ]; then
ARGS="$ARGS --header '$header'"
fi
done <<< '${{ inputs.headers }}'
fi

if [ -n "${{ inputs.additional-args }}" ]; then
ARGS="$ARGS ${{ inputs.additional-args }}"
fi

echo "args=$ARGS" >> $GITHUB_OUTPUT
echo "Command to execute: cdviz-collector $ARGS"
- name: 'Run cdviz-collector'

- name: "Run cdviz-collector"
shell: bash
run: |
# Build environment variable arguments for CDVIZ_COLLECTOR__ prefixed variables
Expand All @@ -86,19 +86,19 @@ runs:
ENV_ARGS="$ENV_ARGS -e $name=$value"
fi
done < <(env)

docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
$ENV_ARGS \
ghcr.io/cdviz-dev/cdviz-collector:${{ inputs.version }} \
${{ steps.args.outputs.args }}
- name: 'Clean up config file'

- name: "Clean up config file"
shell: bash
if: ${{ always() && inputs.config != '' }}
run: |
if [ -f ".cdviz-config-${{ github.run_id }}.toml" ]; then
rm -f ".cdviz-config-${{ github.run_id }}.toml"
echo "Cleaned up temporary config file"
fi
fi
19 changes: 19 additions & 0 deletions dprint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"lineWidth": 120,
"indentWidth": 2,
"useTabs": false,
"newLineKind": "lf",
"includes": ["**/*.{yml,yaml,md,json}"],
"excludes": ["node_modules", ".git", "target", "dist"],
"plugins": [
"https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.1.wasm",
"https://plugins.dprint.dev/markdown-0.19.0.wasm",
"https://plugins.dprint.dev/json-0.20.0.wasm"
],
"markdown": {
"textWrap": "maintain"
},
"json": {
"indentWidth": 2
}
}
Loading