-
Notifications
You must be signed in to change notification settings - Fork 203
113 lines (97 loc) · 3.53 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
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@v4
- name: Install JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '22'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Prepare Gradle Home
run: |
mkdir -p ~/.gradle
touch ~/.gradle/gradle.properties
- name: Bootstrap
run: ./gradlew bootstrap
- 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
run: ./gradlew computeAffectedProjects --changed-files tmp/changed_files.txt -Pslack.debug=true
- name: Check affected projects
run: |
path="build/skippy/merged/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/merged/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@v4
with:
name: reports
path: build/skippy/**
- name: Build and run tests
run: ./gradlew check ${{ env.APP_TARGET }} globalCiLint globalCiUnitTest --continue --quiet -Pslack.avoidance.affectedProjectsFile=build/skippy/merged/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@v3
with:
sarif_file: tmp/modified_sarif.sarif
- name: (Fail-only) Upload build reports
if: failure()
uses: actions/upload-artifact@v4
with:
name: reports
path: |
**/build/reports/*