|
| 1 | +name: run-po4a |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - '**.po' |
| 7 | + - '**.pot' |
| 8 | + - '**.md' #temp for all md files. |
| 9 | + branches: po4a-testing |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + run_on_all: |
| 13 | + description: 'Run po4a on all files' |
| 14 | + required: false |
| 15 | + default: 'false' |
| 16 | + |
| 17 | +jobs: |
| 18 | + changed_files: |
| 19 | + runs-on: ubuntu-latest # windows-latest || macos-latest |
| 20 | + permissions: |
| 21 | + # Give the default GITHUB_TOKEN write permission to commit and push the changed files back to the repository. |
| 22 | + contents: write |
| 23 | + pull-requests: write |
| 24 | + name: Test changed-files |
| 25 | + steps: |
| 26 | + - name: Clone po4a repository at specific commit |
| 27 | + run: | |
| 28 | + git clone https://github.com/mquinson/po4a.git |
| 29 | + cd po4a |
| 30 | + git checkout v0.69 |
| 31 | + |
| 32 | + - name: Install Debian dependencies |
| 33 | + run: | |
| 34 | + sudo apt update |
| 35 | + sudo apt install -y liblocale-gettext-perl libtext-wrapi18n-perl libunicode-linebreak-perl libpod-parser-perl libtest-pod-perl libyaml-tiny-perl libsyntax-keyword-try-perl |
| 36 | + sudo apt install -y cpanminus gettext docbook-xml docbook-xsl docbook xsltproc |
| 37 | + sudo apt install -y texlive-binaries texlive-latex-base opensp libsgmls-perl |
| 38 | + |
| 39 | + - name: Install CPAN dependencies |
| 40 | + run: | |
| 41 | + cpanm Locale::gettext |
| 42 | + cpanm http://search.cpan.org/CPAN/authors/id/R/RA/RAAB/SGMLSpm-1.1.tar.gz |
| 43 | + cpanm Text::WrapI18N |
| 44 | + cpanm Unicode::GCString |
| 45 | + cd po4a |
| 46 | + cpanm -v --installdeps --notest . |
| 47 | + |
| 48 | + - name: Build |
| 49 | + run: | |
| 50 | + cd po4a |
| 51 | + perl Build.PL |
| 52 | + COLUMNS=120 ./Build verbose=1 |
| 53 | + |
| 54 | + - name: Install po4a |
| 55 | + run: | |
| 56 | + cd po4a |
| 57 | + sudo ./Build install |
| 58 | + cd .. |
| 59 | + rm -rf po4a |
| 60 | +
|
| 61 | + - uses: actions/checkout@v4 |
| 62 | + with: |
| 63 | + ref: ${{ github.head }} |
| 64 | + fetch-depth: 0 # OR "2" -> To retrieve the preceding commit. |
| 65 | + |
| 66 | + - name: Get changed files |
| 67 | + id: changed-files |
| 68 | + uses: tj-actions/changed-files@v44 |
| 69 | + # NOTE: `since_last_remote_commit: true` is implied by default and falls back to the previous local commit. |
| 70 | + - name: Run step if po/pot files are changed |
| 71 | + env: |
| 72 | + ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} |
| 73 | + RUN_ON_ALL: ${{ github.event.inputs.run_on_all }} |
| 74 | + run: | |
| 75 | + RUN_ON_ALL=${RUN_ON_ALL:="false"} |
| 76 | + ALL_CHANGED_FILES_ARRAY=() |
| 77 | + CHANGED_MD_FILES_ARRAY=() |
| 78 | + |
| 79 | + # Check if RUN_ON_ALL is set to 'true' |
| 80 | + if [ "$RUN_ON_ALL" == "true" ]; then |
| 81 | + echo "list of all .md files in user-guides and moneropedia..." |
| 82 | + |
| 83 | + # Add all user-guides and moneropedia .md files |
| 84 | + for guide in _i18n/en/resources/user-guides/*.md; do |
| 85 | + echo "-> Adding ${guide} to file list" |
| 86 | + ALL_CHANGED_FILES_ARRAY+=("${guide}") |
| 87 | + done |
| 88 | + |
| 89 | + for entry in _i18n/en/resources/moneropedia/*.md; do |
| 90 | + echo "-> Adding ${entry} to file list" |
| 91 | + ALL_CHANGED_FILES_ARRAY+=("${entry}") |
| 92 | + done |
| 93 | + else |
| 94 | + echo "Running po4a on modified po/pot files only..." |
| 95 | + |
| 96 | + # Split ALL_CHANGED_FILES into an array |
| 97 | + IFS=' ' read -r -a ALL_CHANGED_FILES_ARRAY <<< "$ALL_CHANGED_FILES" |
| 98 | + for file in "${ALL_CHANGED_FILES_ARRAY[@]}"; do |
| 99 | + if [[ "$file" == *.po || "$file" == *.pot ]]; then |
| 100 | + directory=$(echo "$file" | sed -E 's|_i18n/[^/]+/resources/([^/]+)/.*|\1|') |
| 101 | + base_filename=$(basename "$file" | sed -E 's/\.(po|pot)$//') |
| 102 | + md_file="_i18n/en/resources/${directory}/${base_filename}.md" |
| 103 | + if [ -f "$md_file" ]; then |
| 104 | + echo "-> Adding ${md_file} to file list" |
| 105 | + CHANGED_MD_FILES_ARRAY+=("${md_file}") |
| 106 | + fi |
| 107 | + else |
| 108 | + CHANGED_MD_FILES_ARRAY+=("${file}") |
| 109 | + fi |
| 110 | + #remove duplicates |
| 111 | + ALL_CHANGED_FILES_ARRAY=($(printf "%s\n" "${CHANGED_MD_FILES_ARRAY[@]}" | sort -u)) |
| 112 | +
|
| 113 | + done |
| 114 | + fi |
| 115 | + for file in ${ALL_CHANGED_FILES_ARRAY}; do |
| 116 | + echo "$file was changed" |
| 117 | + done |
| 118 | + git config --global user.name "weblate-po4a" |
| 119 | + git config --global user.email "weblate-po4a@example.com" |
| 120 | + ERROR=0 |
| 121 | + for md_file in "${ALL_CHANGED_FILES_ARRAY[@]}"; do |
| 122 | + cd po |
| 123 | + # Determine the base directory and base filename |
| 124 | + directory=$(echo "$md_file" | sed -E 's|_i18n/[^/]+/resources/([^/]+)/.*|\1|') |
| 125 | + base_filename=$(basename "$md_file" | sed -E 's/\.md$//') |
| 126 | + |
| 127 | + # Construct the po4a configuration dynamically |
| 128 | + lang=$(echo "$md_file" | sed -E 's|_i18n/([^/]+)/resources/.*|\1|') |
| 129 | + if [ "$RUN_ON_ALL" == "true" ] || [ "$lang" == "en" ]; then |
| 130 | + po4a_config="[po4a_langs] es it pl fr ar ru de nl pt-br tr zh-cn zh-tw nb-no\n" |
| 131 | + else |
| 132 | + po4a_config="[po4a_langs] ${lang}\n" |
| 133 | + fi |
| 134 | + po4a_config+="[po4a_paths] ../_i18n/en/resources/${directory}/weblate/${base_filename}.pot \$lang:../_i18n/\$lang/resources/${directory}/weblate/${base_filename}.po\n" |
| 135 | + po4a_config+="[options] opt:\"--keep=0\"\n" |
| 136 | + po4a_config+="[options] opt:\"--localized-charset=UTF-8\"\n" |
| 137 | + po4a_config+="[options] opt:\"--master-charset=UTF-8\"\n" |
| 138 | + po4a_config+="[options] opt:\"--master-language=en_US\"\n" |
| 139 | + po4a_config+="[options] opt:\"--msgmerge-opt='--no-wrap'\"\n" |
| 140 | + po4a_config+="[options] opt:\"--wrap-po=newlines\"\n" |
| 141 | + po4a_config+="[po4a_alias:markdown] text opt:\"--option markdown\"\n" |
| 142 | + po4a_config+="[type: markdown] ../_i18n/en/resources/${directory}/${base_filename}.md \$lang:../_i18n/\$lang/resources/${directory}/${base_filename}.md\n" |
| 143 | + |
| 144 | + echo -e "${po4a_config}" > po4a-config.txt |
| 145 | + cat po4a-config.txt |
| 146 | +
|
| 147 | + if po4a po4a-config.txt; then |
| 148 | + echo "po4a ran successfully on ${md_file}" |
| 149 | + else |
| 150 | + echo "::warning file=${md_file}::po4a didn't run successfully" |
| 151 | + ERROR=1 |
| 152 | + fi |
| 153 | + rm po4a-config.txt |
| 154 | + cd .. |
| 155 | + git add . |
| 156 | + COMMIT_MESSAGE="po4a: ${directory}/${base_filename} updates" |
| 157 | + git commit -m "${COMMIT_MESSAGE}" || echo "No changes to commit for ${directory}/${base_filename}" |
| 158 | + done |
| 159 | +
|
| 160 | + #- name: Check if PR exists |
| 161 | + # id: check |
| 162 | + # env: |
| 163 | + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 164 | + # run: | |
| 165 | + # prs=$(gh pr list \ |
| 166 | + # --repo "$GITHUB_REPOSITORY" \ |
| 167 | + # --head 'po4a-staged' \ |
| 168 | + # --base 'master' \ |
| 169 | + # --json title \ |
| 170 | + # --jq 'length') |
| 171 | + # if ((prs > 0)); then |
| 172 | + # echo "skip=true" >> "$GITHUB_OUTPUT" |
| 173 | + # fi |
| 174 | + |
| 175 | + - name: push to po4a-testing |
| 176 | + #if: 'steps.check.outputs.skip' |
| 177 | + uses: ad-m/github-push-action@master |
| 178 | + with: |
| 179 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 180 | + branch: po4a-testing |
| 181 | + #force: true |
| 182 | + |
| 183 | + #- name: Create pull request |
| 184 | + # if: '!steps.check.outputs.skip' |
| 185 | + # uses: peter-evans/create-pull-request@v6 |
| 186 | + # with: |
| 187 | + # token: ${{ secrets.GITHUB_TOKEN }} |
| 188 | + # branch: po4a-staged |
| 189 | + # continue-on-error: true |
0 commit comments