Repository navigation
143 lines (139 loc) · 6.08 KB
/
Copy pathe2e-build.yml
File metadata and controls
143 lines (139 loc) · 6.08 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
name: E2E Build
on:
workflow_call:
inputs:
app:
required: true
type: string
coverage:
description: 'Instrument the app and upload its classes, to build the coverage map that selects e2e tests on pull requests'
required: false
type: boolean
default: false
cache_only:
description: 'Only build the apks to save the Gradle cache, without selecting tests or uploading artifacts'
required: false
type: boolean
default: false
e2e_required:
description: "The e2e-scope job's decision, 'true' or 'false'. Empty makes the lanes ask the GitHub API, which only works on a run without a pull request"
required: false
type: string
default: ''
coverage_map:
description: 'Whether the e2e-scope job uploaded the coverage map that selects the tests'
required: false
type: boolean
default: false
outputs:
e2e_batches:
description: 'JSON array of the batch indices the selected e2e tests need, empty when none'
value: ${{ jobs.build.outputs.e2e_batches }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_PR_NUM: ${{ github.event.pull_request.number }}
E2E_REQUIRED: ${{ inputs.e2e_required }}
jobs:
build:
permissions:
actions: write
contents: read
pull-requests: read
name: ${{ inputs.app }} apks${{ inputs.coverage && ' (coverage)' || '' }}
# No GitHub API calls here: e2e-scope decides E2E_REQUIRED on the static-IP runner, so a
# standard GitHub-hosted runner works. Without E2E_REQUIRED, fastlane would ask the API itself.
runs-on: ubuntu-24.04
outputs:
e2e_batches: ${{ steps.select_e2e_tests.outputs.e2e_batches }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
# A PR merge commit and its base, to diff them. A merge queue entry can stack several pull requests on its base.
fetch-depth: ${{ github.event_name == 'merge_group' && 50 || 2 }}
- uses: GetStream/android-ci-actions/actions/setup-java@cb46e4f44d105a68738bfd2a1cfd156bb768665b
- uses: GetStream/android-ci-actions/actions/enable-kvm@main
- uses: GetStream/android-ci-actions/actions/setup-ruby@main
# Only pushes to develop save a new cache; every other run restores the latest one.
- name: Restore Gradle cache
id: gradle_cache
uses: actions/cache/restore@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-e2e-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-gradle-e2e-
- name: Build apks
run: bundle exec fastlane build_e2e_test coverage:${{ inputs.coverage }}
timeout-minutes: 30
- name: Save Gradle cache
if: ${{ !inputs.coverage && github.event_name == 'push' && github.ref == 'refs/heads/develop' }}
uses: actions/cache/save@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ steps.gradle_cache.outputs.cache-primary-key }}
- name: Download the coverage map
if: ${{ inputs.coverage_map && !inputs.coverage && !inputs.cache_only }}
uses: actions/download-artifact@v8.0.2
with:
name: e2e-coverage-map-input
path: fastlane/test_output
- name: Select E2E Tests
id: select_e2e_tests
if: ${{ !inputs.coverage && !inputs.cache_only }}
run: bundle exec fastlane select_e2e_tests
- name: Upload apks
if: ${{ !inputs.cache_only }}
uses: actions/upload-artifact@v7.0.2
with:
name: apks${{ inputs.coverage && '-coverage' || '' }}
path: |
stream-chat-android-${{ inputs.app }}-sample/build/outputs/apk/e2e/debug/*.apk
stream-chat-android-${{ inputs.app }}-sample/build/outputs/apk/androidTest/e2e/debug/*.apk
- name: Upload e2e selection
if: ${{ !inputs.coverage && !inputs.cache_only }}
uses: actions/upload-artifact@v7.0.2
with:
name: e2e-selection
path: fastlane/test_output/e2e_selection.json
# The coverage map links the classes the tests ran to their source files.
- name: Upload classes
if: ${{ inputs.coverage }}
uses: actions/upload-artifact@v7.0.2
with:
name: e2e-classes
path: |
stream-chat-android-*/build/tmp/kotlin-classes/debug
stream-chat-android-*/build/tmp/kotlin-classes/e2eDebug
stream-chat-android-*/build/intermediates/javac/debug/*/classes
stream-chat-android-*/build/intermediates/javac/e2eDebug/*/classes
stream-chat-android-*/build/classes/java/main
stream-chat-android-*/build/classes/kotlin/main
# Keeps one snapshot, so the saves don't pile up in the repo's Actions cache.
# Calls the GitHub API, and the org IP allow list only admits static-IP runners.
remove-older-gradle-caches:
needs: build
if: ${{ !inputs.coverage && github.event_name == 'push' && github.ref == 'refs/heads/develop' }}
permissions:
actions: write
name: Remove older Gradle caches
runs-on:
group: github-public-amd64
steps:
# A failed save only warns, so the older snapshots stay unless the new one is listed.
# Deletes only snapshots from earlier runs (the key ends in the run id), so a run that finishes
# late never removes a newer snapshot saved by a concurrent run.
- name: Remove older Gradle caches
env:
GH_TOKEN: ${{ github.token }}
PREFIX: ${{ runner.os }}-gradle-e2e-
NEW_KEY: ${{ runner.os }}-gradle-e2e-${{ github.run_id }}
run: |
gh cache list -R "$GITHUB_REPOSITORY" --ref "$GITHUB_REF" --key "$PREFIX" --limit 100 --json id,key \
--jq 'if any(.[]; .key == env.NEW_KEY)
then .[] | select((.key | ltrimstr(env.PREFIX) | tonumber) < (env.NEW_KEY | ltrimstr(env.PREFIX) | tonumber)) | .id
else empty end' \
| xargs -r -n1 gh cache delete -R "$GITHUB_REPOSITORY"