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.

258 lines
9.8 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: HOW TO RUN LOCALLY
  66. #if: "env.PR_MODULES != ''"
  67. run: |
  68. cat << 'EOF'
  69. To test updates run:
  70. WORKDIR=/tmp/DINAR/${{ github.repository }}-${{ github.event.number }}/
  71. mkdir -p $WORKDIR
  72. cd $WORKDIR
  73. # TODO use fixed version instead of master
  74. curl https://raw.githubusercontent.com/itpp-labs/DINAR/master/local-files/docker-compose.yml > docker-compose.yml
  75. export REGISTRY=docker.pkg.github.com REPOSITORY=${{ github.repository }} REPO_NAME=$(echo ${{ github.repository }} | sed "s;.*/;;") VERSION=${{ github.event.pull_request.base.ref }}
  76. git clone --depth=1 --branch $VERSION git@github.com:${{ github.repository }} pr-files
  77. # Version in PR
  78. REVISION=${{ github.event.pull_request.head.sha}}
  79. # Version after merging
  80. REVISION=pull/${{ github.event.number}}/merge
  81. git -C pr-files fetch origin $REVISION
  82. git -C pr-files checkout FETCH_HEAD
  83. docker-compose pull
  84. export MODULES=${{ env.PR_MODULES }}
  85. export LOAD_MODULES=${{ env.PR_MODULES_LOAD }}
  86. EOF
  87. if [ "${{ github.event.pull_request.base.ref }}" == "10.0" ]; then
  88. cat << 'EOF'
  89. # workaround for odoo 10.0
  90. docker-compose up -d odoo
  91. docker-compose exec odoo click-odoo -i
  92. # EXEC:
  93. # env['ir.module.module'].update_list()
  94. # env.cr.commit()
  95. # exit()
  96. docker-compose stop odoo
  97. EOF
  98. fi
  99. cat << 'EOF'
  100. docker-compose up
  101. EOF
  102. # TODO: post this message when Github guys make access to post message in PR
  103. #> Sent by [DINAR :construction_worker_man:](https://github.com/itpp-labs/DINAR) via `.github/workflows/DINAR-pr.yml`
  104. - name: Check Python Version
  105. run:
  106. echo "::set-env name=PY::$(python --version --version | sha256sum | cut -d' '
  107. -f1)"
  108. - uses: actions/cache@v1
  109. with:
  110. path: ~/.cache/pre-commit
  111. key: pre-commit|${{ env.PY }}|${{ hashFiles('REPO/.pre-commit-config.yaml') }}
  112. - name: Install pre-commit
  113. run: |
  114. pip install pre-commit
  115. - name: PRE-COMMIT against updated files only
  116. run: |
  117. cd REPO
  118. git fetch origin ${{ github.event.pull_request.base.ref }}
  119. pre-commit run --show-diff-on-failure --color=always --origin HEAD --source origin/${{ github.event.pull_request.base.ref }}
  120. tests:
  121. name: "Quick Tests"
  122. runs-on: ubuntu-latest
  123. steps:
  124. - name: Checkout Repo
  125. uses: actions/checkout@v2
  126. with:
  127. path: REPO
  128. - name: Checkout DINAR
  129. uses: actions/checkout@v2
  130. with:
  131. path: DINAR
  132. repository: itpp-labs/DINAR-fork
  133. ref: master
  134. - name: Configure docker
  135. run: |
  136. bash DINAR/workflow-files/configure-docker.sh ${{ secrets.DINAR_TOKEN || secrets.GITHUB_TOKEN }}
  137. - name: Install python tools
  138. run: |
  139. pip install plumbum PyGithub pyyaml
  140. - name: Download Docker images with preinstalled modules
  141. run: |
  142. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  143. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml pull
  144. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --no-start
  145. - name: Analyze PR
  146. run: |
  147. # Get list of installed modules
  148. ODOO_BASE_MODULES=$(docker inspect \
  149. --format '{{ index .Config.Labels "dinar.odoo.modules"}}' \
  150. dinar_odoo_1)
  151. # sets environment variables that available in next steps via $ {{ env.PR_... }} notation
  152. cd REPO
  153. python ../DINAR/workflow-files/analyze-modules.py updated ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }} ${{ github.event.number }} $ODOO_BASE_MODULES
  154. - name: Install json parser
  155. run: |
  156. sudo apt-get install jq
  157. - name: Install Additional Dependencies (Modules)
  158. if: env.PR_MODULES_DEPS != ''
  159. run: |
  160. # Install new dependencies without tests
  161. export MODULES="${{ env.PR_MODULES_DEPS }}"
  162. export LOAD_MODULES="${{ env.PR_MODULES_LOAD }}"
  163. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  164. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --abort-on-container-exit
  165. - name: Install Additional Dependencies (Packages)
  166. if: env.PR_DEPS != ''
  167. run: |
  168. # TODO https://github.com/itpp-labs/DINAR/issues/42
  169. exit 1
  170. - name: Prepare DINAR with additional dependencies
  171. if: env.PR_MODULES_DEPS != '' || env.PR_DEPS != ''
  172. run: |
  173. # Save artifacts for local run and for integrations Tests
  174. bash DINAR/workflow-files/save-docker-layers.sh new-deps/
  175. echo $MODULES > new-deps/modules.txt
  176. - name: Save DINAR with dependencies
  177. if: env.PR_MODULES_DEPS != '' || env.PR_DEPS != ''
  178. uses: actions/upload-artifact@v1
  179. with:
  180. name: new-deps
  181. path: new-deps/
  182. - name: Test updated modules
  183. if: env.PR_MODULES != ''
  184. run: |
  185. export MODULES="${{ env.PR_MODULES }}"
  186. export LOAD_MODULES="${{ env.PR_MODULES_LOAD }}"
  187. export ODOO_EXTRA_ARG=--test-enable
  188. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  189. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --abort-on-container-exit
  190. tests-all:
  191. name: Integration Tests
  192. # Let Quick Review/Tests run first
  193. # This job uses artifacts from "Quick Tests"
  194. needs:
  195. - tests
  196. - review
  197. runs-on: ubuntu-latest
  198. steps:
  199. - name: Checkout Repo
  200. uses: actions/checkout@v2
  201. with:
  202. path: REPO
  203. - name: Checkout DINAR
  204. uses: actions/checkout@v2
  205. with:
  206. path: DINAR
  207. repository: itpp-labs/DINAR-fork
  208. ref: master
  209. - name: Install python tools
  210. run: |
  211. pip install plumbum pyyaml
  212. - name: Download Additional Dependencies artifact
  213. uses: actions/download-artifact@v1
  214. with:
  215. name: new-deps
  216. path: new-deps/
  217. - name: Check artifact
  218. if: failure()
  219. run: |
  220. echo "::set-env name=ARTIFACT::0"
  221. - name: Configure Docker
  222. run: |
  223. bash DINAR/workflow-files/configure-docker.sh ${{ secrets.DINAR_TOKEN || secrets.GITHUB_TOKEN }}
  224. - name: Analyze PR
  225. run: |
  226. # sets environment variables that available in next steps via $ {{ env.PR_... }} notation
  227. DEPS_MODULES=$(cat new-deps/modules.txt || true)
  228. cd REPO
  229. python ../DINAR/workflow-files/analyze-modules.py all "$DEPS_MODULES"
  230. - name: Download base images
  231. run: |
  232. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  233. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml pull
  234. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --no-start
  235. - name: Apply new-deps artifact
  236. if: env.ARTIFACT != '0'
  237. run: |
  238. bash DINAR/workflow-files/load-docker-layers.sh new-deps/
  239. - name: Test all modules
  240. run: |
  241. export MODULES="${{ env.ALL_MODULES }}"
  242. export LOAD_MODULES="${{ env.ALL_MODULES_LOAD }}"
  243. export ODOO_EXTRA_ARG=--test-enable
  244. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  245. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --abort-on-container-exit