Skip to content

feat: Github Actions - set working directory in step #66

@pixo-wnobrien

Description

@pixo-wnobrien

I have a repo with a couple different projects in it, and I would like to set up a workflow that tests all the projects on a PR. It would be great if I could set the working directory in the step like below:

      - name: Check Test Coverage
        uses: vladopajic/go-test-coverage@v2
        with:
          working-directory: app1
          config: .coverage.yaml

      - name: Check Test Coverage
        uses: vladopajic/go-test-coverage@v2
        with:
          working-directory: app2
          config: .coverage.yaml

I usually use golangci-lint in the same pipeline before I run my tests, and the Github Action for that works in this way

      - name: Lint
        uses: golangci/golangci-lint-action@v3
        with:
          version: v1.54
          working-directory: ./app1

I've tried many different workarounds, but I'm having a hard time getting it to work in my repo with multiple projects without this feature. If there are any suggestions that would be greatly appreciated! I put my workflow file below for reference

jobs:
  test-app1:
    runs-on: ubuntu-latest

    defaults:
      run:
        working-directory: ./app1

    steps:
      - uses: actions/checkout@v3

      - name: Setup Go
        uses: actions/setup-go@v4
        with:
          go-version: '1.21'

      - name: Lint
        uses: golangci/golangci-lint-action@v3
        with:
          version: v1.54
          install-mode: "goinstall"
          args: --timeout=30m
          working-directory: ./app1

      - name: Run Tests
        run: make test

      - name: Check Test Coverage
        uses: vladopajic/go-test-coverage@v2
        with:
          config: app1/.coverage.yaml

  test-app2:
    runs-on: ubuntu-latest

    defaults:
      run:
        working-directory: ./app2

    steps:
      - uses: actions/checkout@v3

      - name: Setup Go
        uses: actions/setup-go@v4
        with:
          go-version: '1.21'

      - name: Lint
        uses: golangci/golangci-lint-action@v3
        with:
          version: v1.54
          install-mode: "goinstall"
          args: --timeout=30m
          working-directory: ./app2

      - name: Run Tests
        run: make test

      - name: Check Test Coverage
        uses: vladopajic/go-test-coverage@v2
        with:
          config: app2/.coverage.yaml

permissions:
  contents: read

I can configure the step to use the corresponding cover.out file, but since the step is not running in the directory that the tests were run in I get the following error:

failed to generate coverage statistics: could not find file [github.com/org/repo/app1/docs/docs.go]: can't find "docs.go": no required module provides package github.com/org/repo/app1/docs: go.mod file not found in current directory or any parent directory; see 'go help modules'

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions