Skip to content

Commit 1243751

Browse files
authoredJan 11, 2021
docs: add GitHub Actions to pages documentation
fixes #165 Co-Authored-By: dieghernan@users.noreply.github.com
1 parent 9dd5175 commit 1243751

File tree

1 file changed

+54
-18
lines changed

1 file changed

+54
-18
lines changed
 

‎docs-src/src/github-pages.md

+54-18
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,56 @@ layout: content-with-menu.pug
55

66
# Deploying on GitHub Pages
77

8-
GitHub offers free hosting for static websites through its [GitHub Pages][1] feature.
9-
It also has builtin support for Jekyll website. Once [properly configured][2],
10-
every time you push your Jekyll website to GitHub, it will be deployed on
11-
a `username.github.io/reponame` url.
8+
GitHub offers free hosting for static websites through its [GitHub Pages][1] feature. It also has builtin support for Jekyll website. Once [properly configured][2], every time you push your Jekyll website to GitHub, it will be deployed on a `username.github.io/reponame` url.
129

13-
But GitHub will only build your website (`jekyll build`), it will not run other
14-
commands (like `jekyll algolia`), so if you want to update your search results on
15-
each push, you'll have to find another way.
10+
But GitHub will only build your website (`jekyll build`), it will not run other commands (like `jekyll algolia`), so if you want to update your search results on each push, you'll have to find another way. This can be done using GitHub Actions, or via a Continuous Integration provider like Travis CI.
1611

17-
We recommend using [Netlify][3], but if you want to stay hosted on GitHub pages,
18-
this page will explain how to keep your search records in sync with your
19-
deployed website.
12+
We recommend using [Netlify][3] to host the whole pipeline, but if you want to stay hosted on GitHub pages, this page will explain how to keep your search records in sync with your deployed website.
2013

21-
## Enabling Travis
14+
## Using GitHub Actions
15+
16+
First enable [GitHub Actions][6] on your account, and then create this new action under for example `.github/workflows/algolia-search.yml`.
17+
18+
```yaml
19+
on:
20+
push:
21+
branches:
22+
- master
23+
- main
24+
25+
name: algolia-search
26+
27+
jobs:
28+
algolia-search:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v2
32+
- uses: actions/setup-ruby@v1
33+
with:
34+
ruby-version: '2.6'
35+
- uses: actions/cache@v2
36+
with:
37+
path: vendor/bundle
38+
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
39+
restore-keys: |
40+
${{ runner.os }}-gems-
41+
42+
- name: Bundle install
43+
run: |
44+
bundle config path vendor/bundle
45+
bundle install --jobs 4 --retry 3
46+
47+
- name: Exec jekyll algolia
48+
run: bundle exec jekyll algolia
49+
env:
50+
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
51+
```
52+
53+
Then create `ALGOLIA_API_KEY` secret in the repository settings > secrets with the Admin API Key.
54+
55+
## Using Travis CI
56+
57+
### Enabling Travis
2258

2359
[Travis CI][4] is an hosted continuous integration service, and it's free for
2460
open-source projects. It can listen to any changes in your GitHub repository and
@@ -38,7 +74,7 @@ This will avoid re-indexing your data every time you receive a pull request._
3874

3975
![Travis configuration](./assets/images/travis-config.png)
4076

41-
## Configuring Travis
77+
### Configuring Travis
4278

4379
Now that Travis is enabled, we have to configure it to tell it what to do on
4480
every new push to your repo. This can be done through the Travis UI, but we
@@ -59,18 +95,17 @@ branches:
5995
# Change this to gh-pages if you're deploying using the gh-pages branch
6096
- master
6197
rvm:
62-
- 2.4
98+
- 2.4
6399
```
64100

65101
This file will be read by Travis and instruct it to fetch all the dependencies
66-
defined in the `Gemfile` through Bundler. It will then run `bundle exec jekyll
67-
algolia` which will actually index your data.
102+
defined in the `Gemfile` through Bundler. It will then run `bundle exec jekyll algolia` which will actually index your data.
68103

69104
You might have to edit the `branches.only` value to either `master` or
70105
`gh-pages`, depending on which branch is configured to be deployed in your
71106
GitHub Pages configuration.
72107

73-
### Ignoring vendors
108+
#### Ignoring vendors
74109

75110
Travis bundles all gems in the `vendor` directory on its servers, which Jekyll
76111
will mistakenly read. This will likely make the process fail. To avoid this,
@@ -80,7 +115,7 @@ add `vendor` to the `exclude` list in your `_config.yml` file.
80115
exclude: [vendor]
81116
```
82117

83-
## Adding the API Key
118+
### Adding the API Key
84119

85120
The plugin will need your Admin API key to push data. Because you don't want to
86121
expose this key in your repository, you'll have to add `ALGOLIA_API_KEY` as an
@@ -89,7 +124,7 @@ Settings page.
89124

90125
![Travis environment variables](./assets/images/travis-env.png)
91126

92-
## Done
127+
### Done
93128

94129
Commit all the changes you made, and then push your repository. Travis will
95130
catch the event and trigger your indexing for you. You can follow the Travis job
@@ -100,3 +135,4 @@ execution directly on your Travis dashboard, with a full log.
100135
[3]: ./netlify.html
101136
[4]: https://travis-ci.org/
102137
[5]: https://travis-ci.org/
138+
[6]: https://github.com/features/actions

0 commit comments

Comments
 (0)
Failed to load comments.