-
Notifications
You must be signed in to change notification settings - Fork 4
/
diff.yml
100 lines (94 loc) · 3.31 KB
/
diff.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: Detect Changes For PR
on:
pull_request:
branches: [ main ]
paths:
- 'schema/**'
workflow_dispatch:
permissions:
id-token: write
contents: read
pull-requests: write
packages: read
jobs:
get-changed-directories:
runs-on: ubuntu-latest
outputs:
any_changed: ${{ steps.get-changed-directories.outputs.any_changed }}
changed_directories: ${{ steps.set-matrix-changed-directories.outputs.changed_directories }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get changed directories
id: get-changed-directories
uses: tj-actions/changed-files@v35
with:
files: |
kusto/**/*.{yml,yaml,kql}
dir_names: 'true'
dir_names_max_depth: '3'
- name: Create matrix array of changed directories
if: steps.get-changed-directories.outputs.any_changed == 'true'
id: set-matrix-changed-directories
env:
ALL_CHANGED_FILES: ${{ steps.get-changed-directories.outputs.all_changed_files }}
run: |
echo "One or more configuration directories have changed."
echo "Changed configuration directories: ${{ steps.get-changed-directories.outputs.all_changed_files }}"
cdirs=$(echo $ALL_CHANGED_FILES | tr ' ' '\n' | sed 's/.*/"&"/' | paste -s -d ',' - | sed 's/.*/[&]/' | sed 's/,/, /g')
echo "changed_directories=${cdirs}" >> "$GITHUB_OUTPUT"
# This is the new job, only runs on changed directories.
validate-dynamic-workflows:
name: Diff
if: needs.get-changed-directories.outputs.any_changed == 'true'
runs-on: ubuntu-latest
needs: get-changed-directories
container:
image: ghcr.io/github/KustoSchemaToolsAction:main
credentials:
username: ${{ github.actor }}
password: ${{ secrets.github_token }}
strategy:
matrix:
directory: ${{ fromJSON(needs.get-changed-directories.outputs.changed_directories) }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: 'Azure OIDC Login'
uses: azure/login@v1
with:
client-id: ${{ vars.AZURE_CLIENT_ID_OIDC }}
tenant-id: ${{ vars.AZURE_TENANT_ID_OIDC }}
allow-no-subscriptions: true
- name: Set variables
shell: bash
run: |
IFS='/' read -ra DIR <<< ${{ matrix.directory }}
echo "CLUSTER=${DIR[1]}" >> $GITHUB_ENV
echo "DATABASE=${DIR[2]}" >> $GITHUB_ENV
- name: Diff database
uses: ./.github/actions/KustoSchemaTools
id: KustoSchemaTools
with:
mode: diff
path: kusto
cluster: ${{ env.CLUSTER }}
database: ${{ env.DATABASE }}
- name: Post proposed kusto script
if: always()
uses: actions/github-script@v6
env:
REQUEST_BODY: |
${{ steps.KustoSchemaTools.outputs.diff }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const requestBody = JSON.parse(process.env.REQUEST_BODY);
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: requestBody.markDown
})