Update translations #40231
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update translations | |
on: | |
schedule: | |
- cron: "*/15 * * * *" | |
workflow_dispatch: | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
translate: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install po4a | |
run: | | |
git -C $HOME clone --single-branch --recurse-submodules --shallow-submodules --no-tags --depth=1 https://github.com/mquinson/po4a | |
git -C $HOME/po4a fetch --no-tags --depth=1 origin 5766962c0c67703d68d45c02da13600adbf08e61 | |
git -C $HOME/po4a checkout 5766962c0c67703d68d45c02da13600adbf08e61 | |
git -C $HOME/po4a branch -D @{-1} | |
mkdir -p $HOME/.local/bin | |
echo '#!/bin/bash | |
PERLLIB='"$HOME"'/po4a/lib '"$HOME"'/po4a/po4a "$@"' > $HOME/.local/bin/po4a | |
chmod +x $HOME/.local/bin/po4a | |
sudo apt update -y | |
sudo apt install -y liblocale-gettext-perl libtext-wrapi18n-perl libunicode-linebreak-perl libtest-pod-perl libyaml-tiny-perl cpanminus gettext libsgmls-perl libsyntax-keyword-try-perl | |
cpanm Locale::gettext http://search.cpan.org/CPAN/authors/id/R/RA/RAAB/SGMLSpm-1.1.tar.gz Text::WrapI18N Unicode::GCString YAML::Tiny | |
cpanm -v --installdeps --notest $HOME/po4a | |
- name: Fetch source files | |
run: | | |
mkdir $HOME/repos | |
echo "docs\ndl-librescore\napp-librescore\nwebmscore-pwa" | xargs -I {} bash -c "curl -s -d '{\"lock\":\"true\"}' -H 'Content-Type: application/json' -H 'Authorization: Token ${{ secrets.WEBLATE_TOKEN }}' https://weblate.librescore.org/api/components/librescore/{}/lock/" | |
curl -s -d '{"operation":"commit"}' -H "Content-Type: application/json" -H "Authorization: Token ${{ secrets.WEBLATE_TOKEN }}" https://weblate.librescore.org/api/components/librescore/repository/ | |
curl -s -d '{"operation":"push"}' -H "Content-Type: application/json" -H "Authorization: Token ${{ secrets.WEBLATE_TOKEN }}" https://weblate.librescore.org/api/components/librescore/repository/ | |
curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/orgs/LibreScore/repos?per_page=100" | grep -e 'git_url*' | cut -d \" -f 4 | sed -e 's/^git:\/\//https:\/\/${{ secrets.LIBRESCORE_USERNAME }}:${{ secrets.LIBRESCORE_TOKEN }}@/g' | xargs -I {} bash -c "if [[ {} =~ /(docs|dl-librescore|app-librescore|webmscore-pwa).git$ ]]; then git -C $HOME/repos clone {} --single-branch --no-tags --depth=1 ; fi" | |
rm -R -f $HOME/repos/*/docs | |
rm -R -f $HOME/repos/docs/i18n | |
mv -f $HOME/repos/docs/source/titles $HOME/repos/titles || echo "failed=true" >> $GITHUB_ENV | |
rm -R -f $HOME/repos/docs/source | |
find $HOME/repos -not -path "$HOME/repos/titles/*" ! -name "*.md" -type f -delete | |
find $HOME/repos -not -path "$HOME/repos/titles/*" -type d -empty -delete | |
- uses: actions/checkout@v3 | |
if: env.failed != 'true' | |
- name: Generate translations | |
if: env.failed != 'true' | |
run: | | |
rm -R -f source/* | |
mv -f $HOME/repos/* source/ | |
rm -R -f $HOME/repos | |
/bin/bash ./po4a.sh | |
- name: Push to current repo | |
if: env.failed != 'true' | |
run: | | |
mkdir -p ./docs | |
rm -R -f ./docs/* | |
cp -a ./i18n/docs/* ./docs/ -v | |
cp -a ./i18n/docs/en/* . -v | |
if [[ -n $(git status -z --porcelain ./i18n) ]]; then | |
echo "updated=true" >> $GITHUB_ENV | |
git config user.name github-actions | |
git config user.email [email protected] | |
git add -A | |
git commit -m "chore: update translations" | |
git push | |
curl -s -d '{"operation":"pull"}' -H "Content-Type: application/json" -H "Authorization: Token ${{ secrets.WEBLATE_TOKEN }}" https://weblate.librescore.org/api/components/librescore/docs/repository/ | |
curl -s -d '{"lock":"false"}' -H "Content-Type: application/json" -H "Authorization: Token ${{ secrets.WEBLATE_TOKEN }}" https://weblate.librescore.org/api/components/librescore/docs/lock/ | |
fi | |
- name: Push to remote repos | |
if: env.failed != 'true' | |
run: | | |
shopt -s nullglob | |
for dir in i18n/*/ ; do | |
dir=${dir%/} | |
repo=${dir#*/} | |
repo=${repo%/} | |
if ! [[ $repo =~ ^(docs|titles)$ ]]; then | |
git -C $HOME clone --single-branch --no-tags --depth=1 https://${{ secrets.LIBRESCORE_USERNAME }}:${{ secrets.LIBRESCORE_TOKEN }}@github.com/LibreScore/$repo | |
mkdir -p $HOME/$repo/docs | |
rm -R -f $HOME/$repo/docs/* | |
cp -a $dir/* $HOME/$repo/docs/ -v | |
cp -a $dir/en/* $HOME/$repo/ -v | |
cd $HOME/$repo | |
if [[ -n $(git status -z --porcelain) ]]; then | |
echo "updated=true" >> $GITHUB_ENV | |
git config user.name github-actions | |
git config user.email [email protected] | |
git add -A | |
git commit -m "chore: update translations" | |
git push | |
curl -s -d '{"operation":"pull"}' -H "Content-Type: application/json" -H "Authorization: Token ${{ secrets.WEBLATE_TOKEN }}" https://weblate.librescore.org/api/components/librescore/$repo/repository/ | |
curl -s -d '{"lock":"false"}' -H "Content-Type: application/json" -H "Authorization: Token ${{ secrets.WEBLATE_TOKEN }}" https://weblate.librescore.org/api/components/librescore/$repo/lock/ | |
fi | |
cd $GITHUB_WORKSPACE | |
fi | |
done | |
shopt -u nullglob | |
- name: Delete workflow run | |
if: env.updated != 'true' | |
run: | | |
curl -s -i -u ${{ secrets.LIBRESCORE_USERNAME }}:${{ secrets.LIBRESCORE_TOKEN }} -d '{"event_type":"delete_action","client_payload":{"run_id":"'"${{ github.run_id }}"'","repo":"LibreScore/docs"}}' -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/LibreScore/actions/dispatches |