diff --git a/.github/workflows/gettext.yml b/.github/workflows/gettext.yml index 7645827..679c025 100644 --- a/.github/workflows/gettext.yml +++ b/.github/workflows/gettext.yml @@ -5,66 +5,89 @@ on: branches: - main paths: + - '**.blp' - '**.vala' + - 'com.cassidyjames.dippi.json' - 'data/launcher.desktop.in' - 'data/metainfo.appdata.xml.in' - - 'po/LINGUAS' - - 'po/POTFILES.in' - - 'po/extra/LINGUAS' - - 'po/extra/POTFILES.in' + - 'po/POTFILES' + - 'po/extra/POTFILES' - '.github/workflows/gettext.yml' + workflow_dispatch: permissions: contents: write -concurrency: +concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: - build: + gettext: runs-on: ubuntu-latest container: - image: fedora:43 + image: ghcr.io/flathub-infra/flatpak-github-actions:gnome-51 + options: --privileged + env: + MANIFEST: com.cassidyjames.dippi.json + MODULE: dippi + BUILD_DIR: /tmp/gettext-build + STATE_DIR: /tmp/gettext-state steps: - - name: Install deps - run: | - sudo dnf update -y - sudo dnf install -y \ - appstream-devel \ - blueprint-compiler \ - gettext-devel \ - git \ - gtk4-devel \ - libadwaita-devel \ - libxml2-devel \ - meson \ - vala - - name: Checkout - uses: actions/checkout@v4 - with: - token: ${{ secrets.GITHUB_TOKEN }} + uses: actions/checkout@v7 - - name: Build + - name: Prepare build environment run: | - rm -rf _build - meson _build - ninja -C _build + flatpak-builder "$BUILD_DIR" "$MANIFEST" \ + --disable-rofiles-fuse \ + --force-clean \ + --install-deps-from=flathub \ + --state-dir="$STATE_DIR" \ + --stop-at="$MODULE" - name: Regenerate translation files run: | - ninja -C _build com.cassidyjames.dippi-pot - ninja -C _build com.cassidyjames.dippi-update-po + flatpak-builder "$BUILD_DIR" "$MANIFEST" \ + --disable-rofiles-fuse \ + --force-clean \ + --state-dir="$STATE_DIR" \ + --build-shell="$MODULE" <<'EOF' + set -e + # flatpak-builder 1.4 configures before opening the shell; newer versions don't + [ -f _flatpak_build/build.ninja ] || meson setup _flatpak_build + ninja -C _flatpak_build \ + com.cassidyjames.dippi-pot \ + com.cassidyjames.dippi-update-po \ + extra-pot \ + extra-update-po + touch .gettext-done + EOF + + # Fail if the build shell didn't finish regenerating everything + SOURCE_DIR="$STATE_DIR/build/$MODULE" + test -f "$SOURCE_DIR/.gettext-done" - - name: Commit - continue-on-error: true + cp "$SOURCE_DIR"/po/*.pot "$SOURCE_DIR"/po/*.po po/ + cp "$SOURCE_DIR"/po/extra/*.pot "$SOURCE_DIR"/po/extra/*.po po/extra/ + + - name: Commit and push run: | - # FILES_CHANGED=$(git diff --name-only | wc -l) - # if [[ $FILES_CHANGED != 0 ]]; then git config --global --add safe.directory "$GITHUB_WORKSPACE" - git config --global user.email "actions@github.com" - git config --global user.name "GitHub Actions" - git commit -am "Update translation files" + + # Skip churn from source line references and timestamps + CHANGES=$(git diff --unified=0 -- '*.pot' \ + | grep '^[+-]' \ + | grep --invert-match '^\(+++\|---\|[+-]#:\|[+-]"POT-Creation-Date:\)' \ + || true) + if [ -z "$CHANGES" ]; then + echo "Translatable strings are unchanged; nothing to commit." + exit 0 + fi + + echo "$CHANGES" + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + git add po + git commit --message "po: Update translation files" git push - # fi