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.

266 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. echo "::set-env name=PR_FILES::../../REPO"
  138. - name: Install python tools
  139. run: |
  140. pip install plumbum PyGithub pyyaml
  141. - name: Download Docker images with preinstalled modules
  142. run: |
  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 pull
  145. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --no-start
  146. - name: Analyze PR
  147. run: |
  148. # Get list of installed modules
  149. ODOO_BASE_MODULES=$(docker inspect \
  150. --format '{{ index .Config.Labels "dinar.odoo.modules"}}' \
  151. dinar_odoo_1)
  152. echo "ODOO_BASE_MODULES=$ODOO_BASE_MODULES"
  153. # sets environment variables that available in next steps via $ {{ env.PR_... }} notation
  154. cd REPO
  155. python ../DINAR/workflow-files/analyze-modules.py updated ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }} ${{ github.event.number }} $ODOO_BASE_MODULES
  156. - name: Install json parser
  157. run: |
  158. sudo apt-get install jq
  159. - name: Install Additional Dependencies (Modules)
  160. if: env.PR_MODULES_DEPS != ''
  161. run: |
  162. # Install new dependencies without tests
  163. export MODULES="${{ env.PR_MODULES_DEPS }}"
  164. export LOAD_MODULES="${{ env.PR_MODULES_LOAD }}"
  165. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  166. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --abort-on-container-exit
  167. - name: Install Additional Dependencies (Packages)
  168. if: env.PR_DEPS != ''
  169. run: |
  170. # TODO https://github.com/itpp-labs/DINAR/issues/42
  171. exit 1
  172. - name: Prepare Artifact Folder
  173. run: |
  174. mkdir new-deps/
  175. # create dummy file to be sure that Artifact will be uploaded
  176. echo ok > new-deps/.empty
  177. - name: Prepare DINAR with additional dependencies
  178. if: env.PR_MODULES_DEPS != '' || env.PR_DEPS != ''
  179. run: |
  180. # Save artifacts for local run and for integrations Tests
  181. bash DINAR/workflow-files/save-docker-layers.sh new-deps/
  182. echo "${{ env.PR_MODULES_DEPS }}" > new-deps/modules.txt
  183. - name: Save DINAR with dependencies
  184. uses: actions/upload-artifact@v1
  185. with:
  186. name: new-deps
  187. path: new-deps/
  188. - name: Test updated modules
  189. if: env.PR_MODULES != ''
  190. run: |
  191. export MODULES="${{ env.PR_MODULES }}"
  192. export LOAD_MODULES="${{ env.PR_MODULES_LOAD }}"
  193. export ODOO_EXTRA_ARG=--test-enable
  194. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  195. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --abort-on-container-exit
  196. tests-all:
  197. name: Integration Tests
  198. # Let Quick Review/Tests run first
  199. # This job uses artifacts from "Quick Tests"
  200. needs:
  201. - tests
  202. - review
  203. runs-on: ubuntu-latest
  204. steps:
  205. - name: Checkout Repo
  206. uses: actions/checkout@v2
  207. with:
  208. path: REPO
  209. - name: Checkout DINAR
  210. uses: actions/checkout@v2
  211. with:
  212. path: DINAR
  213. repository: itpp-labs/DINAR-fork
  214. ref: master
  215. - name: Install python tools
  216. run: |
  217. pip install plumbum pyyaml
  218. - name: Download Additional Dependencies artifact
  219. uses: actions/download-artifact@v1
  220. with:
  221. name: new-deps
  222. path: new-deps/
  223. - name: Check artifact
  224. run: |
  225. if [ ! -f new-deps/modules.txt ]; then
  226. echo "::set-env name=ARTIFACT::empty"
  227. fi
  228. - name: Configure Docker
  229. run: |
  230. bash DINAR/workflow-files/configure-docker.sh ${{ secrets.DINAR_TOKEN || secrets.GITHUB_TOKEN }}
  231. echo "::set-env name=PR_FILES::../../REPO"
  232. - name: Analyze PR
  233. run: |
  234. # sets environment variables that available in next steps via $ {{ env.PR_... }} notation
  235. DEPS_MODULES=$(cat new-deps/modules.txt || true)
  236. cd REPO
  237. python ../DINAR/workflow-files/analyze-modules.py all "$DEPS_MODULES"
  238. - name: Download base images
  239. run: |
  240. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  241. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml pull
  242. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --no-start
  243. - name: Apply new-deps artifact
  244. if: env.ARTIFACT != 'empty'
  245. run: |
  246. bash DINAR/workflow-files/load-docker-layers.sh new-deps/
  247. - name: Test all modules
  248. run: |
  249. export MODULES="${{ env.ALL_MODULES }}"
  250. export LOAD_MODULES="${{ env.ALL_MODULES_LOAD }}"
  251. export ODOO_EXTRA_ARG=--test-enable
  252. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml config
  253. docker-compose -p DINAR -f DINAR/workflow-files/docker-compose-DINAR-pr.yml up --abort-on-container-exit