Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#2898] Build CI on more realistic combinations (and faster) #3028

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
115 changes: 115 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: Build and Test Project

on:
workflow_call:

jobs:
build-1:
uses: ./.github/workflows/build.yml
with:
mock-maker: 'mock-maker-default'
member-accessor: 'member-accessor-default'

build-2:
uses: ./.github/workflows/build.yml
with:
mock-maker: 'mock-maker-inline'
member-accessor: 'member-accessor-module'

build-3:
uses: ./.github/workflows/build.yml
with:
mock-maker: 'mock-maker-subclass'
member-accessor: 'member-accessor-module'

build-4:
uses: ./.github/workflows/build.yml
with:
mock-maker: 'mock-maker-subclass'
member-accessor: 'member-accessor-reflection'

build-5:
uses: ./.github/workflows/build.yml
with:
mock-maker: 'mock-maker-inline'
member-accessor: 'member-accessor-reflection'

test-1a:
needs: build-1
uses: ./.github/workflows/test.yml
with:
mock-maker: 'mock-maker-default'
member-accessor: 'member-accessor-default'
java: 11

test-1b:
needs: build-1
uses: ./.github/workflows/test.yml
with:
mock-maker: 'mock-maker-default'
member-accessor: 'member-accessor-default'
java: 17

test-2a:
needs: build-2
uses: ./.github/workflows/test.yml
with:
mock-maker: 'mock-maker-inline'
member-accessor: 'member-accessor-module'
java: 11

test-2b:
needs: build-2
uses: ./.github/workflows/test.yml
with:
mock-maker: 'mock-maker-inline'
member-accessor: 'member-accessor-module'
java: 17

test-3a:
needs: build-3
uses: ./.github/workflows/test.yml
with:
mock-maker: 'mock-maker-subclass'
member-accessor: 'member-accessor-module'
java: 11

test-3b:
needs: build-3
uses: ./.github/workflows/test.yml
with:
mock-maker: 'mock-maker-subclass'
member-accessor: 'member-accessor-module'
java: 17

test-4a:
needs: build-4
uses: ./.github/workflows/test.yml
with:
mock-maker: 'mock-maker-subclass'
member-accessor: 'member-accessor-reflection'
java: 11

test-4b:
needs: build-4
uses: ./.github/workflows/test.yml
with:
mock-maker: 'mock-maker-subclass'
member-accessor: 'member-accessor-reflection'
java: 17

test-5a:
needs: build-5
uses: ./.github/workflows/test.yml
with:
mock-maker: 'mock-maker-inline'
member-accessor: 'member-accessor-reflection'
java: 11

test-5b:
needs: build-5
uses: ./.github/workflows/test.yml
with:
mock-maker: 'mock-maker-inline'
member-accessor: 'member-accessor-reflection'
java: 17
66 changes: 66 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Main Build Job

on:
workflow_call:
inputs:
mock-maker:
required: true
type: string
member-accessor:
required: true
type: string

jobs:
#
# Main build job
#
build:
runs-on: ubuntu-latest
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"

# All build steps
# SINGLE-JOB means that the step is only performed when default mock maker environment is used
steps:
- name: 1. Check out code
uses: actions/checkout@v3 # https://github.com/actions/checkout
with:
fetch-depth: '0' # https://github.com/shipkit/shipkit-changelog#fetch-depth-on-ci

- name: 2. Set up Java 11
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 11

- name: 3. Validate Gradle wrapper (single job only)
if: inputs.mock-maker == 'mock-maker-default' # SINGLE-JOB
uses: gradle/wrapper-validation-action@v1.0.6 # https://github.com/gradle/wrapper-validation-action

- name: 4. Build and check reproducibility of artifacts (single job only)
if: inputs.mock-maker == 'mock-maker-default' # SINGLE-JOB
run: ./check_reproducibility.sh

- name: 5. Spotless check (single job only). Run './gradlew spotlessApply' locally if this job fails.
if: inputs.mock-maker == 'mock-maker-default' # SINGLE-JOB
run: ./gradlew spotlessCheck

