Home > OS >  Github actions ./gradlew test can't find directory to run unit test
Github actions ./gradlew test can't find directory to run unit test

Time:08-01

I set up a simple CI work in Github Action for my Android project (Kotlin) that would init unit testing before merging with the master (main) branch

on: 
  push: 
    branches: [ master ] 
  pull_request: 
    branches: [ master ]

jobs: 
  # This workflow contains a single job called "build" 
  build: 
    # The type of runner that the job will run on 
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job 
    steps:
      - uses: actions/checkout@v3
      # Setup JAVA
      - name: set up JDK 1.8
        uses: actions/setup-java@v1
        with:
          java-version: 1.8

      # Execute unit tests
      - name: Unit Test
        run: chmod  x ./gradlew  test

But whenever i push any commit into directory, i receive next error which fails Unit tests and block merging:

Run chmod  x ./gradlew  test
  chmod  x ./gradlew  test
  shell: /usr/bin/bash -e {0}
  env:
    JAVA_HOME_8.0.342_x64: /opt/hostedtoolcache/jdk/8.0.342/x64
    JAVA_HOME: /opt/hostedtoolcache/jdk/8.0.342/x64
    JAVA_HOME_8_0_342_X64: /opt/hostedtoolcache/jdk/8.0.342/x64
chmod: cannot access 'test': No such file or directory
Error: Process completed with exit code 1.

I tried to manually set up a directory with tests using working-directory: app/src/ but it throws the same type of error. What I am doing wrong?

Will provide more info on request. Thanks in advance.

ANSWER: To run unit test in pre-merge, you need to set the correct directory, with the working-directory:, In my case it's :

./app/src/

Changes in workflow .yaml

# List all files (Optional)
  - name: ls
    run: ls -alrth
  - name: add permisiion to gradlew
    run: chmod  x ./gradlew 
    # Execute unit tests
  - name: run unit tests
    working-directory: ./app/src/
    run: chmod  x ./test

CodePudding user response:

I would make multiple RUN commands to ensure where I am and what is in the current folder:

run: pwd
run: ls -alrth
run: chmod  x ./gradlew 
run: chmod  x ./test

AS noted by the OP GremlinShX, a working-directory: ./app/src was missing.

  • Related