From 28cde30151f6abb0477a526901712cc00bac98ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Chmela?= Date: Tue, 26 Aug 2025 00:28:25 +0200 Subject: [PATCH 1/6] Make targets related to gitbook export and Docker configuraiton --- Dockerfile | 27 ++++++++++++++++++++++++++- Makefile | 23 ++++++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 48b772b38..e29d7c347 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,28 @@ FROM lrx0014/gitbook:3.2.3 COPY ./ /srv/gitbook/ -EXPOSE 4000 \ No newline at end of file +EXPOSE 4000 + +# Update sources.list for Debian Jessie. +RUN rm /etc/apt/sources.list +RUN echo "deb http://archive.debian.org/debian-security jessie/updates main" >> /etc/apt/sources.list.d/jessie.list +RUN echo "deb http://archive.debian.org/debian jessie main" >> /etc/apt/sources.list.d/jessie.list +RUN apt update +RUN apt install -y --force-yes calibre bzip2 +RUN npm install svgexport@0.3.0 -g + +# Install CommandBox (https://commandbox.ortusbooks.com/setup/installation). +# Requires OpenJDK 11 but only version 7 is available from Debian Jessie repositories. +# Run that on a more up-to-date system. +#RUN apt install -y libappindicator3-dev openjdk-11-jdk +#RUN curl -fsSl https://downloads.ortussolutions.com/debs/gpg | gpg --dearmor | tee /usr/share/keyrings/ortussolutions.gpg > /dev/null +#RUN echo "deb [signed-by=/usr/share/keyrings/ortussolutions.gpg] https://downloads.ortussolutions.com/debs/noarch /" | tee /etc/apt/sources.list.d/commandbox.list +#RUN apt-get update && apt-get install -y apt-transport-https commandbox + +# Install gitbook-exporter into the CommandBox. +#RUN box install gitbook-exporter + +# Run CommandBox shell with gitbook command available. (https://www.forgebox.io/view/gitbook-exporter) +# Examples: +#RUN gitbook pdf +#RUN gitbook epub + diff --git a/Makefile b/Makefile index f05b586e6..013248413 100644 --- a/Makefile +++ b/Makefile @@ -9,13 +9,34 @@ help: ## Print help .PHONY: run run: image ## docker run ... (docker stop linux-insides-book 2>&1) > /dev/null || true - docker run --detach --rm -p 4000:4000 --name linux-insides-book --hostname linux-insides-book linux-insides-book + docker run --detach -p 4000:4000 --name linux-insides-book --hostname linux-insides-book linux-insides-book + +.PHONY: start +start: ## start the docker container ... + docker start linux-insides-book .PHONY: image image: ## docker image build ... docker image build --rm --squash --label linux-insides --tag linux-insides-book:latest -f Dockerfile . 2> /dev/null || \ docker image build --rm --label linux-insides --tag linux-insides-book:latest -f Dockerfile . +.PHONY: sh +sh: ## run interactive shell inside an already running docker container ... + docker exec -it linux-insides-book sh + +.PHONY: rm +rm: ## remove the docker container ... + (docker stop linux-insides-book 2>&1) > /dev/null || true + (docker rm linux-insides-book 2>&1) > /dev/null || true + +.PHONY: logs +logs: ## gather logs from the docker container ... + docker logs linux-insides-book + +.PHONY: cp +cp: ## copy exported PDF book to current working directory ... + docker cp linux-insides-book:/srv/gitbook/book.pdf . + ### LAUNCH BROWSER .PHONY: browse From 9557d176b3d345c931fe6f1efabfb682db14eed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Chmela?= Date: Fri, 29 Aug 2025 22:04:18 +0200 Subject: [PATCH 2/6] Chapter Booting: Fixed SVG images Apparently, draw.io spoils its SVG 1.1 output images with some HTML tags (invalid within the 1.1 standard). These are then rendered ad black blocks by the svgexport NPM package (required by gitbook to export the book). These SVGs were re-exported using Inkscape 1.2 to make svgexport happy. The package does, however, crop source SVGs slightly from each side for whatever reason. This remains to be resolved. --- Booting/images/early-bss.svg | 965 ++++++++++++++++++++++++++++++++- Booting/images/early-stack.svg | 637 +++++++++++++++++++++- 2 files changed, 1596 insertions(+), 6 deletions(-) diff --git a/Booting/images/early-bss.svg b/Booting/images/early-bss.svg index 3d29cc7d2..768886907 100644 --- a/Booting/images/early-bss.svg +++ b/Booting/images/early-bss.svg @@ -1,4 +1,963 @@ - + - -
Stack
Stack
Kernel setup code
Kernel setup code
0x9000:0x9000
0x9000:0x9000
0x9200:0x0000
0x9200:0x0000
CS:IP
CS:IP
SS:SP
SS:SP
Kernel setup header
Kernel setup header
0x9000:0x0000
0x9000:0x0000
CS:IP
CS:IP
BSS
BSS
0x9000:0x5280
0x9000:0x5280
0x9000:0x3f00
0x9000:0x3f00
__bss_start
__bss_start
__bss_end
__bss_end
Text is not SVG - cannot display
\ No newline at end of file + + + + + + + + + + + + + + + + + + Stack + + + + + Stack + + + + + + + + + + + + + + + + Kernel setup code + + + + + Kernel setup code + + + + + + + + + + + + + + + + + + + + + + 0x9000:0x9000 + + + + + 0x9000:0x9000 + + + + + + + + + + + + + + + + 0x9200:0x0000 + + + + + 0x9200:0x0000 + + + + + + + + + + + + + + + + + + + + + + CS:IP + + + + + CS:IP + + + + + + + + + + + + + + + + SS:SP + + + + + SS:SP + + + + + + + + + + + + + + + + Kernel setup header + + + + + Kernel setup header + + + + + + + + + + + + + + + + 0x9000:0x0000 + + + + + 0x9000:0x0000 + + + + + + + + + + + + + + + + + + + + + + CS:IP + + + + + CS:IP + + + + + + + + + + + + + + + + BSS + + + + + BSS + + + + + + + + + + + + + + + + + + + + + + 0x9000:0x5280 + + + + + 0x9000:0x5280 + + + + + + + + + + + + + + + + + + + + + + 0x9000:0x3f00 + + + + + 0x9000:0x3f00 + + + + + + + + + + + + + + + + __bss_start + + + + + __bss_start + + + + + + + + + + + + + + + + __bss_end + + + + + __bss_end + + + + + + + + + + + Text is not SVG - cannot display + + + diff --git a/Booting/images/early-stack.svg b/Booting/images/early-stack.svg index 2d493362f..85737eb82 100644 --- a/Booting/images/early-stack.svg +++ b/Booting/images/early-stack.svg @@ -1,4 +1,635 @@ - + - -
Stack
Stack
Kernel setup code
Kernel setup code
0x9000:0x9000
0x9000:0x9000
0x9200:0x0000
0x9200:0x0000
CS:IP
CS:IP
SS:SP
SS:SP
Kernel setup header
Kernel setup header
0x9000:0x0000
0x9000:0x0000
CS:IP
CS:IP
Text is not SVG - cannot display
\ No newline at end of file + + + + + + + + + + + + + + + + + + Stack + + + + + Stack + + + + + + + + + + + + + + + + Kernel setup code + + + + + Kernel setup code + + + + + + + + + + + + + + + + + + + + + + 0x9000:0x9000 + + + + + 0x9000:0x9000 + + + + + + + + + + + + + + + + 0x9200:0x0000 + + + + + 0x9200:0x0000 + + + + + + + + + + + + + + + + + + + + + + CS:IP + + + + + CS:IP + + + + + + + + + + + + + + + + SS:SP + + + + + SS:SP + + + + + + + + + + + + + + + + Kernel setup header + + + + + Kernel setup header + + + + + + + + + + + + + + + + 0x9000:0x0000 + + + + + 0x9000:0x0000 + + + + + + + + + + + + + + + + + + + + + + CS:IP + + + + + CS:IP + + + + + + + + + + + Text is not SVG - cannot display + + + From f4031afee76f86b6fd5854e7628dc7724fbdbaca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Chmela?= Date: Fri, 29 Aug 2025 17:52:58 +0200 Subject: [PATCH 3/6] Generate e-books for every release and PR There are still some code blocks which do not fit the A5 format. Let's make A4-sized PDFs the default size. The A5 PDF may still be the oly format suitable for e-book readers, though, as MOBI and EPUB mess code blocks expected to be written in a monotype font up. Bitmap images are still somewhat oversized in the A4 format, though. A CSS rule similar to the following one may be needed in a CSS file at the right location in the repository: @media print { img { object-fit: scale-down; } } --- .github/workflows/generate_release.yaml | 123 ++++++++++++++++++++++++ Makefile | 26 ++++- book-A5.json | 14 +++ book.json | 12 +-- 4 files changed, 162 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/generate_release.yaml create mode 100644 book-A5.json diff --git a/.github/workflows/generate_release.yaml b/.github/workflows/generate_release.yaml new file mode 100644 index 000000000..df932c1c4 --- /dev/null +++ b/.github/workflows/generate_release.yaml @@ -0,0 +1,123 @@ +name: Generate e-books + +on: + push: + tags: + - 'v*.*' # Create a release only when a new tag matching v*.* is pushed. + # To also create a release for each push to the main branch, uncomment the following 2 lines: + # branches: + # - master + pull_request: + branches: + - master + workflow_dispatch: {} # For manual runs. + +jobs: + release-ebooks: + # Run for tag pushes (and optionally for branch pushes if the "branches" node is uncommented above). + if: github.event_name != 'pull_request' + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Export all supported book formats from the Docker container + run: | + make run + make export + + - name: Copy generated files to host system + run: | + make cp + mkdir -p artifacts/ + mv "Linux Inside - 0xAX.epub" \ + "Linux Inside - 0xAX.mobi" \ + "Linux Inside - 0xAX.pdf" \ + "Linux Inside - 0xAX (A5).pdf" \ + artifacts/ + cp LICENSE artifacts/ + + - name: Prepare release metadata + # Use tag name when running on a tag, otherwise fall back to the short commit hash. + id: meta + env: + GITHUB_REF_TYPE: ${{ github.ref_type }} + GITHUB_REF_NAME: ${{ github.ref_name }} + run: | + DATE_US="$(date -u '+%m/%d/%Y %H:%M')" + if [ "${GITHUB_REF_TYPE}" = "tag" ] && [ -n "${GITHUB_REF_NAME}" ]; then + LABEL="${GITHUB_REF_NAME}" + else + LABEL="$(git rev-parse --short HEAD)" + fi + echo "release_name=${DATE_US} (${LABEL})" >> "$GITHUB_OUTPUT" + echo "tag_name=${LABEL}" >> "$GITHUB_OUTPUT" + + - name: Create GitHub release + uses: softprops/action-gh-release@v2 + with: + files: artifacts/* + name: ${{ steps.meta.outputs.release_name }} + tag_name: ${{ steps.meta.outputs.tag_name }} + target_commitish: ${{ github.sha }} + generate_release_notes: true + fail_on_unmatched_files: true + + build-for-pr: + # For every PR, build the same artifacts and make them accessible from the PR. + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + + permissions: + contents: read + pull-requests: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Export all supported book formats from the Docker container + run: | + make run + make export + + - name: Copy generated files to host system + run: | + make cp + mkdir -p artifacts/ + mv "Linux Inside - 0xAX.epub" \ + "Linux Inside - 0xAX.mobi" \ + "Linux Inside - 0xAX.pdf" \ + "Linux Inside - 0xAX (A5).pdf" \ + artifacts/ + + - name: Upload PR artifacts + uses: actions/upload-artifact@v4 + with: + name: ebooks-${{ github.sha }} + path: artifacts/* + if-no-files-found: error + # Change the retention period here if necessary. + retention-days: 90 + + - name: Add a comment with a link to the generated artifacts. + # For forked PRs the token is read-only; skip commenting to avoid failures. + if: ${{ github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }} + uses: actions/github-script@v7 + env: + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + with: + script: | + const body = [ + `E-books generated for this pull request available at: ${process.env.RUN_URL}` + ].join('\n'); + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body + }); \ No newline at end of file diff --git a/Makefile b/Makefile index 013248413..ba308c68c 100644 --- a/Makefile +++ b/Makefile @@ -33,9 +33,31 @@ rm: ## remove the docker container ... logs: ## gather logs from the docker container ... docker logs linux-insides-book +.PHONY: export +export: ## run e-book generation inside an already running docker container ... + docker exec linux-insides-book /bin/bash -c " \ + gitbook epub; \ + gitbook mobi; \ + gitbook pdf; \ + mv book.pdf book-A4.pdf; \ + mv book-A5.json book.json; \ + gitbook pdf; \ + mv book.pdf book-A5.pdf; \ + mv book-A4.pdf book.pdf" + .PHONY: cp -cp: ## copy exported PDF book to current working directory ... - docker cp linux-insides-book:/srv/gitbook/book.pdf . +cp: ## copy all exported e-book formats to current working directory ... + docker cp linux-insides-book:/srv/gitbook/book.epub "Linux Inside - 0xAX.epub" + docker cp linux-insides-book:/srv/gitbook/book.mobi "Linux Inside - 0xAX.mobi" + docker cp linux-insides-book:/srv/gitbook/book.pdf "Linux Inside - 0xAX.pdf" + docker cp linux-insides-book:/srv/gitbook/book-A5.pdf "Linux Inside - 0xAX (A5).pdf" + +.PHONY: clean +clean: ## remove all exported e-book files ... + rm "Linux Inside - 0xAX.epub" \ + "Linux Inside - 0xAX.mobi" \ + "Linux Inside - 0xAX.pdf" \ + "Linux Inside - 0xAX (A5).pdf" ### LAUNCH BROWSER diff --git a/book-A5.json b/book-A5.json new file mode 100644 index 000000000..2cda76249 --- /dev/null +++ b/book-A5.json @@ -0,0 +1,14 @@ +{ + "title": "Linux Insides", + "author" : "0xAX", + "pdf": { + "paperSize": "a5", + "margin": + { + "top": 48, + "bottom": 48, + "right": 28, + "left": 28 + } + } +} diff --git a/book.json b/book.json index 2cda76249..245a7ec92 100644 --- a/book.json +++ b/book.json @@ -1,14 +1,4 @@ { "title": "Linux Insides", - "author" : "0xAX", - "pdf": { - "paperSize": "a5", - "margin": - { - "top": 48, - "bottom": 48, - "right": 28, - "left": 28 - } - } + "author" : "0xAX" } From 34d15b9e542306de2f8112f8b49a1e49632619c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Chmela?= Date: Tue, 2 Sep 2025 20:06:39 +0200 Subject: [PATCH 4/6] Revert "Chapter Booting: Fixed SVG images" This reverts commit 9557d176b3d345c931fe6f1efabfb682db14eed9. --- Booting/images/early-bss.svg | 965 +-------------------------------- Booting/images/early-stack.svg | 637 +--------------------- 2 files changed, 6 insertions(+), 1596 deletions(-) diff --git a/Booting/images/early-bss.svg b/Booting/images/early-bss.svg index 768886907..3d29cc7d2 100644 --- a/Booting/images/early-bss.svg +++ b/Booting/images/early-bss.svg @@ -1,963 +1,4 @@ - + - - - - - - - - - - - - - - - - - - Stack - - - - - Stack - - - - - - - - - - - - - - - - Kernel setup code - - - - - Kernel setup code - - - - - - - - - - - - - - - - - - - - - - 0x9000:0x9000 - - - - - 0x9000:0x9000 - - - - - - - - - - - - - - - - 0x9200:0x0000 - - - - - 0x9200:0x0000 - - - - - - - - - - - - - - - - - - - - - - CS:IP - - - - - CS:IP - - - - - - - - - - - - - - - - SS:SP - - - - - SS:SP - - - - - - - - - - - - - - - - Kernel setup header - - - - - Kernel setup header - - - - - - - - - - - - - - - - 0x9000:0x0000 - - - - - 0x9000:0x0000 - - - - - - - - - - - - - - - - - - - - - - CS:IP - - - - - CS:IP - - - - - - - - - - - - - - - - BSS - - - - - BSS - - - - - - - - - - - - - - - - - - - - - - 0x9000:0x5280 - - - - - 0x9000:0x5280 - - - - - - - - - - - - - - - - - - - - - - 0x9000:0x3f00 - - - - - 0x9000:0x3f00 - - - - - - - - - - - - - - - - __bss_start - - - - - __bss_start - - - - - - - - - - - - - - - - __bss_end - - - - - __bss_end - - - - - - - - - - - Text is not SVG - cannot display - - - + +
Stack
Stack
Kernel setup code
Kernel setup code
0x9000:0x9000
0x9000:0x9000
0x9200:0x0000
0x9200:0x0000
CS:IP
CS:IP
SS:SP
SS:SP
Kernel setup header
Kernel setup header
0x9000:0x0000
0x9000:0x0000
CS:IP
CS:IP
BSS
BSS
0x9000:0x5280
0x9000:0x5280
0x9000:0x3f00
0x9000:0x3f00
__bss_start
__bss_start
__bss_end
__bss_end
Text is not SVG - cannot display
\ No newline at end of file diff --git a/Booting/images/early-stack.svg b/Booting/images/early-stack.svg index 85737eb82..2d493362f 100644 --- a/Booting/images/early-stack.svg +++ b/Booting/images/early-stack.svg @@ -1,635 +1,4 @@ - + - - - - - - - - - - - - - - - - - - Stack - - - - - Stack - - - - - - - - - - - - - - - - Kernel setup code - - - - - Kernel setup code - - - - - - - - - - - - - - - - - - - - - - 0x9000:0x9000 - - - - - 0x9000:0x9000 - - - - - - - - - - - - - - - - 0x9200:0x0000 - - - - - 0x9200:0x0000 - - - - - - - - - - - - - - - - - - - - - - CS:IP - - - - - CS:IP - - - - - - - - - - - - - - - - SS:SP - - - - - SS:SP - - - - - - - - - - - - - - - - Kernel setup header - - - - - Kernel setup header - - - - - - - - - - - - - - - - 0x9000:0x0000 - - - - - 0x9000:0x0000 - - - - - - - - - - - - - - - - - - - - - - CS:IP - - - - - CS:IP - - - - - - - - - - - Text is not SVG - cannot display - - - + +
Stack
Stack
Kernel setup code
Kernel setup code
0x9000:0x9000
0x9000:0x9000
0x9200:0x0000
0x9200:0x0000
CS:IP
CS:IP
SS:SP
SS:SP
Kernel setup header
Kernel setup header
0x9000:0x0000
0x9000:0x0000
CS:IP
CS:IP
Text is not SVG - cannot display
\ No newline at end of file From 3c3ad2165bf6fe7cdfbe7e841936f540674a57bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Chmela?= Date: Wed, 3 Sep 2025 21:19:51 +0200 Subject: [PATCH 5/6] Post-review fixes --- .github/workflows/generate-e-books.yaml | 63 ++++++++++++ .github/workflows/generate_release.yaml | 123 ------------------------ .github/workflows/release-e-books.yaml | 63 ++++++++++++ 3 files changed, 126 insertions(+), 123 deletions(-) create mode 100644 .github/workflows/generate-e-books.yaml delete mode 100644 .github/workflows/generate_release.yaml create mode 100644 .github/workflows/release-e-books.yaml diff --git a/.github/workflows/generate-e-books.yaml b/.github/workflows/generate-e-books.yaml new file mode 100644 index 000000000..cec0ea98c --- /dev/null +++ b/.github/workflows/generate-e-books.yaml @@ -0,0 +1,63 @@ +name: Generate e-books + +on: + pull_request: + branches: + - master + workflow_dispatch: {} # For manual runs. + +jobs: + build-for-pr: + # For every PR, build the same artifacts and make them accessible from the PR. + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + + permissions: + contents: read + pull-requests: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Export all supported book formats from the Docker container + run: | + make run + make export + + - name: Copy generated files to host system + run: | + make cp + mkdir -p artifacts/ + mv "Linux Inside - 0xAX.epub" \ + "Linux Inside - 0xAX.mobi" \ + "Linux Inside - 0xAX.pdf" \ + "Linux Inside - 0xAX (A5).pdf" \ + artifacts/ + + - name: Upload PR artifacts + uses: actions/upload-artifact@v4 + with: + name: ebooks-${{ github.sha }} + path: artifacts/* + if-no-files-found: error + # Change the retention period here if necessary. + retention-days: 90 + + - name: Add a comment with a link to the generated artifacts. + # For forked PRs the token is read-only; skip commenting to avoid failures. + if: ${{ github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }} + uses: actions/github-script@v7 + env: + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + with: + script: | + const body = [ + `E-books generated for this pull request available at: ${process.env.RUN_URL}` + ].join('\n'); + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body + }); diff --git a/.github/workflows/generate_release.yaml b/.github/workflows/generate_release.yaml deleted file mode 100644 index df932c1c4..000000000 --- a/.github/workflows/generate_release.yaml +++ /dev/null @@ -1,123 +0,0 @@ -name: Generate e-books - -on: - push: - tags: - - 'v*.*' # Create a release only when a new tag matching v*.* is pushed. - # To also create a release for each push to the main branch, uncomment the following 2 lines: - # branches: - # - master - pull_request: - branches: - - master - workflow_dispatch: {} # For manual runs. - -jobs: - release-ebooks: - # Run for tag pushes (and optionally for branch pushes if the "branches" node is uncommented above). - if: github.event_name != 'pull_request' - runs-on: ubuntu-latest - - permissions: - contents: write - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Export all supported book formats from the Docker container - run: | - make run - make export - - - name: Copy generated files to host system - run: | - make cp - mkdir -p artifacts/ - mv "Linux Inside - 0xAX.epub" \ - "Linux Inside - 0xAX.mobi" \ - "Linux Inside - 0xAX.pdf" \ - "Linux Inside - 0xAX (A5).pdf" \ - artifacts/ - cp LICENSE artifacts/ - - - name: Prepare release metadata - # Use tag name when running on a tag, otherwise fall back to the short commit hash. - id: meta - env: - GITHUB_REF_TYPE: ${{ github.ref_type }} - GITHUB_REF_NAME: ${{ github.ref_name }} - run: | - DATE_US="$(date -u '+%m/%d/%Y %H:%M')" - if [ "${GITHUB_REF_TYPE}" = "tag" ] && [ -n "${GITHUB_REF_NAME}" ]; then - LABEL="${GITHUB_REF_NAME}" - else - LABEL="$(git rev-parse --short HEAD)" - fi - echo "release_name=${DATE_US} (${LABEL})" >> "$GITHUB_OUTPUT" - echo "tag_name=${LABEL}" >> "$GITHUB_OUTPUT" - - - name: Create GitHub release - uses: softprops/action-gh-release@v2 - with: - files: artifacts/* - name: ${{ steps.meta.outputs.release_name }} - tag_name: ${{ steps.meta.outputs.tag_name }} - target_commitish: ${{ github.sha }} - generate_release_notes: true - fail_on_unmatched_files: true - - build-for-pr: - # For every PR, build the same artifacts and make them accessible from the PR. - if: github.event_name == 'pull_request' - runs-on: ubuntu-latest - - permissions: - contents: read - pull-requests: write - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Export all supported book formats from the Docker container - run: | - make run - make export - - - name: Copy generated files to host system - run: | - make cp - mkdir -p artifacts/ - mv "Linux Inside - 0xAX.epub" \ - "Linux Inside - 0xAX.mobi" \ - "Linux Inside - 0xAX.pdf" \ - "Linux Inside - 0xAX (A5).pdf" \ - artifacts/ - - - name: Upload PR artifacts - uses: actions/upload-artifact@v4 - with: - name: ebooks-${{ github.sha }} - path: artifacts/* - if-no-files-found: error - # Change the retention period here if necessary. - retention-days: 90 - - - name: Add a comment with a link to the generated artifacts. - # For forked PRs the token is read-only; skip commenting to avoid failures. - if: ${{ github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }} - uses: actions/github-script@v7 - env: - RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} - with: - script: | - const body = [ - `E-books generated for this pull request available at: ${process.env.RUN_URL}` - ].join('\n'); - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - body - }); \ No newline at end of file diff --git a/.github/workflows/release-e-books.yaml b/.github/workflows/release-e-books.yaml new file mode 100644 index 000000000..66b4dddfc --- /dev/null +++ b/.github/workflows/release-e-books.yaml @@ -0,0 +1,63 @@ +name: Release e-books + +on: + push: + tags: + - 'v*.*' # Create a release only when a new tag matching v*.* is pushed. + # To also create a release for each push to the main branch, uncomment the following 2 lines: + # branches: + # - master + workflow_dispatch: {} # For manual runs. + +jobs: + release-ebooks: + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Export all supported book formats from the Docker container + run: | + make run + make export + + - name: Copy generated files to host system + run: | + make cp + mkdir -p artifacts/ + mv "Linux Inside - 0xAX.epub" \ + "Linux Inside - 0xAX.mobi" \ + "Linux Inside - 0xAX.pdf" \ + "Linux Inside - 0xAX (A5).pdf" \ + artifacts/ + cp LICENSE artifacts/ + + - name: Prepare release metadata + # Use tag name when running on a tag, otherwise fall back to the short commit hash. + id: meta + env: + GITHUB_REF_TYPE: ${{ github.ref_type }} + GITHUB_REF_NAME: ${{ github.ref_name }} + run: | + DATE_UTC="$(date -u '+%m/%d/%Y %H:%M')" + if [ "${GITHUB_REF_TYPE}" = "tag" ] && [ -n "${GITHUB_REF_NAME}" ]; then + LABEL="${GITHUB_REF_NAME}" + else + LABEL="$(git rev-parse --short HEAD)" + fi + echo "release_name=${DATE_UTC} (${LABEL})" >> "$GITHUB_OUTPUT" + echo "tag_name=${LABEL}" >> "$GITHUB_OUTPUT" + + - name: Create GitHub release + uses: softprops/action-gh-release@v2 + with: + files: artifacts/* + name: ${{ steps.meta.outputs.release_name }} + tag_name: ${{ steps.meta.outputs.tag_name }} + target_commitish: ${{ github.sha }} + generate_release_notes: true + fail_on_unmatched_files: true From 0e8988403603f814d131e27612383725c2b8efac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Chmela?= Date: Thu, 4 Sep 2025 18:02:58 +0200 Subject: [PATCH 6/6] Change e-book retention period in PRs to 7 days --- .github/workflows/generate-e-books.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/generate-e-books.yaml b/.github/workflows/generate-e-books.yaml index cec0ea98c..c2de3b501 100644 --- a/.github/workflows/generate-e-books.yaml +++ b/.github/workflows/generate-e-books.yaml @@ -42,7 +42,7 @@ jobs: path: artifacts/* if-no-files-found: error # Change the retention period here if necessary. - retention-days: 90 + retention-days: 7 - name: Add a comment with a link to the generated artifacts. # For forked PRs the token is read-only; skip commenting to avoid failures.