Search code examples
github-actionsgradlewkotlin-multiplatform

How to deploy GitHub Action for my KMM project


Currently, I got some problems when I try to write the YAML file for deploying the GitHub action for KMM project. I don't know how to write the correct script (gradlew command) about testing the code of the shared module. Here's a part of my YAML file:

test_job:
    name: Test
    runs-on: ubuntu-latest
    continue-on-error: true
    steps:

      - name: Checkout
        uses: actions/checkout@v2

      - name: Set up JDK 11
        uses: actions/setup-java@v2
        with:
          java-version: '11'
          distribution: 'adopt'

      - name: Validate Gradle wrapper
        uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b

      - name: Restore Cache
        uses: actions/cache@v2
        with:
          path: |
            ~/.gradle/caches
            ~/.gradle/wrapper
          key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
          restore-keys: |
            ${{ runner.os }}-gradle-

      - name: Make gradle executable
        run: chmod +x ./gradlew

      - name: Run Debug Tests
        run: ./gradlew testDebugUnitTest --continue

      - name: Upload Test Reports
        if: ${{ always() }}
        uses: actions/upload-artifact@v2
        with:
          name: test-reports
          path: '**/build/reports/tests/'

Solution

  • You can use:

    • ./gradlew check to run tests for all your targets
    • ./gradlew <targetName>Test to run it for a specific target

    Note that probably you'd want to specify the shared module as well, for ex: ./gradlew :shared:check

    For more information you could check out: https://kotlinlang.org/docs/mpp-run-tests.html#run-tests-for-one-or-more-targets