Skip to content

Sync Transifex

Sync Transifex #969

Workflow file for this run

# Secrets:
# transifex_apikey = xxx
name: Sync Transifex
on:
workflow_dispatch:
schedule: [ { cron: 0 20 * * * } ] # 每天 20:00 UTC (04:00 UTC+8) 执行
jobs:
main:
runs-on: ubuntu-latest
defaults: { run: { shell: 'bash --noprofile --norc -eo pipefail {0}' } }
steps:
- name: git clone
uses: actions/checkout@v3
- name: download
run: |
api () { curl -fsS -m600 -H 'content-type: application/vnd.api+json' -H 'authorization: Bearer ${{ secrets.transifex_apikey }}' "${@}"; }
# request
url="$( api 'https://rest.api.transifex.com/resource_translations_async_downloads' --data-raw '{"data":{"attributes":{"content_encoding":"text","file_type":"default","mode":"default"},"relationships":{"language":{"data":{"id":"l:zh_CN","type":"languages"}},"resource":{"data":{"id":"o:cataclysm-dda-translators:p:cataclysm-dda:r:master-cataclysm-dda","type":"resources"}}},"type":"resource_translations_async_downloads"}}' |
jq -Mrc '.data.links.self' )"
# get url
while [[ ! "${location}" ]]; do
(( timeout <= 600 )) || { echo 'timeout 600' >&2; exit 1; }
(( timeout += 2 )); sleep 2
location="$( api -w '%{redirect_url}' -o /dev/null "${url}" )"
done
# download
mv po po_old
curl -fsSL -m600 -o po "${location}"
- name: check & upload
id: commit
run: |
git diff --quiet -- po && exit # not changed
pip3 install polib; ./check.py po_old po; [[ -f fix.html ]] && { need_fix=', and need fix'; echo 'need_fix=1' >>"${GITHUB_OUTPUT}"; }
git add po
git -c user.name='bot' -c user.email='' commit -m "sync po${need_fix}"
git push
- if: ${{ steps.commit.outputs.need_fix }}
name: upload check result
uses: actions/upload-artifact@v3
with:
name: fix
path: fix.html