-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (100 loc) · 4.33 KB
/
lint.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
---
name: Lint
on:
push:
branches:
- master
pull_request:
schedule:
- cron: "10 10 * * SUN"
workflow_dispatch:
env:
# https://www.jeffgeerling.com/blog/2020/getting-colorized-output-molecule-and-ansible-on-github-actions-ci
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
jobs:
lint:
runs-on: ubuntu-latest
steps:
# TODO: is there an easier way to do this?
- name: Determine if we apply to all files
if: contains(fromJSON('["schedule", "workflow_dispatch"]'), github.event_name)
run: echo "changed_all=true" >> "$GITHUB_ENV"
# NOTE: code needs to be checked out to even get at .github/paths-filter.yml
- uses: actions/checkout@v3
- name: Install dependency manager
run: pipx install poetry
- name: Set up Python 3.x
id: setup-python
uses: actions/setup-python@v4
with:
python-version: '3.11.1' # avoid warning in logs
cache: 'poetry'
- name: Install packages
run: poetry install --no-interaction
- name: Check for changes in relevant files
id: changes
if: env.changed_all != 'true'
uses: dorny/paths-filter@v2
with:
filters: .github/paths-filter.yml
- name: Set up pre-commit
if: env.changed_all == 'true' || steps.changes.outputs.all == 'true'
# TODO: how do we make the version of pre-commit match pyproject.toml
run: |
pip install pre-commit
pre-commit install --install-hooks
- name: Get listing of changed Ansible files
id: ansible-files
if: env.changed_all != 'true' && steps.changes.outputs.ansible == 'true'
uses: dorny/paths-filter@v2
with:
# Enable listing of files matching each filter.
# Paths to files will be available in `${FILTER_NAME}_files` output variable.
# Paths will be escaped and space-delimited.
# Output is usable as command line argument list in linux shell
list-files: shell
# Skip linting deleted files
# TODO: how do avoid the redundancy with paths-filter.yml?
filters: |
all:
- added|modified: galaxy.xml
- added|modified: '{docs,meta,plugins,roles}/**'
- name: Run pre-commit on all ansible files
if: env.changed_all == 'true'
run: |
pre-commit run --all-files
- name: Run pre-commit on changed ansible files
if: env.changed_all != 'true' && steps.changes.outputs.ansible == 'true'
run: |
# Run pre-commit to lint and format check files that were changed (but not deleted) compared to master.
# XXX: there is a very small chance that it'll expand to exceed Linux's limits
# `getconf ARG_MAX` - max # bytes of args + environ for exec()
pre-commit run --files ${{ steps.ansible-files.outputs.all_files }}
- name: Get listing of changed GitHub Action files
id: action-files
if: env.changed_all != 'true' && steps.changes.outputs.github_actions == 'true'
uses: dorny/paths-filter@v2
with:
# Enable listing of files matching each filter.
# Paths to files will be available in `${FILTER_NAME}_files` output variable.
# Paths will be escaped and space-delimited.
# Output is usable as command line argument list in linux shell
list-files: shell
# Skip linting deleted files
# TODO: how do avoid the redundancy with paths-filter.yml?
filters: |
all:
- added|modified: '.github/paths-filter.yml'
- added|modified: '.github/workflows/**'
- name: Run actionlint on all GitHub Action files
if: env.changed_all == 'true'
run: |
pre-commit run actionlint --all-files
- name: Run actionlint on changed GitHub Action files
if: env.changed_all != 'true' && steps.changes.outputs.github_actions == 'true'
run: |
# Run pre-commit to lint and format check files that were changed (but not deleted) compared to master.
# XXX: there is a very small chance that it'll expand to exceed Linux's limits
# `getconf ARG_MAX` - max # bytes of args + environ for exec()
pre-commit run actionlint --files ${{ steps.action-files.outputs.all_files }}