Chore: Upgrade Jenkins-job-builder to 6.3.0
[releng/global-jjb.git] / shell / info-file-validate.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2018 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 echo '--> info-file-validate.sh'
12 set -e -o pipefail
13 PROJECT="${PROJECT:-None}"
14
15 # shellcheck disable=SC1090
16 source ~/lf-env.sh
17 lf-activate-venv zipp==1.1.0 PyYAML jsonschema rfc3987 yamllint yq
18 pip freeze
19
20 # Download info-schema.yaml and yaml-verfy-schema.py
21 wget -q https://raw.githubusercontent.com/lfit/releng-global-jjb/master/schema/info-schema.yaml \
22 https://raw.githubusercontent.com/lfit/releng-global-jjb/master/yaml-verify-schema.py
23
24 yamllint INFO.yaml
25
26 python yaml-verify-schema.py \
27     -s info-schema.yaml \
28     -y INFO.yaml
29
30
31 # Verfiy that there is only one repository and that it matches $PROJECT
32 REPO_LIST="$(yq -r '.repositories[]' INFO.yaml)"
33
34 while IFS= read -r project; do
35     if [[ "$project" == "$PROJECT" ]]; then
36         echo "$project is valid"
37     else
38         echo "ERROR: $project is invalid"
39         echo "INFO.yaml file may only list one repository"
40         echo "Repository must match $PROJECT"
41         exit 1
42     fi
43 done <<< "$REPO_LIST"