Skip to content

Commit 69801f0

Browse files
authored
feat: implement caching using github actions cache (#35)
* feat: implement remote cache based on github actions cache This allows us to use an internal remote cache, which is not "supported" by GitHub though. * docs: update documentation about the built-in cache
1 parent 3ac4a96 commit 69801f0

11 files changed

Lines changed: 8424 additions & 3608 deletions

File tree

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"jest"
66
],
77
"env": {
8+
"es6": true,
89
"jest/globals": true,
910
"node": true
1011
},

README.md

Lines changed: 80 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,12 @@ You can also use [the Docker image][link-docker-expo] in other Docker-based envi
99
3. [Example workflows](#example-workflows)
1010
4. [Things to know](#things-to-know)
1111

12-
1312
## What's inside?
1413

1514
Within this Expo action, you have full access to the [Expo CLI][link-expo-cli] itself.
1615
That means you can perform any command like login, publish, and build.
1716
Also, this action takes care of authentication when both `expo-username` and `expo-password` variables are defined.
1817

19-
> You don't necessarily need this action to use Expo.
20-
> You can also add `expo-cli` as a dependency to your project and use `npx expo ...` for example.
21-
> However, when you do that you need to perform authentication yourself.
22-
23-
2418
## Used variables
2519

2620
This action is customizable through variables; they are defined in the [`action.yml`][link-expo-cli-action].
@@ -33,22 +27,22 @@ variable | description
3327
`expo-version` | The Expo CLI you want to use. _(can be any semver range, defaults to `latest`)_
3428
`expo-packager` | The package manager you want to use to install the CLI. _(can be `npm` or `yarn`, defaults to `yarn`)_
3529
`expo-patch-watchers` | If it should patch the `fs.inotify.` limits causing `ENOSPC` errors on Linux. _(can be `true` or `false`, defaults to `true`)_
30+
`expo-cache` | If it should the actions cache, [read more about it here](#using-the-built-in-cache) _(can be `true` or `false`, defaults to `false`)_
31+
`expo-cache-key` | An optional custom remote cache key _(**warning**, only use this when you know what you are doing)_
3632

3733
> It's recommended to set the `expo-version` to avoid breaking changes when a new major version is released.
3834
> For more info on how to use this, please read the [workflow syntax documentation][link-actions-syntax-with].
3935
40-
4136
## Example workflows
4237

4338
Before you dive into the workflow examples, you should know the basics of GitHub Actions.
4439
You can read more about this in the [GitHub Actions documentation][link-actions].
4540

4641
1. [Publish on any push to master](#publish-on-any-push-to-master)
47-
2. [Test PRs on Linux, MacOS and Windows](#test-prs-on-linux-macos-and-windows)
48-
3. [Test PRs on Node 10 and 12](#test-prs-on-node-10-and-12)
49-
4. [Test and build web every day at 08:00](#test-and-build-web-every-day-at-0800)
50-
5. [Use Docker for improved performance](#use-docker-for-improved-performance)
51-
42+
2. [Cache Expo CLI for other jobs](#cache-expo-cli-for-other-jobs)
43+
3. [Test PRs and publish a review version](#test-prs-and-publish-a-review-version)
44+
4. [Test PRs on multiple nodes and systems](#test-prs-on-multiple-nodes-and-systems)
45+
5. [Test and build web every day at 08:00](#test-and-build-web-every-day-at-0800)
5246

5347
### Publish on any push to master
5448

@@ -76,29 +70,56 @@ jobs:
7670
expo-version: 3.x
7771
expo-username: ${{ secrets.EXPO_CLI_USERNAME }}
7872
expo-password: ${{ secrets.EXPO_CLI_PASSWORD }}
79-
- run: npm ci
73+
- run: yarn install
8074
- run: expo publish
8175
```
8276
77+
### Cache Expo CLI for other jobs
8378
84-
### Test PRs on Linux, MacOS, and Windows
79+
Below you can see a slightly modified version of the example above.
80+
In this one, we enabled the built-in cache that will reuse a previous installed Expo CLI.
81+
This skips the installation part and extracts the files directly, boosting the performance of your workflow.
8582
86-
With GitHub Actions, it's reasonably easy to set up a matrix build and test the app on various operating systems.
87-
These matrixes can help to make sure your app runs smoothly on a broad set of different development machines.
88-
The action below is only running on pull requests to avoid unnecessary builds.
83+
> You can [read more about the cache here](#using-the-built-in-cache)
8984
90-
> If you don't need automatic authentication, you can omit the `expo-username` and `expo-password` variables.
85+
```yml
86+
name: Expo Publish
87+
on:
88+
push:
89+
branches:
90+
- master
91+
jobs:
92+
publish:
93+
name: Install and publish
94+
runs-on: ubuntu-latest
95+
steps:
96+
- uses: actions/checkout@v1
97+
- uses: actions/setup-node@v1
98+
with:
99+
node-version: 12.x
100+
- uses: expo/expo-github-action@v4
101+
with:
102+
expo-version: 3.x
103+
expo-username: ${{ secrets.EXPO_CLI_USERNAME }}
104+
expo-password: ${{ secrets.EXPO_CLI_PASSWORD }}
105+
expo-cache: true
106+
- run: yarn install
107+
- run: expo publish
108+
```
109+
110+
### Test PRs and publish a review version
111+
112+
Reviewing pull requests can take some time if you have to read every line of code.
113+
To make this easier, you can publish the edited version of the PR using a dedicated release channel.
114+
Below you can see an example of a workflow that publishes and comments when the app is ready for review.
91115
92116
```yml
93-
name: Expo CI
117+
name: Expo Review
94118
on: [pull_request]
95119
jobs:
96-
ci:
97-
name: Continuous Integration
98-
runs-on: ${{ matrix.os }}
99-
strategy:
100-
matrix:
101-
os: [ubuntu-latest, macOS-latest, windows-latest]
120+
publish:
121+
name: Install and publish
122+
runs-on: ubuntu-latest
102123
steps:
103124
- uses: actions/checkout@v1
104125
- uses: actions/setup-node@v1
@@ -107,27 +128,36 @@ jobs:
107128
- uses: expo/expo-github-action@v4
108129
with:
109130
expo-version: 3.x
110-
- run: npm ci
111-
- run: npm test
112-
- run: expo doctor
131+
expo-username: ${{ secrets.EXPO_CLI_USERNAME }}
132+
expo-password: ${{ secrets.EXPO_CLI_PASSWORD }}
133+
- run: yarn install
134+
- run: expo publish --release-channel=pr-${{ github.event.number }}
135+
- uses: unsplash/comment-on-pr@master
136+
env:
137+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
138+
with:
139+
msg: App is ready for review, you can [see it here](https://expo.io/@bycedric/use-expo?release-channel=pr-${{ github.event.number }}).
113140
```
114141
142+
### Test PRs on multiple nodes and systems
115143
116-
### Test PRs on Node 10 and 12
144+
With GitHub Actions, it's reasonably easy to set up a matrix build and test the app on multiple environments.
145+
These matrixes can help to make sure your app runs smoothly on a broad set of different development machines.
146+
The action below is only running on pull requests to avoid unnecessary builds.
117147
118-
Sometimes you want to double-check if your app builds on multiple node versions.
119-
Setting this up is just as easy as defining a matrix build for multiple systems.
148+
> If you don't need automatic authentication, you can omit the `expo-username` and `expo-password` variables.
120149

121150
```yml
122151
name: Expo CI
123152
on: [pull_request]
124153
jobs:
125154
ci:
126155
name: Continuous Integration
127-
runs-on: ubuntu-latest
156+
runs-on: ${{ matrix.os }}
128157
strategy:
129158
matrix:
130-
node: [10, 12]
159+
os: [ubuntu-latest, macOS-latest, windows-latest]
160+
node: [10, 12, 13]
131161
steps:
132162
- uses: actions/checkout@v1
133163
- uses: actions/setup-node@v1
@@ -136,12 +166,11 @@ jobs:
136166
- uses: expo/expo-github-action@v4
137167
with:
138168
expo-version: 3.x
139-
- run: npm ci
140-
- run: npm test
169+
- run: yarn install
170+
- run: yarn test
141171
- run: expo doctor
142172
```
143173

144-
145174
### Test and build web every day at 08:00
146175

147176
You can also schedule jobs by using the cron syntax.
@@ -165,68 +194,29 @@ jobs:
165194
- uses: expo/expo-github-action@v4
166195
with:
167196
expo-version: 3.x
168-
- run: npm ci
169-
- run: npm test
197+
- run: yarn install
198+
- run: yarn test
170199
- run: expo build:web
171200
```
172201

202+
## Things to know
173203

174-
### Use Docker for improved performance
175-
176-
Unfortunately, GitHub Actions lack a feature to cache files and directories across multiple jobs.
177-
Because of this, the action has to pull and install the [Expo CLI][link-expo-cli] _on every run_.
178-
If you want faster runs and don't care about customizing your workflows in detail, you can use [the Expo Docker image][link-docker-expo] to speed things up.
179-
180-
> Because Docker uses a predefined environment, you lose the ability to customize the Node versions and system types.
181-
> For most projects this won't be an issue, but please make sure you understand the tradeoffs.
182-
> This approach is also a robust way and won't break once we implement the caching feature.
183-
184-
```yml
185-
name: Expo Publish
186-
on:
187-
push:
188-
branches:
189-
- master
190-
jobs:
191-
publish:
192-
name: Install and publish
193-
runs-on: ubuntu-latest
194-
steps:
195-
- uses: actions/checkout@v1
196-
- uses: actions/setup-node@v1
197-
with:
198-
node-version: 12.x
199-
- run: npm ci
200-
- uses: docker://bycedric/expo-cli:3
201-
with:
202-
args: publish
203-
env:
204-
EXPO_CLI_USERNAME: ${{ secrets.EXPO_CLI_USERNAME }}
205-
EXPO_CLI_PASSWORD: ${{ secrets.EXPO_CLI_PASSWORD }}
206-
```
207-
208-
209-
### Things to know
210-
211-
212-
#### Automatic Expo login
204+
### Automatic Expo login
213205

214206
You need to authenticate for some Expo commands as `expo publish` and `expo build:*`.
215207
This project has an additional feature to make this easy and secure.
216208
The action uses the [`EXPO_CLI_PASSWORD`][link-expo-cli-password] variable internally to make this happen.
217209

210+
### Using the built-in cache
218211

219-
#### Why is the action slow?
212+
As of writing, GitHub Actions lacks a feature to "cache" files and directories in 3rd party actions.
213+
That's why we implemented the [Cypress fork of the `actions/cache`][link-actions-cache-cypress] to enable some sort of caching.
214+
You can opt-in to this by setting the `expo-cache` variable to `true`.
215+
If you know what you are doing and need more control, you can also define a custom cache key with `expo-cache-key`.
220216

221-
As of writing, GitHub Actions lacks a feature to "cache" files and directories across multiple jobs.
222-
Because of this, the action has to pull and install the [Expo CLI][link-expo-cli] _on every run_.
223-
Fortunately, GitHub is working on a feature that should make this happen, but it's not available yet.
224-
If this is a show-stopper for you, read about how to set the [Expo CLI up with Docker](#use-docker-for-improved-performance).
225-
Please note that this approach has its limitations and make sure you understand these before trying this out.
226-
When GitHub releases this caching feature, we will implement this feature and it and make it significantly faster.
217+
> Note, this cache will count towards your [repo cache limit][link-actions-cache-limit].
227218

228-
229-
#### ENOSPC errors on Linux
219+
### ENOSPC errors on Linux
230220

231221
React Native bundles are created by the Metro bundler, even when using Expo.
232222
Unfortunately, this Metro bundler requires quite some resources.
@@ -235,18 +225,20 @@ Inside we included a patch that increases these limits for the "active workflow"
235225
It increases the `max_user_instances`, `max_user_watches` and `max_queued_events` to `524288`.
236226
You can disable this patch by setting the `expo-patch-watchers` to `false`.
237227

238-
239228
## License
240229

241230
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
242231

243232
--- ---
244233

245234
<p align="center">
246-
with :heart: <a href="https://bycedric.com" target="_blank">byCedric</a>
235+
with :heart: <a href="https://bycedric.com" target="_blank">byCedric</a>
247236
</p>
248237

249238
[link-actions]: https://help.github.com/en/categories/automating-your-workflow-with-github-actions
239+
[link-actions-cache]: https://github.com/actions/cache
240+
[link-actions-cache-cypress]: https://github.com/cypress-io/github-actions-cache
241+
[link-actions-cache-limit]: https://github.com/actions/cache#cache-limits
250242
[link-actions-node]: https://github.com/actions/setup-node
251243
[link-actions-secrets]: https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables
252244
[link-actions-syntax-with]: https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepswith

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ input:
2222
expo-patch-watchers:
2323
description: If Expo should fix the default watchers limit, helps with ENOSPC errors. (can be true or false)
2424
default: true
25+
expo-cache:
26+
description: If Expo should be stored in the GitHub Actions cache (can be true or false)
27+
default: false
28+
expo-cache-key:
29+
description: A custom remote cache key to use (best to let GitHub Actions handle it)

0 commit comments

Comments
 (0)