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.

249 lines
9.6 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 "::set-env name=PY::$(python --version --version | sha256sum | cut -d' '
  34. -f1)"
  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 "::set-env name=PR_FILES::../../REPO"
  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 "::set-env name=PY::$(python --version --version | sha256sum | cut -d' '
  82. -f1)"
  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 --origin HEAD --source origin/${{ github.event.pull_request.base.ref }}
  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 "::set-env name=PR_FILES::../../REPO"
  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. - name: Prepare DINAR with additional dependencies
  153. if: env.PR_MODULES_DEPS != '' || env.PR_DEPS != ''
  154. run: |
  155. # Save artifacts for local run and for integrations Tests
  156. bash DINAR/workflow-files/save-docker-layers.sh new-deps/
  157. echo "${{ env.PR_MODULES_DEPS }}" > new-deps/modules.txt
  158. - name: Save DINAR with dependencies
  159. uses: actions/upload-artifact@v1
  160. with:
  161. name: new-deps
  162. path: new-deps/
  163. - name: Test updated modules
  164. if: env.PR_MODULES != ''
  165. run: |
  166. export MODULES="${{ env.PR_MODULES }}"
  167. export LOAD_MODULES="${{ env.PR_MODULES_LOAD }}"
  168. export ODOO_EXTRA_ARG=--test-enable
  169. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  170. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --abort-on-container-exit
  171. tests-all:
  172. name: Integration Tests
  173. # Let Quick Review/Tests run first
  174. # This job uses artifacts from "Quick Tests"
  175. needs:
  176. - tests
  177. - review
  178. runs-on: ubuntu-latest
  179. steps:
  180. - name: Checkout Repo
  181. uses: actions/checkout@v2
  182. with:
  183. path: REPO
  184. - name: Checkout DINAR
  185. uses: actions/checkout@v2
  186. with:
  187. path: DINAR
  188. repository: itpp-labs/DINAR-fork
  189. ref: master
  190. - name: Install python tools
  191. run: |
  192. pip install plumbum pyyaml
  193. - name: Download Additional Dependencies artifact
  194. uses: actions/download-artifact@v1
  195. with:
  196. name: new-deps
  197. path: new-deps/
  198. - name: Check artifact
  199. run: |
  200. if [ ! -f new-deps/modules.txt ]; then
  201. echo "::set-env name=ARTIFACT::empty"
  202. fi
  203. - name: Configure Docker
  204. run: |
  205. bash DINAR/workflow-files/configure-docker.sh ${{ secrets.DINAR_TOKEN || secrets.GITHUB_TOKEN }}
  206. echo "::set-env name=PR_FILES::../../REPO"
  207. - name: Analyze PR
  208. run: |
  209. # sets environment variables that available in next steps via $ {{ env.PR_... }} notation
  210. DEPS_MODULES=$(cat new-deps/modules.txt || true)
  211. cd REPO
  212. python ../DINAR/workflow-files/analyze-modules.py all "$DEPS_MODULES"
  213. - name: Install json parser
  214. run: |
  215. sudo apt-get install jq
  216. - name: HOW TO RUN TESTS LOCALLY
  217. if: always()
  218. # TODO make similar for Quick Tests
  219. run: |
  220. export MODULES=${{ env.ALL_MODULES }}
  221. export LOAD_MODULES=${{ env.ALL_MODULES_LOAD }}
  222. export PR_NUM=${{ github.event.number }}
  223. export VERSION=${{ github.event.pull_request.base.ref }}
  224. export REVISION_PR=${{ github.event.pull_request.head.sha}}
  225. export DINAR_REPO="itpp-labs/DINAR-fork"
  226. export ODOO_EXTRA_ARG=--test-enable
  227. bash DINAR/workflow-files/how-to-run-locally.sh ${{ secrets.GITHUB_TOKEN }}
  228. - name: Download base images
  229. run: |
  230. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  231. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml pull
  232. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --no-start
  233. - name: Apply new-deps artifact
  234. if: env.ARTIFACT != 'empty'
  235. run: |
  236. bash DINAR/workflow-files/load-docker-layers.sh new-deps/
  237. - name: Test all modules
  238. run: |
  239. export MODULES="${{ env.ALL_MODULES }}"
  240. export LOAD_MODULES="${{ env.ALL_MODULES_LOAD }}"
  241. export ODOO_EXTRA_ARG=--test-enable
  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 up --abort-on-container-exit