-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Generate e-books for every release and PR #874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
28cde30
Make targets related to gitbook export and Docker configuraiton
9557d17
Chapter Booting: Fixed SVG images
f4031af
Generate e-books for every release and PR
258b662
Merge pull request #4 from 0xAX/master
kyselejsyrecek 34d15b9
Revert "Chapter Booting: Fixed SVG images"
8d7b615
Merge pull request #6 from 0xAX/master
kyselejsyrecek 3c3ad21
Post-review fixes
4c10e7d
Merge pull request #7 from kyselejsyrecek/gitbook
kyselejsyrecek 0e89884
Change e-book retention period in PRs to 7 days
95f7045
Merge pull request #8 from kyselejsyrecek/gitbook
kyselejsyrecek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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')" | ||
|
0xAX marked this conversation as resolved.
Outdated
|
||
| 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 | ||
| }); | ||
|
0xAX marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,28 @@ | ||
| FROM lrx0014/gitbook:3.2.3 | ||
| COPY ./ /srv/gitbook/ | ||
| EXPOSE 4000 | ||
| 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 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "title": "Linux Insides", | ||
| "author" : "0xAX", | ||
| "pdf": { | ||
| "paperSize": "a5", | ||
| "margin": | ||
| { | ||
| "top": 48, | ||
| "bottom": 48, | ||
| "right": 28, | ||
| "left": 28 | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,4 @@ | ||
| { | ||
| "title": "Linux Insides", | ||
| "author" : "0xAX", | ||
| "pdf": { | ||
| "paperSize": "a5", | ||
| "margin": | ||
| { | ||
| "top": 48, | ||
| "bottom": 48, | ||
| "right": 28, | ||
| "left": 28 | ||
| } | ||
| } | ||
| "author" : "0xAX" | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this moment I'd also comment this as probably to generate export for each PR while I am rewriting content and it is in the "middle" state is not the best time.
@kyselejsyrecek what do you think?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be. I knew the generated e-book or a PDF output might come handy sometimes just to be able to briefly check if a change, yours or others', looks rendered the way you would expect it to. It runs in parallel with the code check and the file retention period is configurable with the
retention-daysattribute. The output is re-generated each time the code in the pull request is updated. It does not create a new release, of course, just attaches a link to the generated files to the PR. That part might be confusing. UPDATE: I'll separate these jobs anyway.But the point really was to just provide this possibility if wanted, not to insist on having it merged. I am quite new to the GitHub Workflow API but I guess that this section may be moved to another YAML file and then, from the GitHub GUI, one may disable the separate workflow for however long they chose. Or it could be completely removed if you choose. I am guessing there is no way to make it work for pull requests from the repository forks at this moment on GitHub, so it might actually turn out to be worthless anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After day of thinking I am OK with this. Let's leave it as is but let's maybe make for now data retention shorter, like week or two.
In future it probably will be more comfortable to generate PDF after each commit to markdown file and keep the pdf and other in git tree 🤔. We will see. In general I am pretty happy with the current state what you did.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright. The data retention period was shortened to 7 days.