From eebe12749a52c0de33ac046deee235d83ca39b9a Mon Sep 17 00:00:00 2001 From: Bogdan Preda Date: Thu, 20 Jul 2023 13:20:42 +0300 Subject: [PATCH] chore: add translation diff job Codeinwp/themeisle#1545 chore: add diff script chore: job namespace fix chore: test diff chore: update job chore: test chore: test require review chore: update action required chore: pass test chore: output chore: fail job chore: solve translation --- .github/workflows/diff-translations.yml | 75 +++++++++++++++++++++++++ bin/pot-diff.sh | 19 +++++++ 2 files changed, 94 insertions(+) create mode 100644 .github/workflows/diff-translations.yml create mode 100755 bin/pot-diff.sh diff --git a/.github/workflows/diff-translations.yml b/.github/workflows/diff-translations.yml new file mode 100644 index 0000000..a3e8409 --- /dev/null +++ b/.github/workflows/diff-translations.yml @@ -0,0 +1,75 @@ +name: Translations Diff + +on: + pull_request_review: + pull_request: + types: [opened, edited, synchronize, ready_for_review] + branches: + - 'development' + - 'feat/translation_diff_job' + +jobs: + translation: + runs-on: ubuntu-latest + steps: + - name: Checkout Ref Base + uses: actions/checkout@v2 + with: + path: neve-fse-head + - name: Setup node 14 + uses: actions/setup-node@v1 + with: + node-version: 14.x + - name: FRESH Makepot BASE + run: | + cd neve-fse-head + ls languages/ + composer install --no-dev --prefer-dist --no-progress --no-suggest + yarn install --frozen-lockfile + yarn run build + ls languages/ + - name: Checkout Ref Head + uses: actions/checkout@v2 + with: + ref: development + path: neve-fse-base + - name: FRESH Makepot HEAD + run: | + cd neve-fse-base + ls languages/ + composer install --no-dev --prefer-dist --no-progress --no-suggest + yarn install --frozen-lockfile + yarn run build + ls languages/ + - name: Find Comment + uses: peter-evans/find-comment@v2 + id: find_coomment + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'pirate-bot' + body-includes: PR has POT difference + - name: Install PODiff + run: | + curl -o podiff.gz ftp://download.gnu.org.ua/pub/releases/podiff/podiff-1.3.tar.gz + tar -xf podiff.gz + cd podiff-1.3 + make + mkdir -p $GITHUB_WORKSPACE/bin + mv ./podiff $GITHUB_WORKSPACE/bin + echo "$GITHUB_WORKSPACE/bin" >> $GITHUB_PATH + cd .. + - name: Run Podiff + id: translation_status + run: | + ${GITHUB_WORKSPACE}/neve-fse-head/bin/pot-diff.sh ./neve-fse-base/languages/neve-fse.pot ./neve-fse-head/languages/neve-fse.pot $PERCENT_TRESHOLD + - name: Step require review + if: steps.translation_status.outputs.has_pot_diff != 'success' + uses: Automattic/action-required-review@v3 + with: + requirements: | + - name: Everything else + paths: unmatched + teams: + - "sbs" + status: Has translation changes, a review from SBS team is required + token: ${{ secrets.BOT_TOKEN }} diff --git a/bin/pot-diff.sh b/bin/pot-diff.sh new file mode 100755 index 0000000..4aea2ad --- /dev/null +++ b/bin/pot-diff.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# Set Arguments +file1="$1" +file2="$2" + +## Striping headers for file1 and file2. + +sed '/^"/d' $file1 > $file1.edited +mv $file1.edited $file1 +sed '/^"/d' ${file2} > ${file2}.edited +mv ${file2}.edited ${file2} + +if [[ $(podiff $file1 $file2) ]]; then + podiff $file1 $file2 + echo "has_pot_diff=failure" >> $GITHUB_OUTPUT +else + echo "has_pot_diff=success" >> $GITHUB_OUTPUT + echo "No differences found" +fi