-
Notifications
You must be signed in to change notification settings - Fork 201
123 lines (105 loc) · 3.95 KB
/
ci.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
name: CI
on:
# Only run push on main
push:
branches:
- main
paths-ignore:
- '*.md'
# Always run on PRs
pull_request:
branches:
- main
concurrency:
group: ci-${{ github.ref }}-${{ github.head_ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Gradle Wrapper Validation
uses: gradle/wrapper-validation-action@v1
- name: Install JDK
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '20'
- uses: gradle/gradle-build-action@v2
with:
gradle-home-cache-cleanup: true
cache-read-only: false
- name: Prepare Gradle Home
run: |
mkdir -p ~/.gradle
touch ~/.gradle/gradle.properties
- name: Bootstrap
run: ./gradlew bootstrap --stacktrace
# Due to https://github.com/actions/runner-images/issues/7506#issuecomment-1533097084
- run: echo "y" | /usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager "build-tools;34.0.0-rc3"
- name: Get changed files
if: always() && github.event_name == 'pull_request'
env:
GH_TOKEN: ${{ github.token }}
run: |
mkdir tmp
gh pr view ${{ github.event.number }} --json files -q '.files[].path' > tmp/changed_files.txt
- name: Compute affected projects
if: always() && github.event_name == 'pull_request'
id: gradle-affected-projects
uses: gradle/gradle-build-action@v2
with:
arguments: computeAffectedProjects --changed-files tmp/changed_files.txt -Pslack.debug=true --stacktrace
- name: Check affected projects
run: |
path="build/skippy/affected_projects.txt"
if [[ -e "$path" ]]; then
cat "$path"
# Copy focus file to root of project
# Necessary to omit the newline because the focus plugin reads the whole file text!
# TODO changing settings breaks caching https://issuetracker.google.com/issues/279997228
# echo -n "build/skippy/focus.settings.gradle" > .focus
# Check if app is affected
if grep -q ":app" "$path"; then
echo "App is affected"
echo 'APP_TARGET=:app:assembleRelease' >> $GITHUB_ENV
else
echo "App is not affected"
echo 'APP_TARGET=' >> $GITHUB_ENV
fi
else
echo "No file found, all projects are affected"
echo 'APP_TARGET=:app:assembleRelease' >> $GITHUB_ENV
fi
- name: Upload skippy diagnostics
uses: actions/upload-artifact@v3
with:
name: reports
path: build/skippy/**
- name: Build and run tests
run: ./gradlew check ${{ env.APP_TARGET }} globalCiLint globalCiUnitTest --continue --quiet --stacktrace -Pslack.avoidance.affectedProjectsFile=build/skippy/affected_projects.txt
- name: Filter sarif
if: always() && github.event_name == 'pull_request'
run: |
./.github/workflows/sarif-filter.main.kts --sarif-file app/build/reports/lint-results-release.sarif --modified-files tmp/changed_files.txt --output-file tmp/modified_sarif.sarif
- name: Check if output sarif exists
id: check_file
run: |
if [[ -f tmp/modified_sarif.sarif ]]; then
echo "modified_sarif_exists=true" >> $GITHUB_OUTPUT
else
echo "modified_sarif_exists=false" >> $GITHUB_OUTPUT
fi
- name: Upload lint sarif
if: steps.check_file.outputs.modified_sarif_exists == 'true'
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: tmp/modified_sarif.sarif
- name: (Fail-only) Upload build reports
if: failure()
uses: actions/upload-artifact@v3
with:
name: reports
path: |
**/build/reports/*