Merge pull request #1004 from andrew-bierman/enhance-ui-logic #1085
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: android-preview-build-local | |
on: | |
push: | |
branches: ['**'] | |
pull_request: | |
branches: ['**'] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
update: | |
name: EAS Android Build Local | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
pull-requests: write | |
steps: | |
- name: Check for EXPO_TOKEN | |
run: | | |
if [ -z "${{ secrets.EXPO_TOKEN }}" ]; then | |
echo "You must provide an EXPO_TOKEN secret linked to this project's Expo account in this repo's secrets." | |
exit 1 | |
fi | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Setup Node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 20.x | |
cache: yarn | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Setup EAS | |
uses: expo/expo-github-action@v8 | |
with: | |
eas-version: latest | |
token: ${{ secrets.EXPO_TOKEN }} | |
- name: Export secrets as environment variables | |
env: | |
JSON_SECRETS: '${{ toJSON(secrets) }}' | |
run: | | |
eval "$(jq -r 'to_entries | map("export \(.key)=\(.value|tostring)") | .[]' <<< "$JSON_SECRETS")" | |
- name: Install dependencies | |
uses: ./.github/actions/install-deps | |
- name: Prebuild | |
run: | | |
echo "Using Mapbox Token: $MAPBOX_DOWNLOADS_TOKEN" | |
export MAPBOX_DOWNLOADS_TOKEN=${{ secrets.MAPBOX_DOWNLOADS_TOKEN }} | |
yarn run prebuild:expo | |
- name: Create preview | |
id: build | |
run: | | |
echo "Using Mapbox Token: $MAPBOX_DOWNLOADS_TOKEN" | |
export MAPBOX_DOWNLOADS_TOKEN=${{ secrets.MAPBOX_DOWNLOADS_TOKEN }} | |
eas build --platform android --profile preview --local | |
apk_path=$(find . -name '*.apk') | |
echo "APK Path: ${apk_path}" | |
echo "apk_path=${apk_path}" >> $GITHUB_ENV | |
working-directory: apps/expo | |
env: | |
DEBUG: 'true' | |
continue-on-error: true | |
- name: Upload APK | |
uses: actions/upload-artifact@v3 | |
with: | |
name: android-apk | |
path: /home/runner/work/PackRat/PackRat/apps/expo/build-*.apk | |
- name: Find or create comment | |
if: github.event_name == 'pull_request' | |
uses: actions/github-script@v6 | |
id: find_or_create_comment | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const commentIdentifier = '<!-- build_results -->'; | |
const comments = await github.rest.issues.listComments({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}); | |
const existingComment = comments.data.find(comment => comment.body.startsWith(commentIdentifier)); | |
if (existingComment) { | |
core.setOutput('comment_id', existingComment.id); | |
} else { | |
const commentBody = `${commentIdentifier}\n🚀 Android APK build started... Please wait for the results! 🕐`; | |
const { data: { id: commentId } } = await github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: commentBody | |
}); | |
core.setOutput('comment_id', commentId); | |
} | |
- name: Update PR comment | |
if: always() && github.event_name == 'pull_request' | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const commentIdentifier = '<!-- build_results -->'; | |
const commentId = '${{ steps.find_or_create_comment.outputs.comment_id }}'; | |
const buildOutcome = '${{ steps.build.outcome }}'; | |
const buildStatus = buildOutcome == 'success' ? 'completed' : 'failed'; | |
const workflowUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; | |
let commentBody = `${commentIdentifier}\nAndroid APK build ${buildStatus}!`; | |
if (buildOutcome == 'success') { | |
commentBody += `\nYou can download the APK file from the following link:\n${workflowUrl}#artifacts`; | |
} else { | |
commentBody += '\nPlease check the workflow logs for more details on the build failure.'; | |
} | |
await github.rest.issues.updateComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: commentId, | |
body: commentBody | |
}); |