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.

147 lines
5.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: "Port module"
  15. on:
  16. issues:
  17. types:
  18. - opened
  19. - reopened
  20. jobs:
  21. port:
  22. runs-on: ubuntu-latest
  23. if: "startsWith(github.event.issue.title, 'DINAR-PORT ')"
  24. steps:
  25. - name: Post link
  26. uses: KeisukeYamashita/create-comment@v1
  27. with:
  28. comment:
  29. "Porting is started. Check logs: https://github.com/${{ github.repository
  30. }}/actions/runs/${{ github.run_id }}"
  31. - name: Checkout DINAR
  32. uses: actions/checkout@v2
  33. with:
  34. path: DINAR
  35. repository: itpp-labs/DINAR-fork
  36. ref: master
  37. - uses: actions/setup-python@v2
  38. with:
  39. python-version: "3.7.x"
  40. - name: Install python tools
  41. run: |
  42. pip install plumbum pre-commit git-aggregator
  43. - name: Check Python Version
  44. run:
  45. echo "PY=$(python --version --version | sha256sum | cut -d' ' -f1)" >>
  46. $GITHUB_ENV
  47. - name: Analyze request
  48. env:
  49. TITLE: ${{ github.event.issue.title }}
  50. run: |
  51. # sets environment variables that available in next steps via $ {{ env.PORT_... }} notation
  52. python DINAR/workflow-files/analyze_port_trigger.py "$TITLE"
  53. - name: Checkout Repo
  54. uses: actions/checkout@v2
  55. with:
  56. path: REPO
  57. fetch-depth: 0
  58. ref: ${{ env.PORT_TO_BRANCH }}
  59. - uses: actions/cache@v1
  60. with:
  61. path: ~/.cache/pre-commit
  62. key: pre-commit|${{ env.PY }}|${{ hashFiles('REPO/.pre-commit-config.yaml') }}
  63. - name: Copy module to new branch
  64. run: |
  65. git config --global user.email "itpp-bot@users.noreply.github.com"
  66. git config --global user.name "Mitchell Admin"
  67. cd REPO
  68. if [ ! -d ${{ env.PORT_MODULE }} ]
  69. then
  70. # apply original commit history
  71. if ! git format-patch --keep-subject --stdout origin/${{ env.PORT_TO_BRANCH }}..origin/${{ env.PORT_FROM_BRANCH }} -- ${{ env.PORT_MODULE }} | git am -3 --keep
  72. then
  73. # git am failed
  74. git am --abort
  75. # just copy source
  76. git checkout origin/${{ env.PORT_FROM_BRANCH }} -- ${{ env.PORT_MODULE }}
  77. git commit -m ":tada:${{ env.PORT_FROM_BRANCH_TAGS }} ${{ env.PORT_MODULE }}
  78. previous commits history: https://github.com/${{ github.repository }}/commits/${{ env.PORT_FROM_BRANCH }}/ir_rule_protected
  79. > Made via .github/workflows/DINAR-PORT.yml"
  80. fi
  81. fi
  82. - name: make OCA/odoo-module-migrator
  83. run: |
  84. gitaggregate -c DINAR/workflow-files/odoo-module-migrator-mix.yml
  85. pip install -e ./odoo-module-migrator
  86. - name: apply OCA/odoo-module-migrator
  87. run: |
  88. LOG_FILE=../odoo-module-migrator.logs
  89. cd REPO
  90. odoo-module-migrate \
  91. --modules ${{ env.PORT_MODULE }} \
  92. --init-version-name ${{ env.PORT_FROM_BRANCH }} \
  93. --target-version-name ${{ env.PORT_TO_BRANCH }} \
  94. --no-commit \
  95. 2> $LOG_FILE || true
  96. cat $LOG_FILE
  97. # TMP: run pre-commit agains xml files only. See https://github.com/OCA/odoo-module-migrator/pull/38#pullrequestreview-558886327
  98. pre-commit run --files $(find ${{ env.PORT_MODULE }} -type f -iname "*.xml") || true
  99. # remove colors
  100. sed -r -i "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" $LOG_FILE
  101. # escape character
  102. # TODO: update KeisukeYamashita/create-comment to support reading comment's body from file
  103. echo 'MIGRATOR_LOGS<<EOF' >> $GITHUB_ENV
  104. cat $LOG_FILE >> $GITHUB_ENV
  105. echo 'EOF' >> $GITHUB_ENV
  106. git add -A
  107. git commit -m ":arrow_up:${{ env.PORT_TO_BRANCH_TAGS }} OCA/odoo-module-migrator
  108. close #${{ github.event.issue.number }}
  109. > Made via .github/workflows/DINAR-PORT.yml"
  110. - name: pre-commit
  111. run: |
  112. cd REPO
  113. pre-commit run --files $(find ${{ env.PORT_MODULE }} -type f) || true
  114. git add -A
  115. git commit -m ":rainbow: pre-commit
  116. > Made via .github/workflows/DINAR-PORT.yml" || echo "pre-commit: no changes"
  117. - name: PR
  118. uses: peter-evans/create-pull-request@v3
  119. id: cpr
  120. with:
  121. path: REPO
  122. # GITHUB_TOKEN would not trigger PR checks
  123. token: ${{ secrets.DINAR_TOKEN }}
  124. branch: ${{ env.PORT_TO_BRANCH }}-${{ env.PORT_MODULE }}
  125. title: "[${{ env.PORT_TO_BRANCH }}] ${{ env.PORT_MODULE }}"
  126. body: |
  127. Made by [DINAR](https://github.com/itpp-labs/DINAR#readme) by request in #${{ github.event.issue.number }}
  128. - name: Post logs
  129. uses: KeisukeYamashita/create-comment@v1
  130. with:
  131. number: ${{ steps.cpr.outputs.pull-request-number }}
  132. comment: |
  133. [Migrator](https://github.com/OCA/odoo-module-migrator/)'s [logs](https://github.com/${{ github.repository
  134. }}/actions/runs/${{ github.run_id }}):
  135. ```
  136. ${{ env.MIGRATOR_LOGS }}
  137. ```