-
Notifications
You must be signed in to change notification settings - Fork 124
131 lines (127 loc) · 5.03 KB
/
Copy pathlint-yaml.yml
File metadata and controls
131 lines (127 loc) · 5.03 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
name: Lint YAML
on:
push:
branches:
- main
paths:
- "data/**"
- "settings.yml"
- ".yamllint"
- "uv.lock"
- "pyproject.toml"
- ".github/workflows/lint-yaml.yml"
- ".github/scripts/check_duplicate_people.py"
- ".github/scripts/check_role_dates.py"
pull_request:
branches:
- main
paths:
- "data/**"
- "settings.yml"
- ".yamllint"
- "uv.lock"
- "pyproject.toml"
- ".github/workflows/lint-yaml.yml"
- ".github/scripts/check_duplicate_people.py"
- ".github/scripts/check_role_dates.py"
jobs:
lint:
runs-on: ubuntu-24.04
steps:
# Python & dependency installation
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
id: changed-dirs
with:
files: data/**
dir_names: 'true'
- uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
id: changed-files
- name: install uv
uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
with:
enable-cache: true
- name: Yaml file linting
run: uvx yamllint==1.38.0 -s .
- name: install dependencies
run: uv sync
- name: lint people selectively
env:
ALL_CHANGED_DIRS: ${{ steps.changed-dirs.outputs.all_changed_files }}
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
OS_PEOPLE_DIRECTORY: ${{ env.GITHUB_WORKSPACE }}
run: |
# settings.yml holds vacancies used to compute every jurisdiction's
# expected district counts (see Validator/get_expected_districts in
# openstates.utils.people.lint_people). It isn't under data/, so it
# never matches the per-dir regex below - a bad vacancy entry there
# can hide a real missing/extra-legislator error for a jurisdiction
# whose own files didn't change. Lint everything when it changes.
if [[ " ${ALL_CHANGED_FILES} " == *" settings.yml "* ]]; then
echo "settings.yml changed: linting all jurisdictions"
uv run os-people lint
else
abbrs=()
for dir in ${ALL_CHANGED_DIRS}; do
if [[ "$dir" =~ ^data/([a-z]{2})/(legislature|retired|executive|municipalities) ]]; then
abbrs+=("${BASH_REMATCH[1]}")
fi
done
if [[ ${#abbrs[@]} -gt 0 ]]; then
mapfile -t abbrs < <(printf '%s\n' "${abbrs[@]}" | sort -u)
uv run os-people lint "${abbrs[@]}"
fi
fi
- name: resolve base revision
id: base
env:
BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.before }}
run: |
# The two checks below report only what this change introduced. Both
# describe a bot mistake being made, so a long-standing one in a file
# the change merely reformats is not this author's to fix - see
# check_role_dates.py's module docstring. Without a usable base they
# report everything, which is noisy but never misses a real problem.
empty_sha=0000000000000000000000000000000000000000
if [[ -n "${BASE_SHA}" && "${BASE_SHA}" != "${empty_sha}" ]]; then
# actions/checkout clones at depth 1, so the base commit is usually
# absent locally; fetch just that one commit.
git cat-file -e "${BASE_SHA}^{commit}" 2>/dev/null \
|| git fetch --no-tags --depth=1 origin "${BASE_SHA}" \
|| true
if git cat-file -e "${BASE_SHA}^{commit}" 2>/dev/null; then
echo "base-args=--base-ref ${BASE_SHA}" >> "${GITHUB_OUTPUT}"
exit 0
fi
echo "base ${BASE_SHA} unavailable: reporting all findings"
fi
echo "base-args=" >> "${GITHUB_OUTPUT}"
- name: check duplicate people selectively
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
BASE_ARGS: ${{ steps.base.outputs.base-args }}
run: |
uv run python .github/scripts/check_duplicate_people.py \
--changed-files ${ALL_CHANGED_FILES} ${BASE_ARGS}
- name: check role date integrity selectively
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
BASE_ARGS: ${{ steps.base.outputs.base-args }}
run: |
uv run python .github/scripts/check_role_dates.py \
--changed-files ${ALL_CHANGED_FILES} ${BASE_ARGS}
- name: lint committees selectively
env:
OS_PEOPLE_DIRECTORY: ${{ env.GITHUB_WORKSPACE }}
ALL_CHANGED_DIRS: ${{ steps.changed-dirs.outputs.all_changed_files }}
run: |
abbrs=()
for dir in ${ALL_CHANGED_DIRS}; do
if [[ "$dir" =~ ^data/([a-z]{2})/committees ]]; then
abbrs+=("${BASH_REMATCH[1]}")
fi
done
if [[ ${#abbrs[@]} -gt 0 ]]; then
mapfile -t abbrs < <(printf '%s\n' "${abbrs[@]}" | sort -u)
uv run os-committees lint "${abbrs[@]}"
fi