update actions #294
This file contains hidden or 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: Merge | |
| 'on': | |
| push: | |
| branches: | |
| - master | |
| jobs: | |
| flatpak: | |
| name: flatpak | |
| runs-on: ubuntu-latest | |
| container: | |
| image: 'ghcr.io/flathub-infra/flatpak-github-actions:gnome-48' | |
| options: '--privileged' | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - uses: flatpak/flatpak-github-actions/flatpak-builder@v6 | |
| with: | |
| bundle: planify.Devel.flatpak | |
| manifest-path: build-aux/io.github.alainm23.planify.Devel.json | |
| cache-key: 'flatpak-builder-${{ github.sha }}' | |
| gettext: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Install gettext | |
| run: sudo apt-get update && sudo apt-get install -y gettext | |
| - name: Pull latest changes | |
| run: | | |
| git config --local user.name "Planify Bot" | |
| git config --local user.email "[email protected]" | |
| git fetch origin master | |
| git rebase origin/master || true | |
| - name: Update POTFILES and translations | |
| run: | | |
| # Regenerate POTFILES | |
| cat > po/POTFILES << 'EOF' | |
| # List of source files containing translatable strings. | |
| # Please keep this file sorted alphabetically. | |
| EOF | |
| find core -name "*.vala" | sort >> po/POTFILES | |
| echo >> po/POTFILES | |
| find src -name "*.vala" | sort >> po/POTFILES | |
| echo >> po/POTFILES | |
| find quick-add -name "*.vala" | sort >> po/POTFILES | |
| echo >> po/POTFILES | |
| echo "data/resources/ui/shortcuts.ui" >> po/POTFILES | |
| # Generate temporary POT file | |
| xgettext --files-from=po/POTFILES --directory=. \ | |
| --output=po/io.github.alainm23.planify.pot.tmp --from-code=UTF-8 \ | |
| --keyword=_ --keyword=N_ \ | |
| --package-name=io.github.alainm23.planify \ | |
| --no-location | |
| # Preserve existing metadata from old POT file | |
| if [ -f po/io.github.alainm23.planify.pot ]; then | |
| # Extract metadata from existing file | |
| POT_DATE=$(grep '^"POT-Creation-Date:' po/io.github.alainm23.planify.pot || echo '') | |
| BUGS_TO=$(grep '^"Report-Msgid-Bugs-To:' po/io.github.alainm23.planify.pot || echo '') | |
| # Replace metadata in new file with old values | |
| if [ -n "$POT_DATE" ]; then | |
| sed -i "s/^\"POT-Creation-Date:.*/$POT_DATE/" po/io.github.alainm23.planify.pot.tmp | |
| fi | |
| if [ -n "$BUGS_TO" ]; then | |
| sed -i "s/^\"Report-Msgid-Bugs-To:.*/$BUGS_TO/" po/io.github.alainm23.planify.pot.tmp | |
| fi | |
| fi | |
| mv po/io.github.alainm23.planify.pot.tmp po/io.github.alainm23.planify.pot | |
| # Update PO files preserving their metadata | |
| for lang in $(cat po/LINGUAS); do | |
| # Save existing metadata | |
| PO_DATE=$(grep '^"PO-Revision-Date:' po/$lang.po || echo '') | |
| POT_DATE=$(grep '^"POT-Creation-Date:' po/$lang.po || echo '') | |
| BUGS_TO=$(grep '^"Report-Msgid-Bugs-To:' po/$lang.po || echo '') | |
| msgmerge --update --no-fuzzy-matching --backup=none \ | |
| --no-location po/$lang.po po/io.github.alainm23.planify.pot | |
| # Restore original metadata | |
| if [ -n "$PO_DATE" ]; then | |
| sed -i "s/^\"PO-Revision-Date:.*/$PO_DATE/" po/$lang.po | |
| fi | |
| if [ -n "$POT_DATE" ]; then | |
| sed -i "s/^\"POT-Creation-Date:.*/$POT_DATE/" po/$lang.po | |
| fi | |
| if [ -n "$BUGS_TO" ]; then | |
| sed -i "s/^\"Report-Msgid-Bugs-To:.*/$BUGS_TO/" po/$lang.po | |
| fi | |
| done | |
| - name: Check for real changes | |
| id: check_changes | |
| run: | | |
| # Exclude metadata-only changes | |
| if git diff --ignore-matching-lines='^"POT-Creation-Date:' \ | |
| --ignore-matching-lines='^"PO-Revision-Date:' \ | |
| --ignore-matching-lines='^"Report-Msgid-Bugs-To:' \ | |
| --quiet po/; then | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Resolve conflicts if any | |
| run: | | |
| if [ -f po/io.github.alainm23.planify.pot ]; then | |
| git add po/io.github.alainm23.planify.pot | |
| fi | |
| git rebase --continue || true | |
| - name: Commit and push changes | |
| if: steps.check_changes.outputs.has_changes == 'true' | |
| run: | | |
| git add po/ | |
| git diff --staged --quiet || git commit -m "Update translations" | |
| git push origin master | |
| - name: Notify Weblate of changes | |
| if: steps.check_changes.outputs.has_changes == 'true' | |
| run: | | |
| curl -X POST "https://hosted.weblate.org/api/components/planner/io-github-alainm23-planify/repository/" \ | |
| -H "Authorization: Token ${{ secrets.WEBLATE_TOKEN }}" \ | |
| -H "Content-Type: application/json" \ | |
| -d '{"operation": "pull"}' |