Skip to content

Commit 3f05903

Browse files
authored
Merge pull request #874 from kyselejsyrecek/master
Generate e-books for every release and PR
2 parents 2d05b1c + 95f7045 commit 3f05903

File tree

6 files changed

+211
-13
lines changed

6 files changed

+211
-13
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Generate e-books
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
workflow_dispatch: {} # For manual runs.
8+
9+
jobs:
10+
build-for-pr:
11+
# For every PR, build the same artifacts and make them accessible from the PR.
12+
if: github.event_name == 'pull_request'
13+
runs-on: ubuntu-latest
14+
15+
permissions:
16+
contents: read
17+
pull-requests: write
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
- name: Export all supported book formats from the Docker container
24+
run: |
25+
make run
26+
make export
27+
28+
- name: Copy generated files to host system
29+
run: |
30+
make cp
31+
mkdir -p artifacts/
32+
mv "Linux Inside - 0xAX.epub" \
33+
"Linux Inside - 0xAX.mobi" \
34+
"Linux Inside - 0xAX.pdf" \
35+
"Linux Inside - 0xAX (A5).pdf" \
36+
artifacts/
37+
38+
- name: Upload PR artifacts
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: ebooks-${{ github.sha }}
42+
path: artifacts/*
43+
if-no-files-found: error
44+
# Change the retention period here if necessary.
45+
retention-days: 7
46+
47+
- name: Add a comment with a link to the generated artifacts.
48+
# For forked PRs the token is read-only; skip commenting to avoid failures.
49+
if: ${{ github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }}
50+
uses: actions/github-script@v7
51+
env:
52+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
53+
with:
54+
script: |
55+
const body = [
56+
`E-books generated for this pull request available at: ${process.env.RUN_URL}`
57+
].join('\n');
58+
await github.rest.issues.createComment({
59+
owner: context.repo.owner,
60+
repo: context.repo.repo,
61+
issue_number: context.issue.number,
62+
body
63+
});
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Release e-books
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*' # Create a release only when a new tag matching v*.* is pushed.
7+
# To also create a release for each push to the main branch, uncomment the following 2 lines:
8+
# branches:
9+
# - master
10+
workflow_dispatch: {} # For manual runs.
11+
12+
jobs:
13+
release-ebooks:
14+
runs-on: ubuntu-latest
15+
16+
permissions:
17+
contents: write
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
- name: Export all supported book formats from the Docker container
24+
run: |
25+
make run
26+
make export
27+
28+
- name: Copy generated files to host system
29+
run: |
30+
make cp
31+
mkdir -p artifacts/
32+
mv "Linux Inside - 0xAX.epub" \
33+
"Linux Inside - 0xAX.mobi" \
34+
"Linux Inside - 0xAX.pdf" \
35+
"Linux Inside - 0xAX (A5).pdf" \
36+
artifacts/
37+
cp LICENSE artifacts/
38+
39+
- name: Prepare release metadata
40+
# Use tag name when running on a tag, otherwise fall back to the short commit hash.
41+
id: meta
42+
env:
43+
GITHUB_REF_TYPE: ${{ github.ref_type }}
44+
GITHUB_REF_NAME: ${{ github.ref_name }}
45+
run: |
46+
DATE_UTC="$(date -u '+%m/%d/%Y %H:%M')"
47+
if [ "${GITHUB_REF_TYPE}" = "tag" ] && [ -n "${GITHUB_REF_NAME}" ]; then
48+
LABEL="${GITHUB_REF_NAME}"
49+
else
50+
LABEL="$(git rev-parse --short HEAD)"
51+
fi
52+
echo "release_name=${DATE_UTC} (${LABEL})" >> "$GITHUB_OUTPUT"
53+
echo "tag_name=${LABEL}" >> "$GITHUB_OUTPUT"
54+
55+
- name: Create GitHub release
56+
uses: softprops/action-gh-release@v2
57+
with:
58+
files: artifacts/*
59+
name: ${{ steps.meta.outputs.release_name }}
60+
tag_name: ${{ steps.meta.outputs.tag_name }}
61+
target_commitish: ${{ github.sha }}
62+
generate_release_notes: true
63+
fail_on_unmatched_files: true

Dockerfile

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
11
FROM lrx0014/gitbook:3.2.3
22
COPY ./ /srv/gitbook/
3-
EXPOSE 4000
3+
EXPOSE 4000
4+
5+
# Update sources.list for Debian Jessie.
6+
RUN rm /etc/apt/sources.list
7+
RUN echo "deb http://archive.debian.org/debian-security jessie/updates main" >> /etc/apt/sources.list.d/jessie.list
8+
RUN echo "deb http://archive.debian.org/debian jessie main" >> /etc/apt/sources.list.d/jessie.list
9+
RUN apt update
10+
RUN apt install -y --force-yes calibre bzip2
11+
RUN npm install [email protected] -g
12+
13+
# Install CommandBox (https://commandbox.ortusbooks.com/setup/installation).
14+
# Requires OpenJDK 11 but only version 7 is available from Debian Jessie repositories.
15+
# Run that on a more up-to-date system.
16+
#RUN apt install -y libappindicator3-dev openjdk-11-jdk
17+
#RUN curl -fsSl https://downloads.ortussolutions.com/debs/gpg | gpg --dearmor | tee /usr/share/keyrings/ortussolutions.gpg > /dev/null
18+
#RUN echo "deb [signed-by=/usr/share/keyrings/ortussolutions.gpg] https://downloads.ortussolutions.com/debs/noarch /" | tee /etc/apt/sources.list.d/commandbox.list
19+
#RUN apt-get update && apt-get install -y apt-transport-https commandbox
20+
21+
# Install gitbook-exporter into the CommandBox.
22+
#RUN box install gitbook-exporter
23+
24+
# Run CommandBox shell with gitbook command available. (https://www.forgebox.io/view/gitbook-exporter)
25+
# Examples:
26+
#RUN gitbook pdf
27+
#RUN gitbook epub
28+

Makefile

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,56 @@ help: ## Print help
99
.PHONY: run
1010
run: image ## docker run ...
1111
(docker stop linux-insides-book 2>&1) > /dev/null || true
12-
docker run --detach --rm -p 4000:4000 --name linux-insides-book --hostname linux-insides-book linux-insides-book
12+
docker run --detach -p 4000:4000 --name linux-insides-book --hostname linux-insides-book linux-insides-book
13+
14+
.PHONY: start
15+
start: ## start the docker container ...
16+
docker start linux-insides-book
1317

1418
.PHONY: image
1519
image: ## docker image build ...
1620
docker image build --rm --squash --label linux-insides --tag linux-insides-book:latest -f Dockerfile . 2> /dev/null || \
1721
docker image build --rm --label linux-insides --tag linux-insides-book:latest -f Dockerfile .
1822

23+
.PHONY: sh
24+
sh: ## run interactive shell inside an already running docker container ...
25+
docker exec -it linux-insides-book sh
26+
27+
.PHONY: rm
28+
rm: ## remove the docker container ...
29+
(docker stop linux-insides-book 2>&1) > /dev/null || true
30+
(docker rm linux-insides-book 2>&1) > /dev/null || true
31+
32+
.PHONY: logs
33+
logs: ## gather logs from the docker container ...
34+
docker logs linux-insides-book
35+
36+
.PHONY: export
37+
export: ## run e-book generation inside an already running docker container ...
38+
docker exec linux-insides-book /bin/bash -c " \
39+
gitbook epub; \
40+
gitbook mobi; \
41+
gitbook pdf; \
42+
mv book.pdf book-A4.pdf; \
43+
mv book-A5.json book.json; \
44+
gitbook pdf; \
45+
mv book.pdf book-A5.pdf; \
46+
mv book-A4.pdf book.pdf"
47+
48+
.PHONY: cp
49+
cp: ## copy all exported e-book formats to current working directory ...
50+
docker cp linux-insides-book:/srv/gitbook/book.epub "Linux Inside - 0xAX.epub"
51+
docker cp linux-insides-book:/srv/gitbook/book.mobi "Linux Inside - 0xAX.mobi"
52+
docker cp linux-insides-book:/srv/gitbook/book.pdf "Linux Inside - 0xAX.pdf"
53+
docker cp linux-insides-book:/srv/gitbook/book-A5.pdf "Linux Inside - 0xAX (A5).pdf"
54+
55+
.PHONY: clean
56+
clean: ## remove all exported e-book files ...
57+
rm "Linux Inside - 0xAX.epub" \
58+
"Linux Inside - 0xAX.mobi" \
59+
"Linux Inside - 0xAX.pdf" \
60+
"Linux Inside - 0xAX (A5).pdf"
61+
1962
### LAUNCH BROWSER
2063

2164
.PHONY: browse

book-A5.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"title": "Linux Insides",
3+
"author" : "0xAX",
4+
"pdf": {
5+
"paperSize": "a5",
6+
"margin":
7+
{
8+
"top": 48,
9+
"bottom": 48,
10+
"right": 28,
11+
"left": 28
12+
}
13+
}
14+
}

book.json

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
11
{
22
"title": "Linux Insides",
3-
"author" : "0xAX",
4-
"pdf": {
5-
"paperSize": "a5",
6-
"margin":
7-
{
8-
"top": 48,
9-
"bottom": 48,
10-
"right": 28,
11-
"left": 28
12-
}
13-
}
3+
"author" : "0xAX"
144
}

0 commit comments

Comments
 (0)