green-coding-solutions / eco-ci-energy-estimation

Eco CI Energy estimation for Github Actions Runner VMs
MIT License
47 stars 7 forks source link

does-not-run-on: GitHub Enterprise plan #81

Open Freubert opened 2 weeks ago

Freubert commented 2 weeks ago

Our setup suddenly breaks on display-results task with following error. I'm not sure, but we recently changed our plan to GitHub Enterprise and I think this is connected. We had to rearrange some of our own workflows as well, as some data structure is different on the Enterprise plan. Seems like the error arises from the first line of the following snippet.

  echo "$COMMENTS" | jq -c --arg username "github-actions[bot]" '.[] | select(.user.login == $username and (.body | index("Eco-CI") // false))' | while read -r comment; do
      COMMENT_ID=$(echo "$comment" | jq -r '.id')
      COMMENT_BODY=$(echo "$comment" | jq -r '.body')
      INNER_BODY=$(echo "$COMMENT_BODY" | sed 's/<details><summary>Old Energy Estimation<\/summary>//g' | sed 's/<\/details>//g')

      ## indentation here is important, otherwise newlines are not properly sent/processed
      PAYLOAD=$(jq --null-input --arg body "<details><summary>Old Energy Estimation</summary>

  $INNER_BODY

  </details>" '{"body": $body}')
      curl -s -H "Authorization: ***" -X PATCH -d "$PAYLOAD" "[...]/$COMMENT_ID"
      echo "Comment $COMMENT_ID collapsed."
  done

  NEW_COMMENT=$(cat "/tmp/eco-ci/output-pr.txt" | jq -Rs '.')
  API_URL="[...]"
  curl -X POST -H "Authorization: ***" -d @- $API_URL <<EOF
  {
    "body": $NEW_COMMENT
  }
  EOF
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env: [...]
jq: error (at <stdin>:5): Cannot index string with string "user"
Error: Process completed with exit code 5.
ArneTR commented 2 weeks ago

Hey @Freubert ,

thanks for opening an issue on this! We love to see that the tool is in use ❤️

We had issues with Github Enterprise before but never could really drill down the issue as we have not testing setup (we ourselves only use the free plan).

When looking at the code I believe it comes from the fact that the wrong API endpoint is used.

I created a PR that normalizes all API endpoints to the ${{ github.api_url }}, which was not the case so far.

https://github.com/green-coding-solutions/eco-ci-energy-estimation/pull/82

Please check if that already works for you. You can just change the integration in your workflow to uses: green-coding-solutions/eco-ci-energy-estimation@enterprise-fix

If that does not solve your issue it might be that your enterprise github is hosted on a custom domain. Is that the case?

If so you must modify the variable in the inputs as given in the README. See this part:

api-base: (optional) (default: 'api.github.com') Eco-CI uses the github api to post/edit PR comments set to github's default api, but can be changed if you are using github enterprise

Let me know if it works!

Freubert commented 1 week ago

Hi @ArneTR, thanks for the quick response.

Unfortunately this doesn't seem to help. The error message raised stays exactly the same on the fixed branch.

We are not hosted on a custom domain with our enterprise plan. We are on native github.com as well. Therefor, our API url should also simply be api.github.com.

Could I assist any further with more info/logs or something?

ArneTR commented 1 week ago

Is it maybe a private repo you are using?

In case this part of the docs might help: https://github.com/green-coding-solutions/eco-ci-energy-estimation?tab=readme-ov-file#note-on-private-repos

ArneTR commented 1 week ago

Hey @Freubert , sorry the issue was closed automatically although I understand it is not resolved.

I just merged the PR as it was needed anyway, but apparently not a fix to this issue.

Please follow up if you have more details.

The branch to target now with the current version would be eco-ci-energy-estimation@main

Freubert commented 6 days ago

In fact we are using a private repo, but already had the permission set correctly. Before updating to Github Enterprise the workflow ran flawlessly. I'm currently short on time, but will research a little more during the next days or weeks.