Skip to content

Commit 7fca4f2

Browse files
authored
Merge pull request #13 from python-docs-tr/CI
Set up CI for wrapping ``.po`` files on pull requests.
2 parents e470c39 + 57a9e56 commit 7fca4f2

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

.github/workflows/wrap.yml

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: "Wrap"
2+
3+
on:
4+
pull_request:
5+
branches: [ "**" ]
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
11+
strategy:
12+
matrix:
13+
# Run in all these versions of Python
14+
python-version: ["3.10"]
15+
16+
steps:
17+
# Checkout the latest code from the repo
18+
- name: Checkout repo
19+
uses: actions/checkout@v2
20+
with:
21+
fetch-depth: 0
22+
23+
# Setup which version of Python to use
24+
- name: Set Up Python ${{ matrix.python-version }}
25+
uses: actions/setup-python@v2
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
29+
# Display the Python version being used
30+
- name: Display Python version
31+
run: python -c "import sys; print(sys.version)"
32+
33+
# Update pip
34+
- name: Update pip
35+
run: python -m pip install --upgrade pip
36+
37+
# Install requirements.
38+
- name: Install requirements
39+
run: python -m pip install --upgrade -r requirements.txt
40+
41+
# Install dependencies
42+
- name: Install dependencies
43+
run: sudo apt install gettext
44+
45+
# Detect changed files
46+
- name: Detect changed files
47+
run: echo "CHANGED_FILES=$(git diff --name-only ${{ github.event.before }}..${{ github.event.after }} | tr '\n' ' ')" >> $GITHUB_ENV
48+
49+
# Wrap changed files
50+
- name: Wrap
51+
run: |
52+
array=($CHANGED_FILES)
53+
len=${#array[@]}
54+
if [[ $len -eq 0 ]]; then
55+
echo "No files to wrap"
56+
else
57+
for file in ${CHANGED_FILES}; do
58+
if [[ $file == *.po ]]; then
59+
echo "Wrapping $file"
60+
powrap $file
61+
fi
62+
done
63+
fi
64+
65+
# Detect changed files
66+
- name: Detect changed files
67+
run: echo "WRAPPED=$(git diff --name-only | tr '\n' ' ')" >> $GITHUB_ENV
68+
69+
# Commit changes
70+
- name: Commit changes
71+
run: |
72+
array=($WRAPPED)
73+
len=${#array[@]}
74+
if [[ $len -eq 0 ]]; then
75+
echo "No files to commit"
76+
echo "WRAPPED=False" >> $GITHUB_ENV
77+
else
78+
echo "Committing changes"
79+
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
80+
git config --local user.name "github-actions[bot]"
81+
git add ${WRAPPED}
82+
git commit -m "Wrap translations"
83+
echo "WRAPPED=True" >> $GITHUB_ENV
84+
fi
85+
86+
# Push changes
87+
- name: Push changes
88+
if: env.WRAPPED == 'True'
89+
uses: ad-m/github-push-action@master
90+
with:
91+
github_token: ${{ secrets.GITHUB_TOKEN }}
92+
branch: ${{ github.event.pull_request.head.ref }}

0 commit comments

Comments
 (0)