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.

264 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. echo "CHANGED FILES:"
  95. git diff --name-only --no-ext-diff FETCH_HEAD..HEAD -- .
  96. echo "RUN PRE-COMMIT:"
  97. pre-commit run --show-diff-on-failure --color=always --show-diff-on-failure --files $(git diff --name-only --no-ext-diff FETCH_HEAD..HEAD -- .)
  98. tests:
  99. name: "Quick Tests"
  100. runs-on: ubuntu-latest
  101. steps:
  102. - name: Checkout Repo
  103. uses: actions/checkout@v2
  104. with:
  105. path: REPO
  106. - name: Checkout DINAR
  107. uses: actions/checkout@v2
  108. with:
  109. path: DINAR
  110. repository: itpp-labs/DINAR-fork
  111. ref: master
  112. - name: Configure docker
  113. run: |
  114. bash DINAR/workflow-files/configure-docker.sh ${{ secrets.DINAR_TOKEN || secrets.GITHUB_TOKEN }}
  115. echo "PR_FILES=../../REPO" >> $GITHUB_ENV
  116. - name: Install python tools
  117. run: |
  118. pip install plumbum PyGithub pyyaml
  119. - name: Download Docker images with preinstalled modules
  120. run: |
  121. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  122. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml pull
  123. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --no-start
  124. - name: Analyze PR
  125. run: |
  126. # Get list of installed modules
  127. ODOO_BASE_MODULES=$(docker inspect \
  128. --format '{{ index .Config.Labels "dinar.odoo.modules"}}' \
  129. dinar_odoo_1)
  130. echo "ODOO_BASE_MODULES=$ODOO_BASE_MODULES"
  131. # sets environment variables that available in next steps via $ {{ env.PR_... }} notation
  132. cd REPO
  133. python ../DINAR/workflow-files/analyze-modules.py updated ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }} ${{ github.event.number }} $ODOO_BASE_MODULES
  134. - name: Install json parser
  135. run: |
  136. sudo apt-get install jq
  137. - name: Install Additional Dependencies (Modules)
  138. if: env.PR_MODULES_DEPS != ''
  139. run: |
  140. # Install new dependencies without tests
  141. export MODULES="${{ env.PR_MODULES_DEPS }}"
  142. export LOAD_MODULES="${{ env.PR_MODULES_LOAD }}"
  143. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  144. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --abort-on-container-exit
  145. - name: Install Additional Dependencies (Packages)
  146. if: env.PR_DEPS != ''
  147. run: |
  148. # TODO https://github.com/itpp-labs/DINAR/issues/42
  149. exit 1
  150. - name: Prepare Artifact Folder
  151. run: |
  152. mkdir new-deps/
  153. # create dummy file to be sure that Artifact will be uploaded
  154. echo ok > new-deps/.empty
  155. echo "ARTIFACT=empty" >> $GITHUB_ENV
  156. - name: Prepare DINAR with additional dependencies
  157. if: env.PR_MODULES_DEPS != '' || env.PR_DEPS != ''
  158. run: |
  159. # Save artifacts for local run and for integrations Tests
  160. bash DINAR/workflow-files/save-docker-layers.sh new-deps/
  161. echo "${{ env.PR_MODULES_DEPS }}" > new-deps/modules.txt
  162. echo "ARTIFACT=yes" >> $GITHUB_ENV
  163. - name: Save DINAR with dependencies
  164. uses: actions/upload-artifact@v1
  165. with:
  166. name: new-deps
  167. path: new-deps/
  168. - name: HOW TO RUN QUICK TESTS LOCALLY
  169. if: always()
  170. run: |
  171. export MODULES=${{ env.PR_MODULES }}
  172. export LOAD_MODULES=${{ env.PR_MODULES_LOAD }}
  173. export PR_NUM=${{ github.event.number }}
  174. export VERSION=${{ github.event.pull_request.base.ref }}
  175. export REVISION_PR=${{ github.event.pull_request.head.sha}}
  176. export DINAR_REPO="itpp-labs/DINAR-fork"
  177. export ODOO_EXTRA_ARG=--test-enable
  178. bash DINAR/workflow-files/how-to-run-locally.sh ${{ secrets.GITHUB_TOKEN }}
  179. - name: Test updated modules
  180. if: env.PR_MODULES != ''
  181. run: |
  182. export MODULES="${{ env.PR_MODULES }}"
  183. export LOAD_MODULES="${{ env.PR_MODULES_LOAD }}"
  184. export ODOO_EXTRA_ARG=--test-enable
  185. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  186. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --abort-on-container-exit
  187. tests-all:
  188. name: Integration Tests
  189. # Let Quick Review/Tests run first
  190. # This job uses artifacts from "Quick Tests"
  191. needs:
  192. - tests
  193. - review
  194. runs-on: ubuntu-latest
  195. steps:
  196. - name: Checkout Repo
  197. uses: actions/checkout@v2
  198. with:
  199. path: REPO
  200. - name: Checkout DINAR
  201. uses: actions/checkout@v2
  202. with:
  203. path: DINAR
  204. repository: itpp-labs/DINAR-fork
  205. ref: master
  206. - name: Install python tools
  207. run: |
  208. pip install plumbum pyyaml
  209. - name: Download Additional Dependencies artifact
  210. uses: actions/download-artifact@v1
  211. with:
  212. name: new-deps
  213. path: new-deps/
  214. - name: Check artifact
  215. run: |
  216. if [ ! -f new-deps/modules.txt ]; then
  217. echo "ARTIFACT=empty" >> $GITHUB_ENV
  218. fi
  219. - name: Configure Docker
  220. run: |
  221. bash DINAR/workflow-files/configure-docker.sh ${{ secrets.DINAR_TOKEN || secrets.GITHUB_TOKEN }}
  222. echo "PR_FILES=../../REPO" >> $GITHUB_ENV
  223. - name: Analyze PR
  224. run: |
  225. # sets environment variables that available in next steps via $ {{ env.PR_... }} notation
  226. DEPS_MODULES=$(cat new-deps/modules.txt || true)
  227. cd REPO
  228. python ../DINAR/workflow-files/analyze-modules.py all "$DEPS_MODULES"
  229. - name: Install json parser
  230. run: |
  231. sudo apt-get install jq
  232. - name: HOW TO RUN TESTS LOCALLY
  233. if: always()
  234. run: |
  235. export MODULES=${{ env.ALL_MODULES }}
  236. export LOAD_MODULES=${{ env.ALL_MODULES_LOAD }}
  237. export PR_NUM=${{ github.event.number }}
  238. export VERSION=${{ github.event.pull_request.base.ref }}
  239. export REVISION_PR=${{ github.event.pull_request.head.sha}}
  240. export DINAR_REPO="itpp-labs/DINAR-fork"
  241. export ODOO_EXTRA_ARG=--test-enable
  242. bash DINAR/workflow-files/how-to-run-locally.sh ${{ secrets.GITHUB_TOKEN }}
  243. - name: Download base images
  244. run: |
  245. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  246. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml pull
  247. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --no-start
  248. - name: Apply new-deps artifact
  249. if: env.ARTIFACT != 'empty'
  250. run: |
  251. bash DINAR/workflow-files/load-docker-layers.sh new-deps/
  252. - name: Test all modules
  253. run: |
  254. export MODULES="${{ env.ALL_MODULES }}"
  255. export LOAD_MODULES="${{ env.ALL_MODULES_LOAD }}"
  256. export ODOO_EXTRA_ARG=--test-enable
  257. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  258. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --abort-on-container-exit