1--- 2title: Use GitHub Actions 3description: Learn how to use GitHub Actions to automate publishing updates with EAS Update. 4--- 5 6import { Step } from '~/ui/components/Step'; 7 8A GitHub Action is a cloud function that runs every time an event on GitHub occurs. We can use GitHub Actions to automate building and publishing updates when you or members of your team merge to a branch, like "production". This makes the process of deploying consistent and fast, leaving you more time to develop your app. 9 10## Publish updates on push 11 12We can configure GitHub Actions to run on any GitHub event. One of the most common use cases is to publish an update when code is pushed. Below are the steps to publish an update every time an update is pushed: 13 14<Step label="1"> 15 16Create a file path named **.github/workflows/update.yml** at the root of your project. 17 18</Step> 19 20<Step label="2"> 21 22Inside **update.yml**, copy and paste the following snippet: 23 24```yaml update.yml 25name: update 26on: push 27 28jobs: 29 update: 30 name: EAS Update 31 runs-on: ubuntu-latest 32 steps: 33 - name: Check for EXPO_TOKEN 34 run: | 35 if [ -z "${{ secrets.EXPO_TOKEN }}" ]; then 36 echo "You must provide an EXPO_TOKEN secret linked to this project's Expo account in this repo's secrets. Learn more: https://docs.expo.dev/eas-update/github-actions" 37 exit 1 38 fi 39 40 - name: Checkout repository 41 uses: actions/checkout@v3 42 43 - name: Setup Node 44 uses: actions/setup-node@v3 45 with: 46 node-version: 18.x 47 cache: yarn 48 49 - name: Setup EAS 50 uses: expo/expo-github-action@v8 51 with: 52 eas-version: latest 53 token: ${{ secrets.EXPO_TOKEN }} 54 55 - name: Install dependencies 56 run: yarn install 57 58 - name: Publish update 59 run: eas update --auto 60``` 61 62In the code above, we set the action to run every time code is pushed to any branch. In the `update` job, we set up Node, in addition to Expo's GitHub Action: `expo-github-action`. We then add a couple of steps to cache any dependencies installed from the last run to speed this script up on subsequent runs. In the end, we install dependencies (`yarn install`), then publish the update with `eas update --auto`. 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. 63 64</Step> 65 66<Step label="3"> 67 68Finally, we need to give the script above permission to run by providing an `EXPO_TOKEN` environment variable. 69 701. Navigate to [https://expo.dev/settings/access-tokens](https://expo.dev/settings/access-tokens). 712. Click "Create" to create a new access token. 723. Copy the token generated. 734. Navigate to https://github.com/your-username/your-repo-name/settings/secrets/actions, replacing "your-username" and "your-repo-name" with your project's info. 745. Click "New repository secret" 756. Make the secret's name "EXPO_TOKEN", then paste the access token in as the value. 76 77Your GitHub Action should be set up now. Whenever a developer merges code into the repo, this action will build an update and publish it, making it available to all of our devices with builds that have access to the EAS branch. 78 79> Some repositories or organizations might need to explicitly enable GitHub Workflows and allow third-party Actions. 80 81</Step> 82 83## Publish previews on pull requests 84 85Another common use case it to create a new update for every pull request. This allows you to test the changes in the pull request on a device before merging the code, and without having to start the project locally. Below are the steps to publish an update every time a pull request is opened: 86 87<Step label="1"> 88 89Create a file path named **.github/workflows/preview.yml** at the root of your project. 90 91</Step> 92 93<Step label="2"> 94 95Inside **preview.yml**, copy and paste the following snippet: 96 97```yaml preview.yml 98name: preview 99on: pull_request 100 101jobs: 102 update: 103 name: EAS Update 104 runs-on: ubuntu-latest 105 permissions: 106 pull-requests: write 107 steps: 108 - name: Check for EXPO_TOKEN 109 run: | 110 if [ -z "${{ secrets.EXPO_TOKEN }}" ]; then 111 echo "You must provide an EXPO_TOKEN secret linked to this project's Expo account in this repo's secrets. Learn more: https://docs.expo.dev/eas-update/github-actions" 112 exit 1 113 fi 114 115 - name: Checkout repository 116 uses: actions/checkout@v3 117 118 - name: Setup Node 119 uses: actions/setup-node@v3 120 with: 121 node-version: 18.x 122 cache: yarn 123 124 - name: Setup EAS 125 uses: expo/expo-github-action@v8 126 with: 127 eas-version: latest 128 token: ${{ secrets.EXPO_TOKEN }} 129 130 - name: Install dependencies 131 run: yarn install 132 133 - name: Create preview 134 uses: expo/expo-github-action/preview@v8 135 with: 136 command: eas update --auto 137``` 138 139Although the code above is similar to the example in the previous section, there are a few differences. In this action, we changed the workflow event (`on`) to run every time a pull request is opened or updated. In the `update` job, we still set up Node, Expo's GitHub Action, and the dependencies using GitHub action's built-in cache. But, instead of running `eas update --auto` ourselves, we let the [preview subaction](https://github.com/expo/expo-github-action/tree/main/preview#readme) run it for us. This will add a comment to the pull request with basic information about the update and a QR code to scan the update. 140 141> Don't forget to add the `permissions` section to the job. This enables the job to add comments to the pull request. 142 143</Step> 144 145<Step label="3"> 146 147 148You can skip this step if you have already set up `EXPO_TOKEN` in the previous section. Only one valid `EXPO_TOKEN` is required to authenticate GitHub Actions with your Expo account. 149 150If you haven't, you must give the script above permission to run by providing an `EXPO_TOKEN` environment variable. 151 1521. Navigate to [https://expo.dev/settings/access-tokens](https://expo.dev/settings/access-tokens). 1532. Click "Create" to create a new access token. 1543. Copy the token generated. 1554. Navigate to https://github.com/your-username/your-repo-name/settings/secrets/actions, replacing "your-username" and "your-repo-name" with your project's info. 1565. Click "New repository secret" 1576. Make the secret's name "EXPO_TOKEN", then paste the access token in as the value. 158 159Your GitHub Action should be set up now. Whenever a developer creates a pull request, this action will build an update and publish it, making it available to all reviewers with builds that have access to the EAS branch. 160 161> Some repositories or organizations might need to explicitly enable GitHub Workflows and allow third-party Actions. 162 163</Step> 164