-
Notifications
You must be signed in to change notification settings - Fork 36
129 lines (125 loc) · 4.62 KB
/
Copy pathmodule-checks.yml
File metadata and controls
129 lines (125 loc) · 4.62 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
name: Module Checks
permissions:
contents: read
on:
push:
branches:
- "main"
paths:
- "modules/**"
- ".github/workflows/module-checks.yml"
pull_request:
branches:
- "main"
- "release/*"
- "stable"
paths:
- "modules/**"
- ".github/workflows/module-checks.yml"
jobs:
get-modules:
name: Get Modules
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.get-modules.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@e9772d140489982e0e3704fea5ee93d536f1e275
with:
files: modules/**
- name: List all changed files
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
for file in ${ALL_CHANGED_FILES}; do
echo "$file was changed"
done
- name: Get modules
id: get-modules
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
set -x
# Get all the modules that have the file "deployspec.yaml"
MODULES=$(echo $ALL_CHANGED_FILES | tr ' ' '\n' | cut -d/ -f 2-3 | uniq)
# Create our json structure [{"module_name": "..."}]
MODULES_JSON=$(echo "$MODULES" | jq -R -s 'split("\n")' | jq '[ .[] | select(length > 0) ]' | jq 'map({"module_name": .})')
# Export the modules as json to the outputs
echo 'matrix<<EOF' >> $GITHUB_OUTPUT
echo $MODULES_JSON >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
test:
name: Run unit tests for module ${{ matrix.modules.module_name }} (Python ${{ matrix.python-version }})
needs: get-modules
strategy:
fail-fast: false
matrix:
modules: ${{ fromJson(needs.get-modules.outputs.matrix) }}
python-version: ["3.10", "3.11", "3.12"]
node-version: [18.x]
runs-on: ubuntu-latest
env:
MODULE_PATH: 'modules/${{ matrix.modules.module_name }}'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- id: determine-language
name: Determine Language
run: |
set -x
if [ -f $MODULE_PATH/package.json ]; then \
echo "language=typescript" >> "$GITHUB_OUTPUT"; \
elif [ -f $MODULE_PATH/requirements.txt ]; then \
echo "language=python" >> "$GITHUB_OUTPUT"; \
elif [ -f $MODULE_PATH/pyproject.toml ]; then \
echo "language=python" >> "$GITHUB_OUTPUT"; \
else \
echo "language=none" >> "$GITHUB_OUTPUT"; \
fi
- name: Set up uv
if: ${{ steps.determine-language.outputs.language == 'python' }}
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- name: Set up Python ${{ matrix.python-version }}
if: ${{ steps.determine-language.outputs.language == 'python' }}
run: uv python install ${{ matrix.python-version }}
- name: Create virtual environment
if: ${{ steps.determine-language.outputs.language == 'python' }}
run: uv venv --python ${{ matrix.python-version }}
- name: Set up Node ${{ matrix.node-version }}
if: ${{ steps.determine-language.outputs.language == 'typescript' }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install Requirements (Python)
if: ${{ steps.determine-language.outputs.language == 'python' }}
run: |
set -x
uv pip install -r requirements-dev.txt
uv pip install -r $MODULE_PATH/requirements.txt
- name: Install Requirements (Typescript)
if: ${{ steps.determine-language.outputs.language == 'typescript' }}
run: |
set -x
cd $MODULE_PATH
npm install
- name: Static checks and linting (Python)
if: ${{ steps.determine-language.outputs.language == 'python' }}
run: uv run scripts/validate.sh --language python --path $MODULE_PATH/
- name: Static checks and linting (TypeScript)
if: ${{ steps.determine-language.outputs.language == 'typescript' }}
run: ./scripts/validate.sh --language typescript --path $MODULE_PATH/
- name: Pytest
if: ${{ steps.determine-language.outputs.language == 'python' }}
run: uv run --no-project --directory $MODULE_PATH pytest
- name: NPM Test
if: ${{ steps.determine-language.outputs.language == 'typescript' }}
run: cd $MODULE_PATH/ && npm test