• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1name: CI
2
3on:
4  push:
5    branches:
6      - master
7  pull_request:
8    branches:
9      - master
10
11env:
12  USE_JAVA_DISTRIBUTION: 'zulu'
13  USE_JAVA_VERSION: '11'
14  # This is required by Gradle 8.0+.
15  USE_JAVA_VERSION_FOR_GRADLE_PLUGIN: '17'
16  # Required by JDK Toolchain Configuration
17  USE_JAVA_VERSION_FOR_GRADLE: '18'
18  # The default Maven 3.9.0 has a regression so we manually install 3.8.7.
19  # https://issues.apache.org/jira/browse/MNG-7679
20  USE_MAVEN_VERSION: '3.8.7'
21
22jobs:
23  validate-latest-dagger-version:
24    name: 'Validate Dagger version'
25    runs-on: ubuntu-latest
26    steps:
27      - uses: actions/checkout@v4
28      - uses: ./.github/actions/prechecks
29  bazel-build:
30    name: 'Bazel build'
31    needs: validate-latest-dagger-version
32    runs-on: ubuntu-latest
33    steps:
34      - uses: actions/checkout@v4
35      - uses: ./.github/actions/bazel-build
36  bazel-test:
37    name: 'Bazel tests'
38    needs: validate-latest-dagger-version
39    runs-on:
40      group: large-runner-group
41      labels: ubuntu-22.04-16core
42    steps:
43      - uses: actions/checkout@v4
44      - uses: ./.github/actions/bazel-test
45  gradle-build:
46    name: 'Gradle build'
47    runs-on:
48      group: large-runner-group
49      labels: ubuntu-22.04-16core
50    steps:
51    - uses: actions/checkout@v4
52    - uses: ./.github/actions/gradle-build
53  artifact-verification-tests:
54    name: 'Artifact verification tests'
55    needs: bazel-build
56    runs-on: ubuntu-latest
57    steps:
58      - uses: actions/checkout@v4
59      - uses: ./.github/actions/artifact-verification-tests
60  artifact-java-local-tests:
61    name: 'Artifact Java local tests'
62    needs: bazel-build
63    runs-on: ubuntu-latest
64    steps:
65      - uses: actions/checkout@v4
66      - uses: ./.github/actions/artifact-java-local-tests
67  test-gradle-plugin:
68    name: 'Test Hilt Gradle plugin'
69    needs: bazel-build
70    runs-on: ubuntu-latest
71    steps:
72      - uses: actions/checkout@v4
73      - uses: ./.github/actions/test-gradle-plugin
74  artifact-android-local-tests:
75    name: 'Artifact Android local tests (AGP ${{ matrix.agp }})'
76    needs: bazel-build
77    runs-on: ubuntu-latest
78    strategy:
79      matrix:
80        include:
81          - agp: '8.1.1'
82            jdk: '17'
83    steps:
84      - uses: actions/checkout@v4
85      - uses: ./.github/actions/artifact-android-local-tests
86        with:
87          agp: '${{ matrix.agp }}'
88          jdk: '${{ matrix.jdk }}'
89  artifact-android-emulator-legacy-api-tests:
90    name: 'Artifact Android emulator tests (API ${{ matrix.api-level }})'
91    # We only run this on master push (essentially a postsubmit) since these
92    # can take a while to run
93    if: github.event_name == 'push' && github.repository == 'google/dagger' && github.ref == 'refs/heads/master'
94    needs: bazel-build
95    # It's recommended to run emulator tests on macOS
96    # See https://github.com/marketplace/actions/android-emulator-runner
97    runs-on: macos-latest
98    strategy:
99      matrix: # Run on 16 (PreL), 21 (L), and 26 (O).
100        api-level: [16, 21, 26, 30]
101    steps:
102      - uses: actions/checkout@v4
103      - uses: ./.github/actions/artifact-android-emulator-tests
104        timeout-minutes: 35
105        with:
106          api-level: '${{ matrix.api-level }}'
107  publish-snapshot:
108    name: 'Publish snapshot'
109    # TODO(bcorso): Consider also waiting on artifact-android-emulator-tests
110    # and artifact-android-emulator-legacy-api-tests after checking flakiness.
111    needs: [
112      bazel-test,
113      artifact-verification-tests,
114      artifact-java-local-tests,
115      artifact-android-local-tests,
116      test-gradle-plugin
117    ]
118    if: github.event_name == 'push' && github.repository == 'google/dagger' && github.ref == 'refs/heads/master'
119    runs-on: ubuntu-latest
120    steps:
121      - name: 'Install Java ${{ env.USE_JAVA_VERSION }}'
122        uses: actions/setup-java@v4
123        with:
124          distribution: '${{ env.USE_JAVA_DISTRIBUTION }}'
125          java-version: '${{ env.USE_JAVA_VERSION }}'
126          server-id: sonatype-nexus-snapshots
127          server-username: CI_DEPLOY_USERNAME
128          server-password: CI_DEPLOY_PASSWORD
129      - name: 'Check out repository'
130        uses: actions/checkout@v4
131      - name: 'Cache local Maven repository'
132        uses: actions/cache@v4
133        with:
134          path: |
135            ~/.m2/repository
136            !~/.m2/repository/com/google/dagger
137          key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
138          restore-keys: |
139            ${{ runner.os }}-maven-
140      - name: 'Cache Bazel files'
141        uses: actions/cache@v4
142        with:
143          path: ~/.cache/bazel
144          key: ${{ runner.os }}-bazel-build-${{ github.sha }}
145          restore-keys: |
146            ${{ runner.os }}-bazel-build-
147      - name: 'Cache Gradle files'
148        uses: actions/cache@v4
149        with:
150          path: |
151            ~/.gradle/caches
152            ~/.gradle/wrapper
153          key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
154          restore-keys: |
155            ${{ runner.os }}-gradle-
156      - name: 'Publish latest docs'
157        run: ./util/generate-latest-docs.sh
158        shell: bash
159        env:
160          GH_TOKEN: ${{ github.token }}
161      - name: 'Publish latest snapshot'
162        run: |
163          util/deploy-all.sh \
164            "deploy:deploy-file" \
165            "HEAD-SNAPSHOT" \
166            "-DrepositoryId=sonatype-nexus-snapshots" \
167            "-Durl=https://oss.sonatype.org/content/repositories/snapshots"
168        shell: bash
169        env:
170          CI_DEPLOY_USERNAME: ${{ secrets.CI_DEPLOY_USERNAME }}
171          CI_DEPLOY_PASSWORD: ${{ secrets.CI_DEPLOY_PASSWORD }}
172      - name: 'Clean bazel cache'
173        # According to the documentation, we should be able to exclude these via
174        # the actions/cache path, e.g. "!~/.cache/bazel/*/*/external/" but that
175        # doesn't seem to work.
176        run: |
177          rm -rf $(bazel info repository_cache)
178          rm -rf ~/.cache/bazel/*/*/external/
179        shell: bash
180  build-gradle-plugin-latest-agp:
181    name: 'Build Hilt Gradle plugin against latest AGP version'
182    # We only run this on master push (essentially a postsubmit) since we
183    # don't want this job to prevent merges
184    if: github.event_name == 'push' && github.repository == 'google/dagger' && github.ref == 'refs/heads/master'
185    needs: bazel-build
186    runs-on: ubuntu-latest
187    steps:
188      - uses: actions/checkout@v4
189      - uses: ./.github/actions/build-gradle-plugin
190        with:
191          agp: '+'
192  cleanup-caches:
193    name: 'Clean up GitHub Action caches'
194    # TODO(bcorso): Consider also waiting on artifact-android-emulator-tests
195    # and artifact-android-emulator-legacy-api-tests after checking flakiness.
196    needs: [
197      bazel-test,
198      artifact-verification-tests,
199      artifact-java-local-tests,
200      artifact-android-local-tests,
201      test-gradle-plugin
202    ]
203    runs-on: ubuntu-latest
204    steps:
205      - uses: actions/checkout@v4
206      - uses: ./.github/actions/cleanup-caches
207