forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (132 loc) · 5.03 KB
/
unit-test-mmv1.yml
File metadata and controls
138 lines (132 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
132
133
134
135
136
137
name: mmv1
permissions: read-all
on:
push:
branches:
- main
- 'FEATURE-BRANCH-*'
merge_group:
types: [checks_requested]
pull_request:
concurrency:
group: ${{ github.event_name == 'merge_group' && format('mmv1-merge-group-{0}', github.event.merge_group.head_sha) || github.event_name == 'pull_request' && format('mmv1-pr-{0}', github.event.pull_request.number) || format('mmv1-commit-{0}', github.sha) }}
cancel-in-progress: true
jobs:
version-guard-check:
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2
with:
path: repo
fetch-depth: 0
- name: Merge base branch
if: github.event_name == 'pull_request'
run: |
cd repo
git config user.name "modular-magician"
git config user.email "magic-modules@google.com"
git fetch origin ${{ github.base_ref }} # Fetch the base branch
git merge --no-ff origin/${{ github.base_ref }} # Merge with the base branch
- name: Check for invalid version guards
run: |
cd repo/tools/template-check
tmpls=$(git diff --name-only --diff-filter=d origin/${{ github.base_ref }} ../../*.tmpl | sed 's=^=../../=g')
tmpls=${tmpls//$'\n'/,}
echo $tmpls
if [[ -n "$tmpls" ]]; then
go run main.go version-guard --file-list $tmpls
fi
unused-template-check:
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2
with:
path: repo
fetch-depth: 0
- name: Merge base branch
if: github.event_name == 'pull_request'
id: pull_request
run: |
cd repo
git config user.name "modular-magician"
git config user.email "magic-modules@google.com"
git fetch origin ${{ github.base_ref }} # Fetch the base branch
git merge --no-ff origin/${{ github.base_ref }} # Merge with the base branch
- name: Check new product templates are linked
id: new_templates
run: |
cd repo/tools/template-check
newtmplfiles=$(git diff --name-only --diff-filter=A origin/${{ github.base_ref }} HEAD -- ../../mmv1 | grep .tmpl | sed 's=^=../../=g')
if [ ! -z "$newtmplfiles" ]; then
newtmplfiles=${newtmplfiles//$'\n'/,}
echo $newtmplfiles
go run main.go unused-tmpl --file-list $newtmplfiles
fi
lint-yaml:
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2
with:
path: repo
fetch-depth: 0
- name: Merge base branch
if: github.event_name == 'pull_request'
run: |
cd repo
git config user.name "modular-magician"
git config user.email "magic-modules@google.com"
git fetch origin ${{ github.base_ref }}
git merge --no-ff origin/${{ github.base_ref }}
- name: Find YAML files to lint
id: yaml_files
run: |
cd repo
if [ "${{ github.event_name }}" == "pull_request" ]; then
# For PRs, get only changed files
yamlfiles=$(git diff --name-only origin/${{ github.base_ref }} -- mmv1/products)
if [ ! -z "$yamlfiles" ]; then
echo "yamlfiles=${yamlfiles//$'\n'/ }" >> $GITHUB_OUTPUT
fi
else
# For other events, get all YAML files
yamlfiles=$(find mmv1/products -name "*.yaml" -o -name "*.yml" | tr '\n' ' ')
if [ ! -z "$yamlfiles" ]; then
echo "yamlfiles=$yamlfiles" >> $GITHUB_OUTPUT
fi
fi
- name: Install yamllint
if: ${{ !failure() && steps.yaml_files.outputs.yamlfiles != '' }}
run: pip install yamllint==1.32.0 pyyaml==6.0.1 pathspec==0.12.1 --no-deps
- name: Lint YAML files
if: ${{ !failure() && steps.yaml_files.outputs.yamlfiles != '' }}
run: |
cd repo
yamllint -c .yamllint ${{ steps.yaml_files.outputs.yamlfiles }}
unit-tests:
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2
with:
path: repo
fetch-depth: 0
- name: Merge base branch
if: github.event_name == 'pull_request'
run: |
cd repo
git config user.name "modular-magician"
git config user.email "magic-modules@google.com"
git fetch origin ${{ github.base_ref }} # Fetch the base branch
git merge --no-ff origin/${{ github.base_ref }} # Merge with the base branch
- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: '^1.24'
- name: Run mmv1 unit tests
run: |
cd repo
cd mmv1
go test ./...