-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
73 lines (68 loc) · 2.87 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: 'Write to Google BigQuery'
author: 'Staffbase GmbH'
description: |-
Writes data to Google BigQuery from within a GitHub workflow.
It authenticates with a Google Cloud Service Account.
inputs:
credentials_json:
description: |-
The credentials key for the Service Account user used for authentication in JSON format.
This is forwarded to the google-github-actions/auth@v2 action.
required: true
token_lifetime:
description: |-
The lifetime of the generated auth token in seconds. The default is 30s.
This is forwarded to the google-github-actions/auth@v2 action.
required: false
default: 30s
bigquery_project:
description: 'The Project ID of the project to write to.'
required: true
bigquery_dataset:
description: 'The Dataset ID inside the project to write to.'
required: true
bigquery_table:
description: 'The Table ID inside the dataset to write to.'
required: true
payload_json:
description: |-
The payload to be written into the referenced table in JSON format. It must reflect the schema of the table.
required: true
timestamp_property_to_add:
descritpion: |-
If you want to add a timestamp property to the `payload_json` you can provide the name of the property with this input.
The schema of the `bigquery_table` must have a column of type `TIMESTAMP` and the name of this provided value.
The default is the empty string `''`. In this case the `payload_json` is not modified.
When it's not empty the according timestamp property is added to the `payload_json`.
This input is useful when the `payload_json` doesn't contain a timestamp property but you need one.
required: false
default: ''
runs:
using: "composite"
steps:
- id: auth
name: Authenticate to Google Cloud
uses: 'google-github-actions/auth@v2'
with:
credentials_json: "${{ inputs.credentials_json }}"
token_format: 'access_token'
access_token_scopes: 'https://www.googleapis.com/auth/bigquery.insertdata'
access_token_lifetime: "${{ inputs.token_lifetime }}"
- id: process
name: Process payload
shell: bash
run: ${{github.action_path}}/scripts/process-data.sh '${{ inputs.payload_json }}' ${{ inputs.timestamp_property_to_add }}
- id: write
name: Write to BigQuery
shell: bash
run: |
curl --request POST \
'https://bigquery.googleapis.com/bigquery/v2/projects/${{ inputs.bigquery_project }}/datasets/${{ inputs.bigquery_dataset }}/tables/${{ inputs.bigquery_table }}/insertAll' \
--header 'Authorization: Bearer ${{ steps.auth.outputs.access_token }}' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"rows":[{"json": ${{env.payload_json}} }]}' \
--compressed
branding:
icon: 'bar-chart'
color: 'blue'