You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

261 lines
10 KiB

  1. # Copyright 2020 IT Projects Labs
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. name: "DINAR"
  15. on:
  16. pull_request:
  17. jobs:
  18. pre-commit:
  19. name: "pre-commit"
  20. # Let Quick Review/Tests run first
  21. needs:
  22. - review
  23. - tests
  24. runs-on: ubuntu-latest
  25. steps:
  26. - name: Checkout Repo
  27. uses: actions/checkout@v2
  28. - uses: actions/setup-python@v1
  29. with:
  30. python-version: "3.7.x"
  31. - name: Check Python Version
  32. run:
  33. echo "PY=$(python --version --version | sha256sum | cut -d' ' -f1)" >>
  34. $GITHUB_ENV
  35. - uses: actions/cache@v1
  36. with:
  37. path: ~/.cache/pre-commit
  38. key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
  39. - uses: pre-commit/action@v1.0.1
  40. review:
  41. name: "Quick Review"
  42. runs-on: ubuntu-latest
  43. steps:
  44. - name: Checkout Repo
  45. uses: actions/checkout@v2
  46. with:
  47. path: REPO
  48. - name: Checkout DINAR
  49. uses: actions/checkout@v2
  50. with:
  51. path: DINAR
  52. repository: itpp-labs/DINAR-fork
  53. ref: master
  54. - uses: actions/setup-python@v1
  55. with:
  56. python-version: "3.7.x"
  57. - name: Install python tools
  58. run: |
  59. pip install plumbum PyGithub pyyaml
  60. - name: Analyze PR
  61. run: |
  62. # sets environment variables that available in next steps via $ {{ env.PR_... }} notation
  63. cd REPO
  64. python ../DINAR/workflow-files/analyze-modules.py updated ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }} ${{ github.event.number }}
  65. - name: Configure docker
  66. run: |
  67. bash DINAR/workflow-files/configure-docker.sh ${{ secrets.DINAR_TOKEN || secrets.GITHUB_TOKEN }}
  68. echo "PR_FILES=../../REPO" >> $GITHUB_ENV
  69. - name: HOW TO RUN ODOO LOCALLY
  70. if: always()
  71. run: |
  72. export MODULES=${{ env.PR_MODULES }}
  73. export LOAD_MODULES=${{ env.PR_MODULES_LOAD }}
  74. export PR_NUM=${{ github.event.number }}
  75. export VERSION=${{ github.event.pull_request.base.ref }}
  76. export REVISION_PR=${{ github.event.pull_request.head.sha}}
  77. export DINAR_REPO="itpp-labs/DINAR-fork"
  78. bash DINAR/workflow-files/how-to-run-locally.sh
  79. - name: Check Python Version
  80. run:
  81. echo "PY=$(python --version --version | sha256sum | cut -d' ' -f1)" >>
  82. $GITHUB_ENV
  83. - uses: actions/cache@v1
  84. with:
  85. path: ~/.cache/pre-commit
  86. key: pre-commit|${{ env.PY }}|${{ hashFiles('REPO/.pre-commit-config.yaml') }}
  87. - name: Install pre-commit
  88. run: |
  89. pip install pre-commit
  90. - name: PRE-COMMIT against updated files only
  91. run: |
  92. cd REPO
  93. git fetch origin ${{ github.event.pull_request.base.ref }}
  94. pre-commit run --show-diff-on-failure --color=always --show-diff-on-failure --files $(git diff --name-only --no-ext-diff -z ${{ github.event.pull_request.base.ref }}..HEAD)
  95. tests:
  96. name: "Quick Tests"
  97. runs-on: ubuntu-latest
  98. steps:
  99. - name: Checkout Repo
  100. uses: actions/checkout@v2
  101. with:
  102. path: REPO
  103. - name: Checkout DINAR
  104. uses: actions/checkout@v2
  105. with:
  106. path: DINAR
  107. repository: itpp-labs/DINAR-fork
  108. ref: master
  109. - name: Configure docker
  110. run: |
  111. bash DINAR/workflow-files/configure-docker.sh ${{ secrets.DINAR_TOKEN || secrets.GITHUB_TOKEN }}
  112. echo "PR_FILES=../../REPO" >> $GITHUB_ENV
  113. - name: Install python tools
  114. run: |
  115. pip install plumbum PyGithub pyyaml
  116. - name: Download Docker images with preinstalled modules
  117. run: |
  118. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  119. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml pull
  120. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --no-start
  121. - name: Analyze PR
  122. run: |
  123. # Get list of installed modules
  124. ODOO_BASE_MODULES=$(docker inspect \
  125. --format '{{ index .Config.Labels "dinar.odoo.modules"}}' \
  126. dinar_odoo_1)
  127. echo "ODOO_BASE_MODULES=$ODOO_BASE_MODULES"
  128. # sets environment variables that available in next steps via $ {{ env.PR_... }} notation
  129. cd REPO
  130. python ../DINAR/workflow-files/analyze-modules.py updated ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }} ${{ github.event.number }} $ODOO_BASE_MODULES
  131. - name: Install json parser
  132. run: |
  133. sudo apt-get install jq
  134. - name: Install Additional Dependencies (Modules)
  135. if: env.PR_MODULES_DEPS != ''
  136. run: |
  137. # Install new dependencies without tests
  138. export MODULES="${{ env.PR_MODULES_DEPS }}"
  139. export LOAD_MODULES="${{ env.PR_MODULES_LOAD }}"
  140. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  141. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --abort-on-container-exit
  142. - name: Install Additional Dependencies (Packages)
  143. if: env.PR_DEPS != ''
  144. run: |
  145. # TODO https://github.com/itpp-labs/DINAR/issues/42
  146. exit 1
  147. - name: Prepare Artifact Folder
  148. run: |
  149. mkdir new-deps/
  150. # create dummy file to be sure that Artifact will be uploaded
  151. echo ok > new-deps/.empty
  152. echo "ARTIFACT=empty" >> $GITHUB_ENV
  153. - name: Prepare DINAR with additional dependencies
  154. if: env.PR_MODULES_DEPS != '' || env.PR_DEPS != ''
  155. run: |
  156. # Save artifacts for local run and for integrations Tests
  157. bash DINAR/workflow-files/save-docker-layers.sh new-deps/
  158. echo "${{ env.PR_MODULES_DEPS }}" > new-deps/modules.txt
  159. echo "ARTIFACT=yes" >> $GITHUB_ENV
  160. - name: Save DINAR with dependencies
  161. uses: actions/upload-artifact@v1
  162. with:
  163. name: new-deps
  164. path: new-deps/
  165. - name: HOW TO RUN QUICK TESTS LOCALLY
  166. if: always()
  167. run: |
  168. export MODULES=${{ env.PR_MODULES }}
  169. export LOAD_MODULES=${{ env.PR_MODULES_LOAD }}
  170. export PR_NUM=${{ github.event.number }}
  171. export VERSION=${{ github.event.pull_request.base.ref }}
  172. export REVISION_PR=${{ github.event.pull_request.head.sha}}
  173. export DINAR_REPO="itpp-labs/DINAR-fork"
  174. export ODOO_EXTRA_ARG=--test-enable
  175. bash DINAR/workflow-files/how-to-run-locally.sh ${{ secrets.GITHUB_TOKEN }}
  176. - name: Test updated modules
  177. if: env.PR_MODULES != ''
  178. run: |
  179. export MODULES="${{ env.PR_MODULES }}"
  180. export LOAD_MODULES="${{ env.PR_MODULES_LOAD }}"
  181. export ODOO_EXTRA_ARG=--test-enable
  182. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  183. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --abort-on-container-exit
  184. tests-all:
  185. name: Integration Tests
  186. # Let Quick Review/Tests run first
  187. # This job uses artifacts from "Quick Tests"
  188. needs:
  189. - tests
  190. - review
  191. runs-on: ubuntu-latest
  192. steps:
  193. - name: Checkout Repo
  194. uses: actions/checkout@v2
  195. with:
  196. path: REPO
  197. - name: Checkout DINAR
  198. uses: actions/checkout@v2
  199. with:
  200. path: DINAR
  201. repository: itpp-labs/DINAR-fork
  202. ref: master
  203. - name: Install python tools
  204. run: |
  205. pip install plumbum pyyaml
  206. - name: Download Additional Dependencies artifact
  207. uses: actions/download-artifact@v1
  208. with:
  209. name: new-deps
  210. path: new-deps/
  211. - name: Check artifact
  212. run: |
  213. if [ ! -f new-deps/modules.txt ]; then
  214. echo "ARTIFACT=empty" >> $GITHUB_ENV
  215. fi
  216. - name: Configure Docker
  217. run: |
  218. bash DINAR/workflow-files/configure-docker.sh ${{ secrets.DINAR_TOKEN || secrets.GITHUB_TOKEN }}
  219. echo "PR_FILES=../../REPO" >> $GITHUB_ENV
  220. - name: Analyze PR
  221. run: |
  222. # sets environment variables that available in next steps via $ {{ env.PR_... }} notation
  223. DEPS_MODULES=$(cat new-deps/modules.txt || true)
  224. cd REPO
  225. python ../DINAR/workflow-files/analyze-modules.py all "$DEPS_MODULES"
  226. - name: Install json parser
  227. run: |
  228. sudo apt-get install jq
  229. - name: HOW TO RUN TESTS LOCALLY
  230. if: always()
  231. run: |
  232. export MODULES=${{ env.ALL_MODULES }}
  233. export LOAD_MODULES=${{ env.ALL_MODULES_LOAD }}
  234. export PR_NUM=${{ github.event.number }}
  235. export VERSION=${{ github.event.pull_request.base.ref }}
  236. export REVISION_PR=${{ github.event.pull_request.head.sha}}
  237. export DINAR_REPO="itpp-labs/DINAR-fork"
  238. export ODOO_EXTRA_ARG=--test-enable
  239. bash DINAR/workflow-files/how-to-run-locally.sh ${{ secrets.GITHUB_TOKEN }}
  240. - name: Download base images
  241. run: |
  242. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  243. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml pull
  244. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --no-start
  245. - name: Apply new-deps artifact
  246. if: env.ARTIFACT != 'empty'
  247. run: |
  248. bash DINAR/workflow-files/load-docker-layers.sh new-deps/
  249. - name: Test all modules
  250. run: |
  251. export MODULES="${{ env.ALL_MODULES }}"
  252. export LOAD_MODULES="${{ env.ALL_MODULES_LOAD }}"
  253. export ODOO_EXTRA_ARG=--test-enable
  254. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  255. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --abort-on-container-exit