-
Notifications
You must be signed in to change notification settings - Fork 7
170 lines (146 loc) · 5.89 KB
/
ci.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
166
167
168
169
170
name: CI
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [main]
pull_request:
branches: [main]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
CI:
runs-on: ubuntu-latest
env:
PY_VERSION: "3.11"
REF_TIMES_model: "b488fb07f0899ee8b7e710c230b1a9414fa06f7d"
REF_demos-xlsx: "34a2a5c044cc0bbea1357de50db2f5f02d575181"
REF_demos-dd: "2848a8a8e2fdcf0cdf7f83eefbdd563b0bb74e86"
REF_tim: "e820d8002adc6b1526a3bffcc439219b28d0eed5"
REF_tim-gams: "703f6a4e1d0bedd95c3ebdae534496f3a7e1b7cc"
steps:
- uses: actions/checkout@v3
with:
path: xl2times
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PY_VERSION }}
- name: Install tool and dependencies
working-directory: xl2times
run: |
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e .[dev]
- name: Check code formatting
working-directory: xl2times
run: |
source .venv/bin/activate
pre-commit install
pre-commit run --all-files
- name: Run unit tests
working-directory: xl2times
run: |
source .venv/bin/activate
pytest
# ---------- Prepare ETSAP Demo models
- uses: actions/checkout@v3
with:
repository: etsap-TIMES/TIMES_model
path: TIMES_model
ref: ${{ env.REF_TIMES_model }}
- uses: actions/checkout@v3
with:
repository: olejandro/demos-dd
path: xl2times/benchmarks/dd
ref: ${{ env.REF_demos-dd }}
- uses: actions/checkout@v3
with:
repository: olejandro/demos-xlsx
path: xl2times/benchmarks/xlsx
ref: ${{ env.REF_demos-xlsx }}
token: ${{ secrets.GH_PAT_DEMOS_XLSX }}
# ---------- Prepare TIMES Ireland Model
# We add this model as the directory `ireland` under `benchmarks/{xlsx,dd}/`
# so that the run_benchmarks.py script runs this model too
- uses: actions/checkout@v3
with:
repository: esma-cgep/tim
path: xl2times/benchmarks/xlsx/Ireland
ref: ${{ env.REF_tim }}
- uses: actions/checkout@v3
with:
repository: esma-cgep/tim-gams
path: xl2times/benchmarks/dd/Ireland
ref: ${{ env.REF_tim-gams }}
# ---------- Install GAMS
- name: Install GAMS
env:
GAMS_LICENSE: ${{ secrets.GAMS_LICENSE }}
if: ${{ env.GAMS_LICENSE != '' }}
run: |
curl https://d37drm4t2jghv5.cloudfront.net/distributions/44.1.0/linux/linux_x64_64_sfx.exe -o linux_x64_64_sfx.exe
chmod +x linux_x64_64_sfx.exe
mkdir GAMS
pushd GAMS
../linux_x64_64_sfx.exe > /dev/null && echo Successfully installed GAMS
export PATH=$PATH:$(pwd)/gams44.1_linux_x64_64_sfx
popd
echo Creating license file at $HOME/.local/share/GAMS
mkdir -p $HOME/.local/share/GAMS
echo "$GAMS_LICENSE" > $HOME/.local/share/GAMS/gamslice.txt
ls -l $HOME/.local/share/GAMS/
# ---------- Run tool, check for regressions
- name: Restore XLSX cache directory from cache
id: cache
uses: actions/cache/restore@v4
with:
path: ${{ github.workspace }}/xl2times/xl2times/.cache
# Cache key is refs of the input xlsx repos, since that's what is cached
key: ${{ runner.os }}-py-${{ env.PY_VERSION }}-${{ env.REF_demos-xlsx }}-${{ env.REF_tim }}
# If we can't find the exact key for the TIM repo, still use the cache if the demos repo ref matches
restore-keys: |
${{ runner.os }}-py-${{ env.PY_VERSION }}-${{ env.REF_demos-xlsx }}-
${{ runner.os }}-py-${{ env.PY_VERSION }}-
- name: Run tool on all benchmarks
env:
GAMS_LICENSE: ${{ secrets.GAMS_LICENSE }}
if: ${{ env.GAMS_LICENSE != '' }}
working-directory: xl2times
# Use tee to also save the output to out.txt so that the summary table can be
# printed again in the next step.
# Save the return code to retcode.txt so that the next step can fail the action
run: |
source .venv/bin/activate
export PATH=$PATH:$GITHUB_WORKSPACE/GAMS/gams44.1_linux_x64_64_sfx
(python utils/run_benchmarks.py benchmarks.yml \
--dd --times_dir $GITHUB_WORKSPACE/TIMES_model \
--verbose \
| tee out.txt; \
echo ${PIPESTATUS[0]} > retcode.txt)
- name: Run CSV-only regression tests (no GAMS license)
env:
GAMS_LICENSE: ${{ secrets.GAMS_LICENSE }}
if: ${{ env.GAMS_LICENSE == '' }}
working-directory: xl2times
# Run without --dd flag if GAMS license secret doesn't exist.
# Useful for testing for (CSV) regressions in forks before creating PRs.
run: |
source .venv/bin/activate
export PATH=$PATH:$GITHUB_WORKSPACE/GAMS/gams44.1_linux_x64_64_sfx
(python utils/run_benchmarks.py benchmarks.yml \
--times_dir $GITHUB_WORKSPACE/TIMES_model \
--verbose \
| tee out.txt; \
echo ${PIPESTATUS[0]} > retcode.txt)
- name: Print summary
working-directory: xl2times
run: |
sed -n '/Benchmark *Time.*Accuracy/h;//!H;$!d;x;//p' out.txt
exit $(cat retcode.txt)
- uses: actions/cache/save@v4
# Save the cache even if the regression tests fail
if: always() && !steps.cache-restore.outputs.cache-hit
with:
path: ${{ github.workspace }}/xl2times/xl2times/.cache
key: ${{ runner.os }}-py-${{ env.PY_VERSION }}-${{ env.REF_demos-xlsx }}-${{ env.REF_tim }}