Automate your Ibis eBook build process with this GitHub Action + Workflow
Tags: actionshackathon21, github, git, books
Published: 2021-11-17 14:40:37

## Introduction

The `ibis-build-action` action is a GitHub Action to automatically run your `ibis` builds on push events to your `main` branch.

[Ibis](https://github.com/themsaid/ibis) is an open-source PHP tool that lets you write eBooks in Markdown. It was created by [Mohamed Said](https://github.com/themsaid) who used it to generate his own eBook that he was writing at the time!

Ibis has allowed me to create multiple eBooks already. However not everyone has PHP and Composer installed on their laptops, so people who contribute to your eBook project might not be able to export the PDF of your eBook after their changes.

This is why I decided to create a GitHub Action that would let you automatically generate your Ibis builds directly on GitHub, without having PHP installed on your laptop.

---

### Submission Category:

Maintainer Must-Haves

---

## My Workflow

In order to automatically build your Ibis PDF files, create a directory called `.github/workflows/` and add a fill called `ibis.yml` with the following content:

```yaml
name: Ibis eBook Generation
on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@main
      with:
        fetch-depth: '0'
    - name: Build Ibis Export Files
      uses: bobbyiliev/ibis-build-action@main
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        IBIS_PATH: './'
        IBIS_BRANCH: 'main'
        EMAIL: 'bobby@bobbyiliev.com'
        COMMIT_MESSAGE: 'Updated Ibis Exorted Files'
```

### Environment Variables

This is the list of the environment variables that you need to keep in mind:

* `GITHUB_TOKEN`: Required for permission to tag the repo. You can leave it as it is.
* `IBIS_PATH`: The path to the Ibis init folder. By default it is `./` but if you have a custom location, make sure to update it
* `IBIS_BRANCH`: The Branch that the Ibis exported files will be commited and pushed to. Default is `main`.
* `EMAIL`: The email address that the commit will be associated with.
* `COMMIT_MESSAGE`: The commit message.

### Overview

You can find the `ibis-build-action` GitHub Action repository here:

{% github https://github.com/bobbyiliev/ibis-build-action  %}

The `ibis-build-action` GitHub Action does the following things once added to your repository. 

Every time you push to `main` or merge a PR to `main` this workflow takes palce:

* On push (or merge), the action will:
    * Clone the repository
    * Run the `ibis build` commands including the sample builds
    * Stage and commit the new exported eBook files to the specified branch
    * Pushes tag to GitHub

![ibis-build-action screenshot of completed action](https://imgur.com/ZaQUbKc.png)

This will provide you with your eBook PDF file generated and stored in your repository's content folder.

### Ebook Projects using the `ibis-build-action` GitHub action:

* [Introduction to Docker](https://github.com/bobbyiliev/introduction-to-docker-ebook)
* [Introduction to Git and GitHub](https://github.com/bobbyiliev/introduction-to-git-and-github-ebook)
* [Introduction to Bash Scripting](https://github.com/bobbyiliev/introduction-to-bash-scripting)
* [Introduction to SQL](https://github.com/bobbyiliev/introduction-to-sql)
* [Laravel tips and tricks](https://github.com/bobbyiliev/laravel-tips-and-tricks-ebook)

#### Alternative approach

As brought up to my attention recently by [Roberto B](https://twitter.com/RmeetsH), in case that you need more flexibility about managing the PDF, rather than using the `ibis-build-action` GitHub action, you can produce an artifact instead. 

Here is an example GitHub workflow provided by Robert which would do the same build but store the PDF as an artifact:

[Ibis artifact workflow](https://github.com/roberto-butti/50-drops-of-php/blob/main/.github/workflows/build-sample.yml)

## Conclusion

Ibis is a great tool and in case that you are planning to write an eBook make sure to give it a try!

By using the `ibis-build-action` GitHub Action, you can automate your eBook PDF generation on each push to a specific branch and always have an up-to date export of your eBook!

If you like this, make sure to follow me on Twitter:

[@bobbyiliev ](https://twitter.com/bobbyiliev_)

I hope that this was helpful!