From c83076b396875b804251a26ac5a51385e6eaa0fd Mon Sep 17 00:00:00 2001 From: Edgar Khanzadian Date: Sun, 22 Sep 2024 21:06:25 +0300 Subject: [PATCH] ci: create simulator build when label is added to PR --- .github/actions/eas-deploy/action.yml | 105 ++++++++++++++++++++++++++ .github/workflows/eas-deploy.yml | 25 ++++++ .github/workflows/release-please.yml | 29 +------ 3 files changed, 134 insertions(+), 25 deletions(-) create mode 100644 .github/actions/eas-deploy/action.yml create mode 100644 .github/workflows/eas-deploy.yml diff --git a/.github/actions/eas-deploy/action.yml b/.github/actions/eas-deploy/action.yml new file mode 100644 index 00000000..e626318c --- /dev/null +++ b/.github/actions/eas-deploy/action.yml @@ -0,0 +1,105 @@ +name: EAS deploy +description: Run EAS deploy +inputs: + EXPO_TOKEN: # id of input + description: 'Expo token' + required: true + APPLE_ID: + description: 'Apple ID' + required: true + ASC_APP_ID: + description: 'ASC App ID' + required: true + EXPO_APPLE_APP_SPECIFIC_PASSWORD: + description: 'Expo Apple app specific password' + required: true + LEATHER_BOT: + description: 'GH bot token' + required: true +runs: + using: 'composite' + steps: + - name: Prepare the app + uses: ./.github/actions/provision + - name: Extract branch name + shell: bash + run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT + id: extract_branch + - name: Setup Expo and EAS + uses: expo/expo-github-action@v8 + with: + eas-version: latest + token: ${{ inputs.EXPO_TOKEN }} + - name: Install jq tool + run: | + sudo apt-get update + sudo apt-get install jq + shell: bash + - name: Setup eas credentials + run: | + echo $(jq --arg APPLE_ID "$APPLE_ID" '.submit.production.ios.appleId = $APPLE_ID' ./apps/mobile/eas.json) > ./apps/mobile/eas.json + echo $(jq --arg ASC_APP_ID "$ASC_APP_ID" '.submit.production.ios.ascAppId = $ASC_APP_ID' ./apps/mobile/eas.json) > ./apps/mobile/eas.json + shell: bash + env: + APPLE_ID: ${{ inputs.APPLE_ID }} + ASC_APP_ID: ${{ inputs.ASC_APP_ID }} + # Wait for build to either succeed or fail + - name: 🛫 Build for simulator 🛫 + id: simulator_build + run: | + cd apps/mobile + if [[ "$BRANCH_NAME" == "dev" ]] + then + # No wait on simulator version build of the app if we are on a dev branch + eas build --platform ios --profile=simulator --non-interactive --no-wait + else + # set temporary command output + setTmpOutput () { tee /tmp/capture.out; } + + # get temporary command output + getTmpOutput () { cat /tmp/capture.out; } + + eas build --platform ios --profile=simulator --non-interactive | setTmpOutput + + # Last line of the build output is the link to the expo build + UNSAFE_BUILD_LINK=$(getTmpOutput | tail -n 1) + + if [[ $UNSAFE_BUILD_LINK == *"https://expo.dev/accounts/leather-wallet/projects/leather-wallet-mobile/builds/"* ]]; then + echo "Found build link!" + echo "BUILD_LINK=$UNSAFE_BUILD_LINK" >> $GITHUB_OUTPUT + else + echo "No build link!" + fi + + fi + shell: bash + env: + EXPO_APPLE_APP_SPECIFIC_PASSWORD: ${{ inputs.EXPO_APPLE_APP_SPECIFIC_PASSWORD }} + BRANCH_NAME: ${{ steps.extract_branch.outputs.branch }} + - name: Publish simulator expo link in PR + if: ${{ steps.extract_branch.outputs.branch != 'dev' }} + uses: actions/github-script@v7 + env: + BUILD_LINK: ${{ steps.simulator_build.outputs.BUILD_LINK }} + with: + github-token: ${{ inputs.LEATHER_BOT }} + script: | + const { BUILD_LINK } = process.env + if(BUILD_LINK) { + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: "Expo simulator build link: " + BUILD_LINK + }) + } + + - name: 🛫 Build for production 🛫 + if: ${{ steps.extract_branch.outputs.branch == 'dev' }} + run: | + cd apps/mobile + # Release version of the app, we should wait for it to see the result + eas build --platform ios --profile=production --non-interactive --auto-submit + shell: bash + env: + EXPO_APPLE_APP_SPECIFIC_PASSWORD: ${{ inputs.EXPO_APPLE_APP_SPECIFIC_PASSWORD }} diff --git a/.github/workflows/eas-deploy.yml b/.github/workflows/eas-deploy.yml new file mode 100644 index 00000000..943d7f29 --- /dev/null +++ b/.github/workflows/eas-deploy.yml @@ -0,0 +1,25 @@ +on: + pull_request: + types: + - synchronize + - labeled + +permissions: + contents: write + pull-requests: write + +name: trigger EAS deploy + +jobs: + deploy-eas: + if: contains(github.event.pull_request.labels.*.name, 'needs:demo-build') + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/eas-deploy + with: + EXPO_APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.EXPO_APPLE_APP_SPECIFIC_PASSWORD }} + APPLE_ID: ${{ secrets.APPLE_ID }} + ASC_APP_ID: ${{ secrets.ASC_APP_ID }} + EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }} + LEATHER_BOT: ${{ secrets.LEATHER_BOT }} diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 96a52613..6df51a38 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -77,31 +77,10 @@ jobs: if: needs.release-please.outputs.releases_created steps: - uses: actions/checkout@v4 - - name: Prepare the app - uses: ./.github/actions/provision - - name: Setup Expo and EAS - uses: expo/expo-github-action@v8 + - uses: ./.github/actions/eas-deploy with: - eas-version: latest - token: ${{ secrets.EXPO_TOKEN }} - - name: Install jq tool - run: | - sudo apt-get update - sudo apt-get install jq - - name: Setup eas credentials - run: | - echo $(jq --arg APPLE_ID "$APPLE_ID" '.submit.production.ios.appleId = $APPLE_ID' ./apps/mobile/eas.json) > ./apps/mobile/eas.json - echo $(jq --arg ASC_APP_ID "$ASC_APP_ID" '.submit.production.ios.ascAppId = $ASC_APP_ID' ./apps/mobile/eas.json) > ./apps/mobile/eas.json - env: + EXPO_APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.EXPO_APPLE_APP_SPECIFIC_PASSWORD }} APPLE_ID: ${{ secrets.APPLE_ID }} ASC_APP_ID: ${{ secrets.ASC_APP_ID }} - # Wait for build to either succeed or fail - - name: 🛫 Prepare for takeoff! 🛫 - run: | - cd apps/mobile - # No wait on simulator version build of the app - eas build --platform ios --profile=simulator --non-interactive --no-wait - # Release version of the app, we should wait for it to see the result - eas build --platform ios --profile=production --non-interactive --auto-submit - env: - EXPO_APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.EXPO_APPLE_APP_SPECIFIC_PASSWORD }} + EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }} + LEATHER_BOT: ${{ secrets.LEATHER_BOT }}