generated from flaskcwg/translation-template
-
Notifications
You must be signed in to change notification settings - Fork 22
66 lines (59 loc) · 2.23 KB
/
sync.yaml
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
name: Sync
on:
workflow_dispatch:
schedule:
- cron: "0 19 * * *" # Run at 3am UTF+8 every day
jobs:
sync:
name: Sync with upstream docs
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Fetch upstream changes
id: fetch-changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git remote add upstream https://github.com/pallets/flask.git
git fetch upstream
git merge upstream/2.0.x -m "Merge upstream changes into 'main' by GitHub Actions"
# If docs/ has changes, continue below steps otherwise abort
git diff --name-only origin/main HEAD | grep -q -e '^docs/'
- name: Generate Translation
run: |
pip install -r requirements/docs.txt
pip install PyGithub
pip install -e .
cd docs
make gettext
sphinx-intl update -p _build/gettext
cd ..
git add docs/
git commit -m "Update po files by GitHub Actions"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Create issue
shell: python
run: |
import subprocess, os
from datetime import datetime
from github import Github
current_date = datetime.today().strftime(' %Y-%m-%d')
g = Github(os.getenv('GITHUB_TOKEN'))
changed = subprocess.check_output("git diff --name-only HEAD~1 HEAD | grep -e '^docs/locales/'", shell=True, text=True)
body = "## Changed po files\n\n" + "\n".join(f"- [ ] {line}" for line in changed.splitlines() if line.strip())
repo = g.get_repo(os.getenv('REPO'))
label = repo.get_label('sync')
issue = repo.create_issue(title=os.getenv('ISSUE_TITLE') + current_date, body=body, labels=[label])
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
ISSUE_TITLE: Sync translation for upstream updates