Add Expo preview comments to pull requests
This (sub)action allows you to comment on pull requests containing Expo QR codes. It can help speed up the review process by letting the reviewer load the app directly on their phone.
This action only creates the comment. You still have to publish the project.
This action is customizable through variables defined in the action.yml
.
Here is a summary of all the input options you can use.
variable | default | description |
---|---|---|
project | - | The relative path to the Expo project |
channel | default |
On what channel the project was published |
comment | true |
If this action should comment on a PR |
message | see code | The message template |
message-id | see code | A unique id template to prevent duplicate comments (read more) |
github-token | GITHUB_TOKEN |
A GitHub token to use when commenting on PR (read more) |
There are a few variables available to generate the comment content. Some of these variables are also exported as subaction output. Here is a summary of these variables.
output name | template name | description |
---|---|---|
projectOwner | {projectOwner} |
The resolved owner of the project |
projectSlug | {projectSlug} |
The resolved slug of the project |
projectName | {projectName} |
The resolved name of the project |
projectLink | {projectLink} |
The expo.dev project link, including release channel |
projectQR | {projectQR} |
The QR code link, to load the project in Expo Go |
- | {channel} |
The release channel that was used |
message | - | The resolved message content |
messageId | - | The resolved message id content |
Before diving into the workflow examples, you should know the basics of GitHub Actions. You can read more about this in the GitHub Actions documentation.
This workflow listens to the pull_request
event and publishes a to Expo, on release channel pr-#
.
Once that's done, it will comment with the QR code on that same pull request.
It's essential to keep pull requests separated, by release channel, to avoid writing over pull requests.
on:
pull_request:
types: [opened, synchronize]
jobs:
preview:
runs-on: ubuntu-latest
steps:
- name: 🏗 Setup repo
uses: actions/checkout@v2
- name: 🏗 Setup Node
uses: actions/setup-node@v2
with:
node-version: 16.x
cache: yarn
- name: 🏗 Setup Expo
uses: expo/expo-github-action@v7
with:
expo-version: 5.x
token: ${{ secrets.EXPO_TOKEN }}
- name: 📦 Install dependencies
run: yarn install
- name: 🚀 Publish to Expo
run: expo publish --release-channel=pr-${{ github.event.number }} --non-interactive
- name: 💬 Comment in preview
uses: expo/expo-github-action/preview-comment@v7
with:
channel: pr-${{ github.event.number }}
You can also use this action to generate the comment without actually commenting.
By disabling commenting with comment set to false
, you can reuse this action with any workflow trigger and send it to any service accessible in GitHub Actions.
See Available variables for a list of all outputs.
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: 🏗 Setup repo
uses: actions/checkout@v2
- name: 🏗 Setup Node
uses: actions/setup-node@v2
with:
node-version: 16.x
cache: yarn
- name: 🏗 Setup Expo
uses: expo/expo-github-action@v7
with:
expo-version: latest
token: ${{ secrets.EXPO_TOKEN }}
- name: 📦 Install dependencies
run: yarn install
- name: 🚀 Publish preview
run: expo publish --release-channel=production --non-interactive
- name: 👷 Create preview comment
uses: expo/expo-github-action/preview-comment@v7
id: preview
with:
comment: false
channel: production
- name: 💬 Comment in Slack
uses: slackapi/[email protected]
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_TOKEN }}
with:
channel-id: deployments
slack-message: 'New deployment is ready!\n- Preview: ${{ steps.preview.outputs.projectQR }}'
When automating these preview comments, you have to be careful not to spam a pull request on every successful run. Every comment contains a generated message-id to identify previously made comments and update instead of creating a new comment.
When using the GitHub API, you always need to be authenticated.
This action tries to auto-authenticate using the Automatic token authentication from GitHub.
You can overwrite the token by adding the GITHUB_TOKEN
environment variable, or add the github-token input.
with ❤️ byCedric