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

Running infracost action using working-directory #176

Closed
kaykhan opened this issue Aug 16, 2023 · 6 comments
Closed

Running infracost action using working-directory #176

kaykhan opened this issue Aug 16, 2023 · 6 comments

Comments

@kaykhan
Copy link

kaykhan commented Aug 16, 2023

We are using working-directory https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#defaultsrun

defaults:
 run:
  working-directory: applications/prod/kafka-ui

We then define below a cost job.

  cost:
    needs: plan
    name: cost
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout/@v3
    - name: Setup Infracost
      uses: infracost/actions/setup@v2
      with:
        api-key: ${{ secrets.INFRACOST_API_KEY }}
    - name: Checkout base branch
      uses: actions/checkout@v3
      with:
        ref: '${{ github.event.pull_request.base.ref }}'

    - name: Generate Infracost cost estimate baseline
      run: |
        infracost breakdown --path=. \
                            --format=json \
                            --out-file=/tmp/infracost-base.json
    - name: Checkout PR branch
      uses: actions/checkout@v3
    - name: Generate Infracost diff
      run: |
        infracost diff --path=. \
                        --format=json \
                        --compare-to=/tmp/infracost-base.json \
                        --out-file=/tmp/infracost.json
    - name: Post Infracost comment
      run: |
          infracost comment github --path=/tmp/infracost.json \
                                   --repo=$GITHUB_REPOSITORY \
                                   --github-token=${{github.token}} \
                                   --pull-request=${{github.event.pull_request.number}} \
                                   --behavior=new

However this is failing with the following error

An error occurred trying to start process '/usr/bin/bash' with working directory '/home/runner/work/infra-kafka/infra-kafka/applications/prod/kafka-ui'. No such file or directory

any idea what is happening here?

@kaykhan kaykhan changed the title Does not work with working-directory Running infracost action using working-directory Aug 16, 2023
@aliscott
Copy link
Member

@kaykhan are you able to share some additional logs, so we can see at which stage the failure is happening. Once you find the failing step you could add the following to check that the directory exists:

- name: Print directory contents
  run: ls -la

One thing I noticed is that this looks odd: /home/runner/work/infra-kafka/infra-kafka/applications/prod/kafka-ui. It seems like it's repeating the infra-kafka directory twice.

@kaykhan
Copy link
Author

kaykhan commented Aug 17, 2023

I moved away from using working-directory as a default as it does not work with uses github actions. I am assuming there is some conflict occuring whenever working-directory is set. Sorry i cannot be more helpful right now.

Instead i now specify a TF_ROOT variable and it works.

...
`TF_ROOT: applications/prod/kafka-ui`
...

  cost:
    needs: plan
    name: cost
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout/@v3
    - name: Setup Infracost
      uses: infracost/actions/setup@v2
      with:
        api-key: ${{ secrets.INFRACOST_API_KEY }}
    - name: Checkout base branch
      uses: actions/checkout@v3
      with:
        ref: '${{ github.event.pull_request.base.ref }}'
    - name: Generate Infracost cost estimate baseline
      run: |
        infracost breakdown --path=${{ inputs.TF_ROOT }} \
                            --format=json \
                            --out-file=/tmp/infracost-base.json
    - name: Checkout PR branch
      uses: actions/checkout@v3
    - name: Generate Infracost diff
      run: |
        infracost diff --path=${{ inputs.TF_ROOT }} \
                        --format=json \
                        --compare-to=/tmp/infracost-base.json \
                        --out-file=/tmp/infracost.json
    - name: Post Infracost comment
      run: |
          infracost comment github --path=/tmp/infracost.json \
                                   --repo=$GITHUB_REPOSITORY \
                                   --github-token=${{github.token}} \
                                   --pull-request=${{github.event.pull_request.number}} \
                                   --behavior=new

@kaykhan kaykhan closed this as completed Aug 17, 2023
@aliscott
Copy link
Member

Awesome! Thanks for the update @kaykhan.

@alikhajeh1
Copy link
Member

Hi @kaykhan, I'm curious to learn if you considered using the GitHub App as it has several benefits? the feedback helps us learn if we should keep investing in making the GH Actions easier to use in the future too

@kaykhan
Copy link
Author

kaykhan commented Aug 18, 2023

Hi @kaykhan, I'm curious to learn if you considered using the GitHub App as it has several benefits? the feedback helps us learn if we should keep investing in making the GH Actions easier to use in the future too

No particular reason. When we were building our custom terraform ci/cd pipeline using github actions - We thought it was simpler to setup Infracost Github Actions because Infracost Github App setup looks a little more involved.

Maybe its something we would use in the future but right now we are happy with what we have. Infracost for us is a nice to have but not super essential so just a time trade off.

@alikhajeh1
Copy link
Member

@kaykhan thanks for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants