Last active
October 16, 2023 16:20
-
-
Save nandorojo/9c53dbf01ec37ce6d3bb9814fdb3937b to your computer and use it in GitHub Desktop.
Create EAS Update Preview on each commit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Expo Preview | |
on: | |
push: | |
branches: [dev*, preview*] | |
paths: | |
- "**.ts" | |
- "**.tsx" | |
- "**.js" | |
- "**.json" | |
- "**.jsx" | |
- "**.patch" | |
- "**.lock" | |
- ".env.*" | |
- ".github/workflows/**" | |
workflow_dispatch: | |
jobs: | |
commit-preview: | |
name: Preview Expo Commit | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
app-env: [dev, dev-sandbox] | |
steps: | |
- name: Setup repo | |
uses: actions/checkout@v2 | |
- name: Setup node | |
uses: actions/setup-node@v1 | |
with: | |
node-version: 14.x | |
- name: Remove Remotion | |
run: rm -rf ./applications/remotion | |
- name: Start Deployment | |
uses: bobheadxi/deployments@v0.4.3 | |
id: deployment | |
with: | |
step: start | |
token: ${{ secrets.GITHUB_TOKEN }} | |
env: ${{ matrix.app-env }} | |
- name: Authenticate with private NPM package | |
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
- name: Find yarn cache | |
id: yarn-cache-path | |
run: echo "::set-output name=dir::$(yarn cache dir)" | |
- name: Restore cache | |
uses: actions/cache@v2 | |
with: | |
path: ${{ steps.yarn-cache-path.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Install dependencies | |
run: yarn install --frozen-lockfile --check-files | |
- uses: expo/expo-github-action@v6 | |
with: | |
eas-version: latest | |
eas-cache: true | |
expo-cache: true | |
expo-version: latest | |
token: ${{ secrets.EXPO_TOKEN }} | |
- uses: 8BitJonny/gh-get-current-pr@1.1.0 | |
id: PR | |
name: Check if we're in a PR | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
filterOutClosed: false | |
- name: Dotenv | |
uses: falti/dotenv-action@v0.2.7 | |
id: dotenv | |
with: | |
path: ".env.${{ matrix.app-env }}" | |
log-variables: true | |
- name: EAS Branch Name | |
id: eas-branch | |
run: echo "::set-output name=branch::commit-${{ github.sha }}" | |
- name: Publish Preview to EAS | |
id: eas | |
if: success() | |
run: APP_ENV=${{ matrix.app-env }} eas update --branch ${{ steps.eas-branch.outputs.branch }} --message "${{ github.event.head_commit.message }}" | |
- name: Expo Manifest URL | |
id: manifest | |
run: echo "::set-output name=url::exp+${{ steps.dotenv.outputs.EXPO_APP_SLUG }}://expo-development-client/?url=https://u.expo.dev/${{ steps.dotenv.outputs.EXPO_PROJECT_ID }}?channel-name=${{ matrix.app-env }}&branch=${{ steps.eas-branch.outputs.branch }}" | |
- name: QR Code URL | |
id: qrcode | |
run: echo "::set-output name=url::https://qr.expo.dev/development-client?appScheme=${{ steps.manifest.outputs.url }}" | |
- name: Update Deployment Status | |
uses: bobheadxi/deployments@v0.4.3 | |
if: always() | |
with: | |
step: finish | |
token: ${{ secrets.GITHUB_TOKEN }} | |
status: ${{ job.status }} | |
deployment_id: ${{ steps.deployment.outputs.deployment_id }} | |
# env_url: ${{ steps.preview.outputs.EXPO_MANIFEST_URL }} | |
env_url: ${{ steps.manifest.outputs.url }} | |
# https://stackoverflow.com/questions/59810838/how-to-get-the-short-sha-for-the-github-workflow/59819441#59819441 | |
- name: Create Short Commit SHA | |
id: get-commit-sha | |
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" | |
- name: Get Commit URL | |
id: commit-url | |
run: echo "::set-output name=commit-url::https://github.com/${{ github.repository_owner }}/${{ github.repository }}/commits/${{ github.sha }}" | |
- name: Find Commits Comment (maybe exists) | |
uses: peter-evans/find-comment@v1 | |
if: success() && steps.PR.outputs.number != '' | |
id: maybe-commits-comment | |
with: | |
issue-number: ${{ steps.PR.outputs.number }} | |
body-includes: ${{ matrix.app-env }} Commit Previews | |
- name: Create Commits Comment (if missing) | |
uses: peter-evans/create-or-update-comment@v1 | |
id: create-commit-previews-comment | |
if: success() && steps.PR.outputs.number != '' && steps.maybe-commits-comment.outputs.comment-id == '' | |
with: | |
issue-number: ${{ steps.PR.outputs.number }} | |
body: | | |
## ${{ matrix.app-env }} Commit Previews 🎹 | |
- name: Find Commits Comment (certainly exists) | |
uses: peter-evans/find-comment@v1 | |
if: success() && steps.PR.outputs.number != '' | |
id: commits-comment | |
with: | |
issue-number: ${{ steps.PR.outputs.number }} | |
body-includes: ${{ matrix.app-env }} Commit Previews | |
- name: Add commit preview to PR | |
uses: peter-evans/create-or-update-comment@v1 | |
if: success() && steps.PR.outputs.number != '' && steps.publish-url.outputs.url != '' && steps.commits-comment.outputs.comment-id != '' | |
with: | |
comment-id: ${{ steps.commits-comment.outputs.comment-id }} | |
issue-number: ${{ steps.PR.outputs.number }} | |
edit-mode: append | |
body: | | |
<details> | |
<summary>(<a href="${{ steps.commit-url.outputs.commit-url }}">${{ steps.get-commit-sha.outputs.sha_short }}</a>) ${{ github.event.head_commit.message }}</summary> | |
<br /> | |
You can <a href="${{ steps.manifest.outputs.url }}">view the published **${{ steps.dotenv.outputs.EXPO_APP_NAME }}** app</a> now. 🥸 | |
<a href="${{ steps.qrcode.outputs.url }}"><img src="${{ steps.qrcode.outputs.url }}" height="200px" width="200px"></a> | |
Manifest URL: ${{ steps.manifest.outputs.url }}<br> | |
<a href="${{ steps.commit-url.outputs.commit-url }}">View commit</a> | |
0th message: ${{ github.event.commits[0].message }} | |
Head message: ${{ github.event.head_commit.message }} | |
</details> | |
- name: Comment on commit (if there's no PR) | |
uses: peter-evans/commit-comment@v1 | |
if: ${{ success() && steps.publish-url.outputs.url != '' && steps.PR.outputs.number == '' }} | |
with: | |
sha: ${{ github.sha }} | |
body: | | |
<details> | |
<summary>${{ matrix.app-env }} Expo Preview</summary> | |
You can <a href="${{ steps.manifest.outputs.url }}">view the published **${{ steps.dotenv.outputs.EXPO_APP_NAME }}** app</a> now. 🥸 | |
<a href="${{ steps.qrcode.outputs.url }}"><img src="${{ steps.qrcode.outputs.url }}" height="200px" width="200px"></a> | |
Manifest URL: ${{ steps.manifest.outputs.url }}<br> | |
<a href="${{ steps.commit-url.outputs.commit-url }}">View commit</a> | |
0th message: ${{ github.event.commits[0].message }} | |
Head message: ${{ github.event.head_commit.message }} | |
</details> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment