-
Notifications
You must be signed in to change notification settings - Fork 66
53 lines (51 loc) · 1.71 KB
/
datadog_service_catalog_update.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
name: 'Update DataDog Service Catalog'
on:
pull_request:
types:
- merged
branches:
- master
paths:
- "datadog-service-catalog/**.yml"
jobs:
get_files:
name: 'Get all modified and added files'
runs-on: ubuntu-latest
outputs:
files: ${{steps.one.outputs.files}}
steps:
- name: 'Checkout repo'
uses: actions/checkout@v4
with:
fetch-depth: 0
- id: one
name: 'Git diff for changes and output matrix of file names'
run: |
git fetch origin master
arr=$(jq -ncR '[inputs]' <<< $(git diff --diff-filter=d --name-only origin/master... -- "datadog-service-catalog/**.yml"))
out=$(echo $arr | jq '.[] | select(. !="datadog-service-catalog/datadog-service-catalog.yml")| [.]')
echo ::set-output name=files::$out
update_dd:
name: 'Update DD with changes'
runs-on: ubuntu-latest
needs:
- get_files
strategy:
matrix:
file: ${{fromJSON(needs.get_files.outputs.files)}}
steps:
- name: 'Checkout repo'
uses: actions/checkout@v4
- id: read_yaml
name: 'Read in the Service Catalog data'
uses: mikefarah/yq@master
with:
cmd: yq '.' ${{matrix.file}}
- name: 'Update Service Catalog in DataDog'
run: |
curl --location --request POST 'https://api.ddog-gov.com/api/v2/services/definitions?schema_version=v2.2' \
--header 'Accept: application/json' \
--header 'DD-API-KEY: ${{ secrets.DD_API_KEY }}' \
--header 'DD-APPLICATION-KEY: ${{ secrets.DD_APP_KEY }}' \
--header 'Content-Type: text/plain' \
--data "${{ steps.read_yaml.outputs.result}}"