- name: 6. Build on Java 11 with ${{ inputs.mock-maker }} and ${{ inputs.member-accessor }}
run: |
./gradlew build idea --scan \
-x test \
-x sourcesJar -x javadocJar \
-x publishJavaLibraryPublicationToMavenLocal
./gradlew :android:build
env:
MOCK_MAKER: ${{ inputs.mock-maker }}
MEMBER_ACCESSOR: ${{ inputs.member-accessor }}

- name: 7. Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.mock-maker }}-${{ inputs.member-accessor }}-build-artifacts
path: |
build
subprojects/*/build


125 changes: 84 additions & 41 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,60 @@ permissions:
contents: read

jobs:

#
# Main build job
#
build:
runs-on: ubuntu-latest
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"

# All build steps
steps:

- name: 1. Check out code
uses: actions/checkout@v3 # https://github.com/actions/checkout
with:
fetch-depth: '0' # https://github.com/shipkit/shipkit-changelog#fetch-depth-on-ci

- name: 2. Set up Java 11
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 11

- name: 3. Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1.0.6 # https://github.com/gradle/wrapper-validation-action

- name: 4. Build and check reproducibility of artifacts (single job only)
run: ./check_reproducibility.sh

- name: 5. Spotless check (single job only). Run './gradlew spotlessApply' locally if this job fails.
run: ./gradlew spotlessCheck

- name: 6. Build on Java 11
run: |
./gradlew build idea --scan \
-x test \
-x sourcesJar -x javadocJar \
-x publishJavaLibraryPublicationToMavenLocal
./gradlew :android:build

- name: 7. Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: java-11-build-artifacts
path: |
build
subprojects/*/build

#
# Main test job
#
test:
needs: build
runs-on: ubuntu-latest
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"

# Definition of the build matrix
strategy:
matrix:
Expand All @@ -37,53 +83,50 @@ jobs:
- { mock-maker: 'mock-maker-subclass', member-accessor: 'member-accessor-reflection' }
- { mock-maker: 'mock-maker-inline', member-accessor: 'member-accessor-reflection' }

# All build steps
# SINGLE-MATRIX-JOB means that the step does not need to be executed on every job in the matrix
# All test steps
steps:
- name: 1. Checkout out test code
uses: actions/checkout@v3
with:
fetch-depth: '0'

- name: 1. Check out code
uses: actions/checkout@v3 # https://github.com/actions/checkout
with:
fetch-depth: '0' # https://github.com/shipkit/shipkit-changelog#fetch-depth-on-ci

- name: 2. Set up Java ${{ matrix.java }}
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: ${{ matrix.java }}

- name: 3. Validate Gradle wrapper
if: matrix.java == 11 && matrix.entry.mock-maker == 'mock-maker-default' # SINGLE-MATRIX-JOB
uses: gradle/wrapper-validation-action@v1.0.6 # https://github.com/gradle/wrapper-validation-action

- name: 4. Build and check reproducibility of artifacts (single job only)
if: matrix.java == 11 && matrix.entry.mock-maker == 'mock-maker-default' # SINGLE-MATRIX-JOB
run: ./check_reproducibility.sh

- name: 5. Spotless check (single job only). Run './gradlew spotlessApply' locally if this job fails.
if: matrix.java == 11 && matrix.entry.mock-maker == 'mock-maker-default' # SINGLE-MATRIX-JOB
run: ./gradlew spotlessCheck
- name: 2. Download java 11 build artifacts
uses: actions/download-artifact@v3
with:
name: java-11-build-artifacts

- name: 6. Build on Java ${{ matrix.java }} with ${{ matrix.entry.mock-maker }} and ${{ matrix.entry.member-accessor }}
run: ./gradlew build idea --scan
env:
MOCK_MAKER: ${{ matrix.entry.mock-maker }}
MEMBER_ACCESSOR: ${{ matrix.entry.member-accessor }}
- name: 3. Set up Java ${{ matrix.java }}
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: ${{ matrix.java }}

