Running infracost action using `working-directory`
kaykhan opened this issue · 6 comments
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 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.
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
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
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.
@kaykhan thanks for the feedback!