-
Notifications
You must be signed in to change notification settings - Fork 39
131 lines (114 loc) · 4.5 KB
/
android-preview-build-local.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: android-preview-build-local
on:
push:
branches: ['**']
pull_request:
branches: ['**']
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: Setup environment variables
run: |
echo "MAPBOX_DOWNLOADS_TOKEN=$MAPBOX_DOWNLOADS_TOKEN" >> $GITHUB_ENV
- 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
});