|
| 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. |
0 commit comments