forked from chronicle/content-hub
-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (130 loc) · 5.09 KB
/
Copy pathgoogle_code_check.yml
File metadata and controls
143 lines (130 loc) · 5.09 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: Google Integration Code Checks
permissions:
contents: read
on:
push:
branches:
- '**'
paths:
- 'packages/**'
- 'content/response_integrations/google/**'
pull_request:
branches:
- '**'
paths:
- 'packages/**'
- 'content/response_integrations/google/**'
jobs:
changes:
name: Detect Changes
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
mp: ${{ steps.filter.outputs.mp }}
integration_packages: ${{ steps.filter.outputs.integration_packages }}
changed_integrations: ${{ steps.find_integrations.outputs.integrations }}
test_all: ${{ steps.find_integrations.outputs.test_all }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for changes
uses: dorny/paths-filter@v3
id: filter
with:
# language=yaml
filters: |
mp:
- 'packages/mp/**'
integration_packages:
- 'packages/envcommon/**'
- 'packages/tipcommon/**'
- 'packages/integration_testing/**'
- 'packages/integration_testing_whls/**'
response_integrations_google:
- 'content/response_integrations/google/**'
- name: Find changed integrations
id: find_integrations
env:
FILTER_MP: ${{ steps.filter.outputs.mp }}
FILTER_PACKAGES: ${{ steps.filter.outputs.integration_packages }}
FILTER_GOOGLE: ${{ steps.filter.outputs.response_integrations_google }}
BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.before }}
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
# language=bash
run: |
# If shared packages or mp changed, test everything
if [[ "$FILTER_MP" == "true" ]] || \
[[ "$FILTER_PACKAGES" == "true" ]]; then
echo "test_all=true" >> $GITHUB_OUTPUT
echo "integrations=" >> $GITHUB_OUTPUT
exit 0
fi
echo "test_all=false" >> $GITHUB_OUTPUT
# Get changed files directly from git to avoid environment variable limits
if [[ "$BASE_SHA" == "0000000000000000000000000000000000000000" ]] || [[ -z "$BASE_SHA" ]]; then
# New branch or push without base, compare against parent
git diff --name-only --diff-filter=d HEAD~1 HEAD > changed_files.txt
else
# Use three-dot diff for PRs to get changes relative to the merge base
# For pushes, it works as a standard two-dot diff if the range is valid
git diff --name-only --diff-filter=d "$BASE_SHA...$HEAD_SHA" > changed_files.txt || \
git diff --name-only --diff-filter=d "$BASE_SHA" "$HEAD_SHA" > changed_files.txt
fi
INTEGRATIONS=""
# Extract unique integration names from changed file paths (Google)
if [[ "$FILTER_GOOGLE" == "true" ]]; then
GOOGLE_INTS=$(grep "^content/response_integrations/google/" changed_files.txt | \
sed 's|content/response_integrations/google/||' | \
cut -d'/' -f1 | \
sort -u | \
tr '\n' ' ' | xargs)
INTEGRATIONS="$INTEGRATIONS $GOOGLE_INTS"
fi
echo "integrations=$(echo $INTEGRATIONS | xargs)" >> $GITHUB_OUTPUT
mp_check:
name: Code Linter
needs: changes
if: >-
needs.changes.outputs.test_all == 'true' ||
needs.changes.outputs.changed_integrations != ''
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install mp package
# language=bash
run: |
python -m pip install uv
uv pip install --system -e ./packages/mp
- name: Run mp check on Google integrations
env:
TEST_ALL: ${{ needs.changes.outputs.test_all }}
CHANGED_INTEGRATIONS: ${{ needs.changes.outputs.changed_integrations }}
# language=bash
run: |
mp config --root-path . --processes 10 --display-config
if [[ "$TEST_ALL" == "true" ]]; then
echo "Shared packages changed — checking all Google integrations"
mp check content/response_integrations/google --raise-error-on-violations --output-format grouped
else
echo "Checking only changed Google integrations: $CHANGED_INTEGRATIONS"
FAILED=0
for integration in $CHANGED_INTEGRATIONS; do
INT_PATH="content/response_integrations/google/$integration"
if [[ -d "$INT_PATH" ]]; then
echo "--- Checking: $integration ($INT_PATH) ---"
mp check "$INT_PATH" --raise-error-on-violations --output-format grouped || FAILED=1
else
echo "Warning: Could not find path for integration $integration"
fi
done
exit $FAILED
fi