-
Notifications
You must be signed in to change notification settings - Fork 2
195 lines (173 loc) · 6.96 KB
/
run_tests.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
name: Run tests
on:
pull_request:
branches: [ v5_backport ]
types: [ labeled ]
workflow_dispatch:
inputs:
pr_number:
description: "Pull Request number"
required: true
concurrency:
group: ${{ github.workflow }}-${{ github.event.label.name || github.ref }}-${{ github.ref }}
cancel-in-progress: true
env:
VENVS_PATH: /home/ci_replicante/ci_virtualenvs
REPOSITORY_PATH: /home/ci_replicante/src
SCRIPTS_PATH: /home/ci_replicante/ci_scripts
HELP_PATH: /home/ci_replicante/help
CI_REPO: ${{ github.repository }}
CI_PULL_REQUEST: ${{ github.event.pull_request.number || inputs.pr_number }}
jobs:
init:
runs-on: ubuntu-latest
steps:
- name: Comment PR
if: github.event_name == 'workflow_dispatch'
run: |
gh api repos/${{ github.repository }}/issues/${{ inputs.pr_number }}/comments \
-f body="🔄 *Starting tests execution...*
👉 [Track execution](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
env:
GITHUB_TOKEN: ${{ github.token }}
tests:
needs: init
if: (github.event_name == 'pull_request' && github.event.label.name == 'to be merged') || github.event_name == 'workflow_dispatch'
runs-on: [self-hosted, Buda]
strategy:
fail-fast: false
matrix:
python-version: [ "2.7.18", "3.11.4" ]
steps:
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v4
with:
path: custom_modules/${{ github.event.repository.name }}
ref: refs/pull/${{ inputs.pr_number || github.event.pull_request.number }}/merge
- name: 'Set build id'
id: build_id
run: echo "id=$(date +%s)" >> $GITHUB_OUTPUT
- name: Update repositories
run: |
. $SCRIPTS_PATH/update_branches.sh
- name: Checkout erp
uses: actions/checkout@v4
with:
path: src/erp
repository: gisce/erp
token: ${{ secrets.RO_GITHUB_ACTIONS_REPOS }}
- name: Prepare virtualenv Python ${{ matrix.python-version }}
env:
BUILD_ID: ${{ steps.build_id.outputs.id }}
ROOT_DIR_SRC: ${{ github.workspace }}/src
run: |
. $SCRIPTS_PATH/load_pyenv.sh
pyenv virtualenv ${{ matrix.python-version }} $BUILD_ID
pyenv activate $BUILD_ID
. $SCRIPTS_PATH/install_packages.sh $ROOT_DIR_SRC
cd $REPOSITORY_PATH/smmwebstg
pip install -e .
cd $REPOSITORY_PATH/twobeatstg
pip install -e .
- name: Update mamba for Python 3
env:
BUILD_ID: ${{ steps.build_id.outputs.id }}
if: matrix.python-version == '3.11.4'
run: |
. $SCRIPTS_PATH/load_pyenv.sh
pyenv activate $BUILD_ID
pip install --upgrade mamba
- name: Link Addons
env:
BUILD_ID: ${{ steps.build_id.outputs.id }}
CUSTOM_MODULES_PATH: ${{ github.workspace }}/custom_modules/
ROOT_DIR_SRC: ${{ github.workspace }}/src
ADDONS_PATH: ${{ github.workspace }}/src/erp/server/bin/addons
run: |
. $SCRIPTS_PATH/load_pyenv.sh
pyenv activate $BUILD_ID
cd $ROOT_DIR_SRC/erp
git apply $HELP_PATH/link_addons.diff
python tools/link_addons.py --skip-relative --base-path $REPOSITORY_PATH/,$CUSTOM_MODULES_PATH
rm $ADDONS_PATH/poweremail
cd $ADDONS_PATH
ln -s $CUSTOM_MODULES_PATH/${{ github.event.repository.name }} ./poweremail
- name: Run Tests
id: run_tests
env:
BUILD_ID: ${{ steps.build_id.outputs.id }}
GITHUB_TOKEN: ${{ secrets.RO_GITHUB_ACTIONS_REPOS }}
ROOT_DIR_SRC: ${{ github.workspace }}/src
ADDONS_PATH: ${{ github.workspace }}/src/erp/server/bin/addons
run: |
. $SCRIPTS_PATH/load_pyenv.sh
pyenv activate $BUILD_ID
. $SCRIPTS_PATH/export_env_vars.sh $ROOT_DIR_SRC
. $SCRIPTS_PATH/run_tests_custom.sh $BUILD_ID $ROOT_DIR_SRC $ADDONS_PATH ${{ github.event.repository.name }}
- name: Remove virtualenv
if: success() || failure()
env:
BUILD_ID: ${{ steps.build_id.outputs.id }}
run: |
. $SCRIPTS_PATH/load_pyenv.sh
pyenv virtualenv-delete -f $BUILD_ID
- name: Publish Unit Test Results 2
uses: EnricoMi/publish-unit-test-result-action@v2
if: always() && matrix.python-version == '2.7.18'
with:
check_name: "PY2TestsResults"
junit_files: "src/${{ steps.build_id.outputs.id }}/*.xml"
- name: Publish Unit Test Results 3
uses: EnricoMi/publish-unit-test-result-action@v2
if: always() && matrix.python-version == '3.11.4'
with:
check_name: "PY3TestsResults"
junit_files: "src/${{ steps.build_id.outputs.id }}/*.xml"
- name: Clean workspace
if: success() || failure()
run: |
cd ${{ github.workspace }}
rm -r *
- name: Obtener el SHA del último commit de la PR
if: github.event_name == 'workflow_dispatch'
run: |
PR_COMMIT_SHA=$(gh api repos/${{ github.repository }}/pulls/${{ inputs.pr_number }}/commits | jq -r '.[-1].sha')
echo "PR_COMMIT_SHA=$PR_COMMIT_SHA" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Set mergeable check (manual execution)
if: github.event_name == 'workflow_dispatch' && steps.run_tests.outcome == 'success' && matrix.python-version == '2.7.18'
run: |
gh api repos/${{ github.repository }}/statuses/${{ env.PR_COMMIT_SHA }} \
-f state="success" \
-f target_url="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
-f description="Tests passed - Mergeable" \
-f context="Mergeable"
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Set mergeable check
if: github.event_name != 'workflow_dispatch' && steps.run_tests.outcome == 'success' && matrix.python-version == '2.7.18'
uses: ouzi-dev/commit-status-updater@v2
with:
name: "Mergeable"
status: "${{ steps.run_tests.outcome }}"
url: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
end:
needs: tests
if: always()
runs-on: ubuntu-latest
steps:
- name: Comment PR with results
if: github.event_name == 'workflow_dispatch'
run: |
STATUS="✅ *Tests passed!*"
if [ "${{ needs.tests.result }}" != "success" ]; then
STATUS="❌ *Tests failed!*"
fi
gh api repos/${{ github.repository }}/issues/${{ inputs.pr_number }}/comments \
-f body="🔄 *Tests execution finished.*
👉 [Track execution](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
**Result:**
$STATUS"
env:
GITHUB_TOKEN: ${{ github.token }}