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.

263 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 "::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 Artifact Folder
  171. run: |
  172. mkdir new-deps/
  173. # create dummy file to be sure that Artifact will be uploaded
  174. echo ok > new-deps/.empty
  175. - name: Prepare DINAR with additional dependencies
  176. if: env.PR_MODULES_DEPS != '' || env.PR_DEPS != ''
  177. run: |
  178. # Save artifacts for local run and for integrations Tests
  179. bash DINAR/workflow-files/save-docker-layers.sh new-deps/
  180. echo "${{ env.PR_MODULES_DEPS }}" > new-deps/modules.txt
  181. - name: Save DINAR with dependencies
  182. uses: actions/upload-artifact@v1
  183. with:
  184. name: new-deps
  185. path: new-deps/
  186. - name: Test updated modules
  187. if: env.PR_MODULES != ''
  188. run: |
  189. export MODULES="${{ env.PR_MODULES }}"
  190. export LOAD_MODULES="${{ env.PR_MODULES_LOAD }}"
  191. export ODOO_EXTRA_ARG=--test-enable
  192. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  193. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --abort-on-container-exit
  194. tests-all:
  195. name: Integration Tests
  196. # Let Quick Review/Tests run first
  197. # This job uses artifacts from "Quick Tests"
  198. needs:
  199. - tests
  200. - review
  201. runs-on: ubuntu-latest
  202. steps:
  203. - name: Checkout Repo
  204. uses: actions/checkout@v2
  205. with:
  206. path: REPO
  207. - name: Checkout DINAR
  208. uses: actions/checkout@v2
  209. with:
  210. path: DINAR
  211. repository: itpp-labs/DINAR-fork
  212. ref: master
  213. - name: Install python tools
  214. run: |
  215. pip install plumbum pyyaml
  216. - name: Download Additional Dependencies artifact
  217. uses: actions/download-artifact@v1
  218. with:
  219. name: new-deps
  220. path: new-deps/
  221. - name: Check artifact
  222. run: |
  223. if [ ! -f new-deps/modules.txt ]; then
  224. echo "::set-env name=ARTIFACT::empty"
  225. fi
  226. - name: Configure Docker
  227. run: |
  228. bash DINAR/workflow-files/configure-docker.sh ${{ secrets.DINAR_TOKEN || secrets.GITHUB_TOKEN }}
  229. - name: Analyze PR
  230. run: |
  231. # sets environment variables that available in next steps via $ {{ env.PR_... }} notation
  232. DEPS_MODULES=$(cat new-deps/modules.txt || true)
  233. cd REPO
  234. python ../DINAR/workflow-files/analyze-modules.py all "$DEPS_MODULES"
  235. - name: Download base images
  236. run: |
  237. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  238. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml pull
  239. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --no-start
  240. - name: Apply new-deps artifact
  241. if: env.ARTIFACT != 'empty'
  242. run: |
  243. bash DINAR/workflow-files/load-docker-layers.sh new-deps/
  244. - name: Test all modules
  245. run: |
  246. export MODULES="${{ env.ALL_MODULES }}"
  247. export LOAD_MODULES="${{ env.ALL_MODULES_LOAD }}"
  248. export ODOO_EXTRA_ARG=--test-enable
  249. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  250. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --abort-on-container-exit