|
| 1 | +name: 'Build EPUB with ditac' |
| 2 | +description: 'Convert a DITA map to EPUB/EPUB3 using XMLmind DITA Converter (ditac)' |
| 3 | +author: 'VT-Evia' |
| 4 | +branding: |
| 5 | + color: blue |
| 6 | + icon: book |
| 7 | + |
| 8 | +inputs: |
| 9 | + map: |
| 10 | + description: 'Path to the DITA map (e.g., example/document.ditamap)' |
| 11 | + required: true |
| 12 | + output: |
| 13 | + description: 'Output EPUB path (e.g., out/book.epub)' |
| 14 | + required: true |
| 15 | + format: |
| 16 | + description: 'Target format: epub or epub3' |
| 17 | + required: false |
| 18 | + default: 'epub3' |
| 19 | + ditac-version: |
| 20 | + description: 'ditac version tag, e.g., 3_17_2' |
| 21 | + required: false |
| 22 | + default: '3_17_2' |
| 23 | + resources-dir: |
| 24 | + description: 'xsl-resources-directory (CSS/images); will be created if missing' |
| 25 | + required: false |
| 26 | + default: 'res' |
| 27 | + java-version: |
| 28 | + description: 'Java version to install (ditac supports Java 8+).' |
| 29 | + required: false |
| 30 | + default: '17' |
| 31 | + extra-args: |
| 32 | + description: 'Additional arguments passed to ditac (advanced).' |
| 33 | + required: false |
| 34 | + default: '' |
| 35 | + validate-with-epubcheck: |
| 36 | + description: 'Run EPUBCheck after build (true/false).' |
| 37 | + required: false |
| 38 | + default: 'true' |
| 39 | + epubcheck-version: |
| 40 | + description: 'EPUBCheck version (used if validate-with-epubcheck=true).' |
| 41 | + required: false |
| 42 | + default: '5.1.0' |
| 43 | + |
| 44 | +runs: |
| 45 | + using: "composite" |
| 46 | + steps: |
| 47 | + - name: Set up Java |
| 48 | + uses: actions/setup-java@v4 |
| 49 | + with: |
| 50 | + distribution: temurin |
| 51 | + java-version: ${{ inputs.java-version }} |
| 52 | + |
| 53 | + - name: Restore ditac cache |
| 54 | + id: cache-ditac |
| 55 | + uses: actions/cache@v4 |
| 56 | + with: |
| 57 | + path: ditac-${{ inputs.ditac-version }} |
| 58 | + key: ditac-${{ inputs.ditac-version }} |
| 59 | + |
| 60 | + - name: Download ditac |
| 61 | + if: steps.cache-ditac.outputs.cache-hit != 'true' |
| 62 | + shell: bash |
| 63 | + run: | |
| 64 | + curl -fsSL -o ditac.zip "https://www.xmlmind.com/ditac/ditac-${{ inputs.ditac-version }}.zip" |
| 65 | + unzip -q ditac.zip |
| 66 | + rm -f ditac.zip |
| 67 | +
|
| 68 | + - name: Add ditac to PATH |
| 69 | + shell: bash |
| 70 | + run: echo "$GITHUB_WORKSPACE/ditac-${{ inputs.ditac-version }}/bin" >> "$GITHUB_PATH" |
| 71 | + |
| 72 | + - name: Ensure directories |
| 73 | + shell: bash |
| 74 | + run: | |
| 75 | + mkdir -p "${{ inputs.resources-dir }}" |
| 76 | + mkdir -p "$(dirname "${{ inputs.output }}")" |
| 77 | +
|
| 78 | + - name: Build EPUB |
| 79 | + shell: bash |
| 80 | + run: | |
| 81 | + if [ "${{ inputs.format }}" = "epub3" ]; then FORMAT_OPT="-format epub3"; else FORMAT_OPT=""; fi |
| 82 | + set -e |
| 83 | + ditac -r . \ |
| 84 | + -p xsl-resources-directory "${{ inputs.resources-dir }}" \ |
| 85 | + $FORMAT_OPT \ |
| 86 | + ${{ inputs.extra-args }} \ |
| 87 | + "${{ inputs.output }}" "${{ inputs.map }}" |
| 88 | +
|
| 89 | + - name: (Optional) Download EPUBCheck |
| 90 | + if: inputs.validate-with-epubcheck == 'true' |
| 91 | + shell: bash |
| 92 | + run: | |
| 93 | + curl -fsSL -o epubcheck.zip "https://github.com/w3c/epubcheck/releases/download/v${{ inputs.epubcheck-version }}/epubcheck-${{ inputs.epubcheck-version }}.zip" |
| 94 | + unzip -q epubcheck.zip |
| 95 | + rm -f epubcheck.zip |
| 96 | + echo "EPUBCHECK_JAR=$GITHUB_WORKSPACE/epubcheck-${{ inputs.epubcheck-version }}/epubcheck.jar" >> "$GITHUB_ENV" |
| 97 | +
|
| 98 | + - name: (Optional) Validate EPUB |
| 99 | + if: inputs.validate-with-epubcheck == 'true' |
| 100 | + shell: bash |
| 101 | + run: | |
| 102 | + # Fail on EPUBCheck errors; print report |
| 103 | + java -jar "$EPUBCHECK_JAR" "${{ inputs.output }}" |
0 commit comments