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