-
Notifications
You must be signed in to change notification settings - Fork 1
165 lines (145 loc) · 6.98 KB
/
check_project_version_change.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
---
# This workflow checks that the semantic versioning (e.g. 1.1.0) of the GitHub
# project is correct, and if it's "minor" or "patch", checks backwards
# compatibility.
# The logic of this workflow is:
# - Details: EE-2699
# - Why: it helps avoiding human errors of versions in the schemas not being
# changed when or how they should.
# - Would block the PR if failed? Yes, as long as the PR is for a release.
# - How: by executing the script check_project_version_change.py, and then,
# based on its output, deploying Biovalidator with the old and new schemas
# and old and new JSON examples.
#
# For more information, check:
# https://github.com/EbiEga/ega-metadata-schema/tree/main/docs/releases
name: |
[REQUIRED] Check project version change
on:
# Executes on any commit to a PR to the "main" branch
pull_request:
branches: [main]
jobs:
check-modifications:
runs-on: ubuntu-latest
env:
BASE_URL: "https://raw.githubusercontent.com/EbiEga/ega-metadata-schema/main"
REPOSITORY_URL: "https://api.github.com/repos/EbiEga/ega-metadata-schema"
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
# This bit is needed to checkout in the branch that triggered the action
# (e.g. v2.0.1)
ref: ${{ github.head_ref }}
- uses: actions/setup-python@v4
with:
# We'll use the latest version of python from major 3 release
# This bit is needed for running the following python script
python-version: '3.x'
- name: Cache pip
uses: actions/cache@v4
with:
# On subsequent runs, if the cache key matches (i.e., operating system and the hash of the requirements.txt file),
# the dependencies are restored from the cache instead of being downloaded and installed again.
path: ~/.cache/pip
# combines the OS type and a hash of the requirements.txt file: the cache is specific to the dependencies listed
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
# If there is no cache for this key, we create it at the end of the run, even if there was an error mid-way
save-always: true
- name: Install dependencies
run: |
pip install --upgrade pip
requirements_f="./.github/scripts/requirements.txt"
if [ -f "$requirements_f" ]; then pip install -r "$requirements_f" --prefer-binary --verbose; fi
- name: Run version modification check
id: run-version-modification-check
run: |
script_path="./.github/scripts/check_project_version_change.py"
python3 "$script_path" --git_var_name "VERSION_CHANGE" --verbose
echo "- The version change is: ${{ env.VERSION_CHANGE }}"
# The output of this previous script will determine if changes are not "major" (i.e. minor or patch), and therefore retrocompatibility
# has to be tested through JSON Schema validation (combination of old and new schemas with old and new examples).
# Thus, only if the output (saved at 'VERSION_CHANGE') from the script is NOT Major, the following steps will occur.
- name: Check if version change is Major
id: check-version
# This step is just to set the logic for triggering the following steps
run: |
if [[ "${{ env.VERSION_CHANGE }}" != "Major" ]]; then
echo "version_needs_to_be_checked=True" >> $GITHUB_ENV
echo "- Since the changes are not 'Major', we will make sure by testing retrocompatibility"
else
echo "version_needs_to_be_checked=False" >> $GITHUB_ENV
echo "- Since the changes are 'Major', there is no need to test retrocompatibility"
fi
- name: Clone Biovalidator
if: ${{ env.version_needs_to_be_checked == 'True' }}
# See https://github.com/elixir-europe/biovalidator#installation
run: git clone https://github.com/elixir-europe/biovalidator.git
- name: Install Biovalidator
if: ${{ env.version_needs_to_be_checked == 'True' }}
run: |
cd biovalidator
npm install
# We shouldn't need to audit the issues, but for now it is what it is
# npm audit fix
- name: Start Biovalidator server (old schemas)
if: ${{ env.version_needs_to_be_checked == 'True' }}
# We want to specify the OLD JSON schemas, so we DO NOT specify the schemas
# at deployment level, and instead let Biovalidator fetch them from "main"
run: |
node biovalidator/src/biovalidator &
# We stop for a few seconds to give the server some time
sleep 3
- name: Validate JSON examples (old schemas, new examples)
if: ${{ env.version_needs_to_be_checked == 'True' }}
# Validate NEW JSON documents against the OLD (from "main") schemas
run: |
json_ex_dir="./examples/json_validation_tests"
# The following URL points to the locally deployed server of
# Biovalidator
url="http://localhost:3020/validate"
python3 ./.github/scripts/request_validation.py "$json_ex_dir" "$url"
- name: Kill previous Biovalidator server
if: ${{ env.version_needs_to_be_checked == 'True' }}
# We kill the existing Biovalidator server if it exists
run: |
# File path
file="./server.pid"
# Check if the file exists
if [ -f "$file" ]
then
# Read PID
pid=$(cat "$file")
# Check if the PID exists
if ps -p $pid > /dev/null
then
echo "Killing task with PID: $pid"
kill $pid
else
echo "No process found with PID: $pid"
fi
rm $file
else
echo "File $file does not exist"
fi
- name: Start Biovalidator server (New schemas)
if: ${{ env.version_needs_to_be_checked == 'True' }}
# We want to specify the NEW JSON schemas, so we DO specify the schemas
# at deployment level
run: |
schemas_dir="./schemas"
node biovalidator/src/biovalidator -r "$schemas_dir/*.json" &
sleep 3
- name: Validate JSON examples (New schemas, old examples)
if: ${{ env.version_needs_to_be_checked == 'True' }}
# Validate OLD JSON documents against the NEW (from branch) schemas
run: |
# We fetch all old JSON examples from "main"
old_json_ex_dir="./examples/old_json_validation_tests"
json_ex_dir="./examples/json_validation_tests"
python3 ./.github/scripts/fetch_github_documents.py --input_directory "$json_ex_dir" --destination_directory "$old_json_ex_dir"
url="http://localhost:3020/validate"
python3 ./.github/scripts/request_validation.py "$old_json_ex_dir" "$url"