-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathdatadog_service_catalog_warn_delete.yml
More file actions
40 lines (37 loc) · 1.66 KB
/
datadog_service_catalog_warn_delete.yml
File metadata and controls
40 lines (37 loc) · 1.66 KB
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
name: Warn PR if it deletes a DataDog Service Catalog File
on:
pull_request:
permissions:
contents: read
pull-requests: write
jobs:
warn_if_deleting:
name: 'Check and warn'
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
steps:
- name: 'Checkout repo'
uses: actions/checkout@v6
with:
fetch-depth: 0
- id: one
name: 'Check for deleted DataDog service files'
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") | [.] | map(select(length > 0)) | . != []')
echo "needs_comment=$out" >> $GITHUB_OUTPUT
- id: two
if: steps.one.outputs.needs_comment == 'true'
name: 'Comment on PR if deleting a DataDog Service file'
run: |
echo ${{steps.one.outputs.needs_comment}}
message="You are deleting a Datadog Service Definition file in this PR. If this change is merged to the main branch, that entry will be automatically deleted from the Datadog service catalog. Please ensure that this removal is intended."
posted_already=$(gh pr view ${{github.event.number}} -c --json comments | jq -r --arg message "$message" '.[] | map(.body==$message) | index(true) != null')
if [ $posted_already = "false" ]; then
echo "Warning PR of DataDog Service File Deletion"
gh pr comment ${{github.event.number}} --body "$message"
else
echo "PR has already been warned"
fi