Skip to content

StefanVanDyck is checking for translations updates #23

StefanVanDyck is checking for translations updates

StefanVanDyck is checking for translations updates #23

name: Update translations
run-name: ${{ github.actor }} is checking for translations updates
on:
workflow_dispatch:
permissions:
contents: write
jobs:
update-translations:
runs-on: [ self-hosted ]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: Install Crowdin CLI
run: |
set -e -o pipefail -x
curl -sSLO https://github.com/crowdin/crowdin-cli/releases/latest/download/crowdin-cli.zip -z crowdin-cli.zip -o crowdin-cli.zip
unzip -j crowdin-cli.zip '*/crowdin-cli.jar'
rm crowdin-cli.zip
mkdir $HOME/.bin || true
mv crowdin-cli.jar $HOME/.bin/crowdin-cli.jar
cat <<EOF > $HOME/.bin/crowdin
#!/bin/bash
exec java -jar '$HOME/.bin/crowdin-cli.jar' "\$@" --no-progress
EOF
chmod +x $HOME/.bin/crowdin
echo "$HOME/.bin" >> $GITHUB_PATH
- name: Create commit
id: update-translations
env:
CROWDIN_TOKEN: ${{ secrets.CROWDIN_TOKEN }}
run: |
set -e -o pipefail
git checkout update-translations || git checkout -b update-translations
./scripts/update-translations.sh
git config --global user.email "support.natuurdata@inbo.be"
git config --global user.name "Github Actions"
if [ -n "$(git status --porcelain)" ]; then
git add '**/crowdin/messages*.properties'
git commit -m "Github actions: automated update of translations"
git push --set-upstream origin update-translations
echo "changes=true" >> "$GITHUB_OUTPUT"
else
echo "no changes";
echo "changes=false" >> "$GITHUB_OUTPUT"
fi
- name: Create Pull Request
uses: actions/github-script@v7
if: steps.update-translations.outputs.changes == 'true'
with:
github-token: ${{ secrets.GIT_PAT_TOKEN }}
script: |
const openPrs = await github.rest.pulls.list({
owner: 'inbo',
repo: 'vlaams-biodiversiteitsportaal',
state: 'open',
head: 'inbo:update-translations'
});
if (openPrs.data.length === 1) {
console.log(`PR already exists: ${openPrs.data[0].html_url}`);
return;
}
const result = await github.rest.pulls.create({
title: 'Update crowdin translations',
owner: 'inbo',
repo: 'vlaams-biodiversiteitsportaal',
head: 'update-translations',
base: '${{ github.ref_name }}',
body: 'This PR is auto-generated by [a github action](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) in [inbo/vlaams-biodiversiteitsportaal](https://github.com/inbo/vlaams-biodiversiteitsportaal).'
});
github.rest.issues.addLabels({
owner: 'inbo',
repo: 'vlaams-biodiversiteitsportaal',
issue_number: result.data.number,
labels: ['translation', 'automated pr']
});