Skip to content
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

Add action to auto generate Ebooks #1123

Merged
merged 6 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/generate_ebooks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
######################################
## Custom Web Almanac GitHub action ##
######################################
#
# Generate the ebooks when this GitHub Action is run manually
# This should be run everytime before release
#
name: Generate Ebooks

env:
# Update periodically from https://www.princexml.com/latest/
PRINCE_PACKAGE: 'prince_20200728-1_ubuntu20.04_amd64.deb'

on:
workflow_dispatch:

jobs:
build:
# Prince needs ubuntu 20 and ubuntu-latest is only on 18
runs-on: ubuntu-20.04
steps:
- name: Checkout branch
uses: actions/checkout@v2
- name: Setup Node.js for use with actions
uses: actions/[email protected]
with:
version: 12.x
# Install Python 3.7 as used by Google Cloud Platform
- name: Set up Python 3.7
uses: actions/setup-python@v2
with:
python-version: '3.7'
- name: Install Python requirements
run: |
echo "Installing Python requirements"
python -m pip install --upgrade pip
cd src
pip install -r requirements.txt
- name: Install node modules
run: |
echo "Running npm install"
cd src
npm install
- name: Install PrinceXML
run: |
echo "Installing PrinceXML"
cd /tmp
sudo apt-get install -y aptitude
sudo aptitude install -y gdebi
wget https://www.princexml.com/download/${{ env.PRINCE_PACKAGE }}
sudo gdebi --non-interactive ${{ env.PRINCE_PACKAGE }}
- name: Run website
run: |
echo "Running website"
cd src
python main.py background &
- name: Generating Ebooks
run: |
echo "Generating ebooks"
cd src
npm run ebooks
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v3
with:
title: Regenerate Ebooks
branch-suffix: timestamp
commit-message: Generate Ebooks
body: |
Regenerated Ebooks through GitHub action
- Auto-generated by [create-pull-request][1] GitHub Action

[1]: https://github.com/peter-evans/create-pull-request
labels: generate chapters
- name: Check outputs
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
16 changes: 11 additions & 5 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,32 @@ ptw

The chapter generation is dependent on nodejs, so you will need to have [nodejs](https://nodejs.org/en/) installed as well. All of the following commands must be run from within the `src` directory by executing `cd src` first.

1. Install the dependencies:
Note this is run automatically by a GitHub Action on merges to main, so does not need to be run manually.

Install the dependencies:

```
npm install
```

2. Run the generate chapters script:
Run the generate chapters script:

```
npm run generate
```

3. For generating PDFs of the ebook, you need to install Prince. Follow the instructions on [the Prince Website](https://www.princexml.com/).
## Generating Ebooks

For generating PDFs of the ebook, you need to install Prince. Follow the instructions on [the Prince Website](https://www.princexml.com/).

4. To actually generate the ebooks, start your local server, then run the following:
To actually generate the ebooks, start your local server, then run the following:

```
npm run ebooks
```

There is a GitHub Action which can be run manually from the Actions tab to generate the Ebooks and open a Pull Request for them.

## Generating ebooks - including print-ready ebooks if you want a hardcopy

It is also possible to generate the ebook from the website (either production or 127.0.0.1), with some optional params (e.g. to print it!)
Expand Down Expand Up @@ -136,7 +142,7 @@ With the print-ready eBook and Cover you can send them to a printer. I used http

If you've been added to the "App Engine Deployers" role in the GCP project, you're able to push code changes to the production website.

_Make sure you have generated the ebooks PDFs as that currently requires some extra steps that are not automated!_
_Make sure you have generated the ebooks PDFs by running the Generate Ebooks GitHub Action_

1. Install the [`gcloud`](https://cloud.google.com/sdk/install) Google Cloud SDK.

Expand Down