diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index e62e24e8..2d2d06f3 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -26,26 +26,14 @@ jobs: with: ref: ${{ github.event.pull_request.head.ref || github.ref_name }} - - name: Set up Node id: node uses: actions/setup-node@v3 with: node-version: "16" - - name: Install po4a dependencies - run: sudo apt-get install libyaml-tiny-perl gettext libunicode-linebreak-perl - - # install po4a (replace by stable tag after v0.66 release / we need PR #331) - - name: Install po4a from github - run: | - git clone --branch v0.66 https://github.com/mquinson/po4a.git ~/po4a - ls -la ~/po4a - echo "$HOME/po4a" >> $GITHUB_PATH - echo "PERLLIB=$HOME/po4a/lib" >> $GITHUB_ENV - - name: Update translation files - run: po4a --no-translations po4a.conf + run: ./scripts/run_po4a.sh po4a.conf --no-translations - name: Commit translation file updates uses: EndBug/add-and-commit@v9 @@ -57,10 +45,7 @@ jobs: run: yarn install - name: Run translation - run: | - echo "PATH=$PATH" - echo "PERLLIB=$PERLLIB" - yarn translate + run: yarn translate - name: Run antora run: | diff --git a/Dockerfile.po4a b/Dockerfile.po4a new file mode 100644 index 00000000..6396dc5f --- /dev/null +++ b/Dockerfile.po4a @@ -0,0 +1,46 @@ +FROM ubuntu:22.04 + +# Set locale to UTF-8 +ENV LANG=C.UTF-8 +ENV LC_ALL=C.UTF-8 + +# Install dependencies +RUN apt-get update && apt-get install -y \ + git \ + make \ + libyaml-tiny-perl \ + gettext \ + libunicode-linebreak-perl \ + perl \ + perl-modules \ + libmodule-build-perl \ + libpod-parser-perl \ + libsgmls-perl \ + liblocale-gettext-perl \ + libterm-readkey-perl \ + libtext-wrapi18n-perl \ + xsltproc \ + docbook-xsl \ + && rm -rf /var/lib/apt/lists/* + +# Install po4a from GitHub +RUN git clone --branch v0.66 https://github.com/mquinson/po4a.git /po4a \ + && cd /po4a \ + && perl Build.PL \ + && ./Build \ + && ./Build install + +# Create a non-root user with the same UID/GID as the host user +ARG USER_ID=1000 +ARG GROUP_ID=1000 +RUN groupadd -g $GROUP_ID builder && \ + useradd -u $USER_ID -g $GROUP_ID -m builder + +# Set up working directory with correct permissions +WORKDIR /workspace +RUN chown builder:builder /workspace + +# Switch to non-root user +USER builder + +ENTRYPOINT ["/bin/bash"] \ No newline at end of file diff --git a/package.json b/package.json index 8af2a254..cb1d31b6 100644 --- a/package.json +++ b/package.json @@ -1,27 +1,27 @@ -{ - "name": "agrirouter-user-documentation", - "version": "1.0.0", - "repository": "https://github.com/DKE-Data/agrirouter-user-documentation.git", - "author": "Oliver Rahner ", - "license": "Apache-2.0", - "scripts": { - "validate-xrefs": "for LNG in de en fr it ru pt es nl pl; do cd $LNG; $(npm bin)/antora --generator @antora/xref-validator ./antora-playbook.yml; cd ..; done", - "update-i18n": "po4a po4a.conf --no-translations", - "translate": "echo \\* Generating translated files...; po4a po4a.conf --no-update; for LNG in en fr it ru pt es nl pl; do echo \\* Copying assets for $LNG...; cp -nrT de/modules/ROOT/assets/ $LNG/modules/ROOT/assets; cp -nrT de/modules/ROOT/partials/ $LNG/modules/ROOT/partials; done", - "build": "for LNG in de en fr it ru pt es nl pl; do echo \\* Building lang $LNG...; cd $LNG; $(npm bin)/antora generate antora-playbook.yml --to-dir ../build/$LNG || exit; cd ..; done; cp index.html build/", - "generate-images": "node scripts/generate_images.js" - }, - "dependencies": { - "@antora/cli": "3.1.0", - "@antora/content-classifier": "https://gitpkg.now.sh/DKE-Data/antora/packages/content-classifier?3.1.0-dke-1", - "@antora/lunr-extension": "1.0.0-alpha.8", - "@antora/site-generator-default": "3.1.0", - "asciidoctor-kroki": "^0.16.0" - }, - "devDependencies": { - "got": "^12.0.1", - "prompt": "^1.2.1", - "puppeteer": "^13.0.1", - "sleep-promise": "^9.1.0" - } -} +{ + "name": "agrirouter-user-documentation", + "version": "1.0.0", + "repository": "https://github.com/DKE-Data/agrirouter-user-documentation.git", + "author": "Oliver Rahner ", + "license": "Apache-2.0", + "scripts": { + "validate-xrefs": "for LNG in de en fr it ru pt es nl pl; do cd $LNG; $(npm bin)/antora --generator @antora/xref-validator ./antora-playbook.yml; cd ..; done", + "update-i18n": "./scripts/run_po4a.sh po4a.conf --no-translations", + "translate": "echo \\* Generating translated files...; ./scripts/run_po4a.sh po4a.conf --no-update; for LNG in en fr it ru pt es nl pl; do echo \\* Copying assets for $LNG...; cp -nrT de/modules/ROOT/assets/ $LNG/modules/ROOT/assets; cp -nrT de/modules/ROOT/partials $LNG/modules/ROOT/partials; done", + "build": "for LNG in de en fr it ru pt es nl pl; do echo \\* Building lang $LNG...; cd $LNG; $(npm bin)/antora generate antora-playbook.yml --to-dir ../build/$LNG || exit; cd ..; done; cp index.html build/", + "generate-images": "node scripts/generate_images.js" + }, + "dependencies": { + "@antora/cli": "3.1.0", + "@antora/content-classifier": "https://gitpkg.now.sh/DKE-Data/antora/packages/content-classifier?3.1.0-dke-1", + "@antora/lunr-extension": "1.0.0-alpha.8", + "@antora/site-generator-default": "3.1.0", + "asciidoctor-kroki": "^0.16.0" + }, + "devDependencies": { + "got": "^12.0.1", + "prompt": "^1.2.1", + "puppeteer": "^13.0.1", + "sleep-promise": "^9.1.0" + } +} diff --git a/scripts/run_po4a.sh b/scripts/run_po4a.sh new file mode 100755 index 00000000..eef92173 --- /dev/null +++ b/scripts/run_po4a.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# Check if the po4a image exists +if ! docker image inspect po4a >/dev/null 2>&1; then + echo "Building po4a Docker image..." + docker build -t po4a -f Dockerfile.po4a \ + --build-arg USER_ID=$(id -u) \ + --build-arg GROUP_ID=$(id -g) . +fi + +# Run po4a and capture output +output=$(docker run --rm \ + -v "$(pwd):/workspace" \ + -w /workspace \ + --user $(id -u):$(id -g) \ + po4a -c "po4a $*" 2>&1) +exit_code=$? + +# If po4a failed and the error contains a command that exited with value +if [ $exit_code -ne 0 ] && echo "$output" | grep -q "exited with value"; then + echo "po4a failed. message:" + echo "$output" + echo "Running failed command with verbose output for more details..." + echo "----------------------------------------" + # Extract the command from between single quotes + failed_cmd=$(echo "$output" | grep -o "'[^']*'" | head -n 1 | sed "s/'//g") + if [ -n "$failed_cmd" ]; then + echo "Running command: $failed_cmd --verbose" + docker run --rm \ + -v "$(pwd):/workspace" \ + -w /workspace \ + --user $(id -u):$(id -g) \ + po4a -c "$failed_cmd --verbose" + else + echo "Could not extract command from error message" + echo "$output" + fi + echo "----------------------------------------" + exit $exit_code +fi + +# If no command error or no command found, just show the original output +echo "$output" +exit $exit_code \ No newline at end of file