- name: 4. Test on Java ${{ matrix.java }} with ${{ matrix.entry.mock-maker }} and ${{ matrix.entry.member-accessor }}
run: |
./gradlew test \
-x compileTestJava -x compileTestGroovy -x compileTestKotlin -x compileTestBundleJava \
-x classes -x compileJava -x compileGroovy -x compileKotlin -x compileOtherBundleJava \
-x processResources -x processOtherBundleResources \
-x preBuild -x preDebugBuild \
-x jar
Comment on lines +105 to +111
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip: when you have just one command you can do this too:

Suggested change
run: |
./gradlew test \
-x compileTestJava -x compileTestGroovy -x compileTestKotlin -x compileTestBundleJava \
-x classes -x compileJava -x compileGroovy -x compileKotlin -x compileOtherBundleJava \
-x processResources -x processOtherBundleResources \
-x preBuild -x preDebugBuild \
-x jar
run: >
./gradlew test
-x compileTestJava -x compileTestGroovy -x compileTestKotlin -x compileTestBundleJava
-x classes -x compileJava -x compileGroovy -x compileKotlin -x compileOtherBundleJava
-x processResources -x processOtherBundleResources
-x preBuild -x preDebugBuild
-x jar

probably worth keeping the \ version though for consistency with other run: blocks.

env:
MOCK_MAKER: ${{ matrix.entry.mock-maker }}
MEMBER_ACCESSOR: ${{ matrix.entry.member-accessor }}

- name: 7. Upload coverage report
run: |
./gradlew coverageReport -s --scan && cp build/reports/jacoco/mockitoCoverage/mockitoCoverage.xml jacoco.xml
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --keyring trustedkeys.gpg --import # One-time step
- name: 5. Upload coverage report
run: |
./gradlew coverageReport -s --scan && cp build/reports/jacoco/mockitoCoverage/mockitoCoverage.xml jacoco.xml
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --keyring trustedkeys.gpg --import # One-time step

curl -Os https://uploader.codecov.io/latest/linux/codecov
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig
curl -Os https://uploader.codecov.io/latest/linux/codecov
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig

gpgv codecov.SHA256SUM.sig codecov.SHA256SUM
shasum -a 256 -c codecov.SHA256SUM
gpgv codecov.SHA256SUM.sig codecov.SHA256SUM
shasum -a 256 -c codecov.SHA256SUM

chmod +x codecov
./codecov
chmod +x codecov
./codecov

#
# Android build job
Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Main Test Job

on:
workflow_call:
inputs:
mock-maker:
required: true
type: string
member-accessor:
required: true
type: string
java:
required: true
type: number

jobs:
#
# Main test job
#
test:
runs-on: ubuntu-latest
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"

# All test steps
steps:
- name: 1. Checkout out test code
uses: actions/checkout@v3

- name: 2. Download build artifacts with name ${{ inputs.mock-maker }}-${{ inputs.member-accessor }}-build-artifacts
uses: actions/download-artifact@v3
with:
name: ${{ inputs.mock-maker }}-${{ inputs.member-accessor }}-build-artifacts

- name: 3. Set up Java ${{ inputs.java }}
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: ${{ inputs.java }}

- name: 4. Test on Java ${{ inputs.java }} with ${{ inputs.mock-maker }} and ${{ inputs.member-accessor }}
run: |
./gradlew test -x testClasses \
-x compileTestJava -x compileTestGroovy -x compileTestKotlin -x compileTestBundleJava \
-x classes -x compileJava -x compileGroovy -x compileKotlin -x compileOtherBundleJava \
-x processResources -x processOtherBundleResources \
-x preBuild -x preDebugBuild \
-x jar

- name: 5. Upload coverage report
run: |
./gradlew coverageReport -s --scan && cp build/reports/jacoco/mockitoCoverage/mockitoCoverage.xml jacoco.xml
curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --keyring trustedkeys.gpg --import # One-time step

curl -Os https://uploader.codecov.io/latest/linux/codecov
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig

gpgv codecov.SHA256SUM.sig codecov.SHA256SUM
shasum -a 256 -c codecov.SHA256SUM

chmod +x codecov
./codecov