Skip to content

Commit ccfad6f

Browse files
authored
docs(preview): clarify the branch and workflow trigger relations (#246)
1 parent 6a82be3 commit ccfad6f

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ jobs:
174174
- name: 🚀 Create preview
175175
uses: expo/expo-github-action/preview@v8
176176
with:
177-
command: eas update --auto
177+
# `github.event.pull_request.head.ref` is only available on `pull_request` triggers.
178+
# Use your own, or keep the automatically infered branch name from `--auto`, when using different triggers.
179+
command: eas update --auto --branch ${{ github.event.pull_request.head.ref }}
178180
```
179181
180182
## Things to know

preview/README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,12 @@ You can read more about this in the [GitHub Actions documentation][link-actions]
123123
### Create previews on pull requests
124124

125125
This workflow creates a new EAS Update every time a pull request is created or updated.
126-
Since we're using the `--auto` flag, the EAS branch will be named after the GitHub branch, and the message for the update will match the commit's message.
126+
We are using the `--auto`, together with the `--branch`, flag in this example.
127+
- `--auto` will automatically create an update using the current git commit message and git branch.
128+
- `--branch` will overwrite this value infere from git with our own value.
129+
130+
> **Warning**
131+
> GitHub Actions might use a temporary merge branch for PRs. To avoid using this merge branch for our update, we overwrite the branch name from `--auto` with our own `--branch` value.
127132
128133
```yml
129134
on:
@@ -156,7 +161,9 @@ jobs:
156161
- name: 🚀 Create preview
157162
uses: expo/expo-github-action/preview@v8
158163
with:
159-
command: eas update --auto
164+
# `github.event.pull_request.head.ref` is only available on `pull_request` triggers.
165+
# Use your own, or keep the automatically infered branch name from `--auto`, when using different triggers.
166+
command: eas update --auto --branch ${{ github.event.pull_request.head.ref }}
160167
```
161168
162169
### Sending preview information elsewhere
@@ -197,6 +204,8 @@ jobs:
197204
uses: expo/expo-github-action/preview@v8
198205
id: preview
199206
with:
207+
# In this example, we use the `push` trigger which will always use the branch name that was pushed to.
208+
# By using `--auto` we both use the git commit message and branch name for the update.
200209
command: eas update --auto
201210
comment: false
202211

@@ -216,6 +225,13 @@ jobs:
216225
When automating these preview comments, you have to be careful not to spam a pull request on every successful run.
217226
Every comment contains a generated **message-id** to identify previously made comments and update them instead of creating a new comment.
218227
228+
### Update branch and workflow triggers
229+
230+
GitHub Actions uses slightly different checkout logic for different workflow triggers.
231+
When using the `push` trigger, GitHub Actions checks out the branch that was pushed to.
232+
But for [`pull_request` triggers][link-gha-trigger-pull], GitHub Actions might use a temporary branch name.
233+
This affects in what "branch" your EAS Update is created when using the `--auto` flag.
234+
219235
### GitHub tokens
220236

221237
When using the GitHub API, you always need to be authenticated.
@@ -231,3 +247,5 @@ You can overwrite the token by adding the `GITHUB_TOKEN` environment variable or
231247
[code-defaults]: ../src/actions/preview.ts#L10
232248
[link-actions]: https://help.github.com/en/categories/automating-your-workflow-with-github-actions
233249
[link-gha-token]: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
250+
[link-gha-trigger-pull]: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
251+
[link-gha-trigger-push]: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push

0 commit comments

Comments
 (0)