-
Notifications
You must be signed in to change notification settings - Fork 261
146 lines (139 loc) · 5.47 KB
/
DINAR-PORT.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Copyright 2020 IT Projects Labs
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: "Port module"
on:
issues:
types:
- opened
- reopened
jobs:
port:
runs-on: ubuntu-latest
if: "startsWith(github.event.issue.title, 'DINAR-PORT ')"
steps:
- name: Post link
uses: KeisukeYamashita/create-comment@v1
with:
comment:
"Porting is started. Check logs: https://github.com/${{ github.repository
}}/actions/runs/${{ github.run_id }}"
- name: Checkout DINAR
uses: actions/checkout@v2
with:
path: DINAR
repository: itpp-labs/DINAR-fork
ref: master
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install python tools
run: |
pip install plumbum pre-commit git-aggregator
- name: Check Python Version
run:
echo "PY=$(python --version --version | sha256sum | cut -d' ' -f1)" >>
$GITHUB_ENV
- name: Analyze request
env:
TITLE: ${{ github.event.issue.title }}
run: |
# sets environment variables that available in next steps via $ {{ env.PORT_... }} notation
python DINAR/workflow-files/analyze_port_trigger.py "$TITLE"
- name: Checkout Repo
uses: actions/checkout@v2
with:
path: REPO
fetch-depth: 0
ref: ${{ env.PORT_TO_BRANCH }}
- uses: actions/cache@v1
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('REPO/.pre-commit-config.yaml') }}
- name: Copy module to new branch
run: |
git config --global user.email "[email protected]"
git config --global user.name "Mitchell Admin"
cd REPO
if [ ! -d ${{ env.PORT_MODULE }} ]
then
# apply original commit history
if ! git format-patch --keep-subject --stdout origin/${{ env.PORT_TO_BRANCH }}..origin/${{ env.PORT_FROM_BRANCH }} -- ${{ env.PORT_MODULE }} | git am -3 --keep
then
# git am failed
git am --abort
fi
fi
if [ ! -d ${{ env.PORT_MODULE }} ]
then
# just copy source
git checkout origin/${{ env.PORT_FROM_BRANCH }} -- ${{ env.PORT_MODULE }}
git commit -m ":tada:${{ env.PORT_FROM_BRANCH_TAGS }} ${{ env.PORT_MODULE }}
previous commits history: https://github.com/${{ github.repository }}/commits/${{ env.PORT_FROM_BRANCH }}/${{ env.PORT_MODULE }}
> Made via .github/workflows/DINAR-PORT.yml"
fi
- name: make OCA/odoo-module-migrator
run: |
gitaggregate -c DINAR/workflow-files/odoo-module-migrator-mix.yml
pip install -e ./odoo-module-migrator
- name: apply OCA/odoo-module-migrator
run: |
LOG_FILE=../odoo-module-migrator.logs
cd REPO
odoo-module-migrate \
--modules ${{ env.PORT_MODULE }} \
--init-version-name ${{ env.PORT_FROM_BRANCH }} \
--target-version-name ${{ env.PORT_TO_BRANCH }} \
--no-commit \
--no-pre-commit \
2> $LOG_FILE || true
cat $LOG_FILE
# remove colors
sed -r -i "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" $LOG_FILE
# escape character
# TODO: update KeisukeYamashita/create-comment to support reading comment's body from file
echo 'MIGRATOR_LOGS<<EOF' >> $GITHUB_ENV
cat $LOG_FILE >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
git add -A
git commit -m ":arrow_up:${{ env.PORT_TO_BRANCH_TAGS }} OCA/odoo-module-migrator
close #${{ github.event.issue.number }}
> Made via .github/workflows/DINAR-PORT.yml"
- name: pre-commit
run: |
cd REPO
pre-commit run --files $(find ${{ env.PORT_MODULE }} -type f) || true
git add -A
git commit -m ":rainbow: pre-commit
> Made via .github/workflows/DINAR-PORT.yml" || echo "pre-commit: no changes"
- name: PR
uses: peter-evans/create-pull-request@v3
id: cpr
with:
path: REPO
# GITHUB_TOKEN would not trigger PR checks
token: ${{ secrets.DINAR_TOKEN }}
branch: ${{ env.PORT_TO_BRANCH }}-${{ env.PORT_MODULE }}
title: "[${{ env.PORT_TO_BRANCH }}] ${{ env.PORT_MODULE }}"
body: |
Made by [DINAR](https://github.com/itpp-labs/DINAR#readme) by request in #${{ github.event.issue.number }}
- name: Post logs
uses: KeisukeYamashita/create-comment@v1
with:
number: ${{ steps.cpr.outputs.pull-request-number }}
comment: |
[Migrator](https://github.com/OCA/odoo-module-migrator/)'s [logs](https://github.com/${{ github.repository
}}/actions/runs/${{ github.run_id }}):
```
${{ env.MIGRATOR_LOGS }}
```