Commit message after eas build

I have a bare workflow project. EAS build works perfectly fine. I am using github actions for CI flow.

I am having issues getting a working QR code to display in my pull request as a commit after “eas build” has finished. All the examples show “expo publish” before the comment (either using “expo/expo-github-action/preview-comment@v7” or “unsplash”) using release channels. I do get a QR code generated in the comments but it doesn’t seem to work either in the camera app or in expo go. The QR code generated in the build in the expo dashboard lets me download the correct .apk file (trying only for android atm) but it doesn’t translate properly to the github comments.

Any help would be much appreciated on this or an example to show how to use comments after “eas build”. I guess it’s something to do around the release channels as it’s a major player in creating those links/QR for the commit messages but not entirely sure

I’ve found that you need to do the “expo publish” step otherwise the QR code doesn’t seem to work.

      - name: 🚀 Publish preview
        run: expo publish --release-channel=pr-${{ github.event.number }} --non-interactive

But I’m not seeing how to set the release channel dynamically with eas build. The releaseChannel is hardcoded in my eas.json file, so I’m not sure what to do about that.

Well, the preview-comment library works with expo publish as it relies on a release channel and that is what it uses to create the minified links which it posts on the PR as a message.

But since eas build does not have a related release channel pipeline to it, I am assuming the “preview-comment” action fails there. So was hoping to come across a solution which works for eas build cause I would like not to not setup my config in eas.json file as eas would be useless then.

Yeah. I gave up on preview-comment and expo publish. Something like this works for a single build. It generates the URL that links to the EAS QR code. Then messages to a slack workflow. But I’m not sure this scales if you have multiple simultaneous builds.

      - name: Build on EAS
        id: build
        run: |
          eas build --platform ios --non-interactive --profile yourprofilename
          eas build:view --json > build.json

      - name: Output the EAS build id
        uses: sergeysova/jq-action@v2
        id: buildId
          cmd: "jq .id build.json -r"

      - name: Comment in Slack
        id: slack
        uses: slackapi/slack-github-action@v1.18.0
          payload: |
              "projectLink": "${{ steps.buildId.outputs.value }}"
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

That looks interesting. I wasn’t across the eas build:view bit. I tried pushing the entire thing in a comment as well, but that didn’t work exactly. I think playing around with that json file along with a comment action on github should do the trick (atleast for the links). The QR codes are something that will need a bit of thought. But this seems promising. Thank you very much :slight_smile:

Well that works. Following is a github action that you can use to get your build urls into a comment into your preview PR’s.

    name: Create preview
    runs-on: ubuntu-latest
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Set up repository
        uses: actions/checkout@v2

      - name: Set up Node
        uses: actions/setup-node@v2
          node-version: 16.x
          cache: yarn

      - name: Set up Expo and EAS
        uses: expo/expo-github-action@v7
          expo-version: 5.x
          eas-version: latest
          token: ${{ secrets.EXPO_TOKEN }}

      - name: Install dependencies
        run: yarn install

      - name: Publish preview to Expo
        run: eas build --profile yourprofilename --platform all --non-interactive --json > build.json

      - name: Fetch data from json file
        id: buildUrls
        run: |
          echo "::set-output name=ANDROID_URL::$(jq '.[0].artifacts.buildUrl' build.json -r)"
          echo "::set-output name=IOS_URL::$(jq '.[1].artifacts.buildUrl' build.json -r)"

      - name: Add preview comment
        uses: unsplash/comment-on-pr@v1.3.0
          msg: "Build successfully created. Here are the URLs -\n\nAndroid Build URL - ${{ steps.buildUrls.outputs.ANDROID_URL }}\niOS Build URL - ${{ steps.buildUrls.outputs.IOS_URL }}"
          check_for_duplicate_msg: false
          delete_prev_regex_msg: 'Build successfully created. Here are the URLs'

This will

  • Add script output to a json file using --json > build.json function of the eas build command
  • Uses jq to parse the json file and fetch the buildUrls for the apps
  • Uses unsplash to comment on PR using the buildUrls

Awesome! :trophy:

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.