JasonEtco / build-and-tag-action

📦🔖 A GitHub Action for publishing JavaScript Actions
MIT License
92 stars 38 forks source link

GitHub Enterprise support #26

Open gaborho opened 1 year ago

gaborho commented 1 year ago

Hi, is this action comptabile with GitHub Enterprise? When I try to use it, I receive the following error:

ℹ  info      Creating tree
Error: Bad credentials

✖  fatal     HttpError: Bad credentials 
    at /mnt/data/actions-runner/_work/_actions/internal-marketplace/build-and-tag-action/v2/dist/index.js:4476:23
    at processTicksAndRejections (internal/process/task_queues.js:[9](https://code.rbi.tech/raiffeisen/wzhgaho-merlin-gha-helper/runs/307969?check_suite_focus=true#step:5:10)7:5)
    at async Object.createCommit [as default] (/mnt/data/actions-runner/_work/_actions/internal-marketplace/build-and-tag-action/v2/dist/index.js:17383:18)
    at async buildAndTagAction (/mnt/data/actions-runner/_work/_actions/internal-marketplace/build-and-tag-action/v2/dist/index.js:17492:20)

My configuration:

name: publish

on:
  release:
    types: [published, edited]

env:
  NODE_EXTRA_CA_CERTS: /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem

jobs:
  publish:
    runs-on: [ self-hosted, build-testtenant ]
    permissions: write-all
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: ${{ github.event.release.tag_name }}
      - uses: actions/setup-node@v3
        with:
          node-version: 16
      - name: Install deps and build
        run: npm ci && npm run build
      - uses: internal-marketplace/build-and-tag-action@v2
        env:
          DEBUG: '*'
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

I'm pretty sure I hand over correctly the token. The issue is somewhere here, with the createTree API.

https://github.com/JasonEtco/build-and-tag-action/blob/main/src/lib/create-commit.ts#L11

Should this action work with GHES 3.6?

Thank you.

gaborho commented 1 year ago

After adding NODE_DEBUG: http environment variable to my workflow, I can clearly see that the action is talking to api.github.com and not to my GHES instance. I tried to set GITHUB_API_URL as this commit suggests, but did not helped. Can you please add GHES support @JasonEtco ?

cpitchford commented 1 year ago

I've got this working and interacting with my GitHub Enterprise Server, but its not only a fix here.

Working backwards, this code relies on https://github.com/JasonEtco/actions-toolkit where we use the run method here: https://github.com/JasonEtco/build-and-tag-action/blob/8aebd433ae6d9f3d7433205d11740c3f5163db8e/src/index.ts#L4

The constructor then create the github property using the Octokit class here: https://github.com/JasonEtco/actions-toolkit/blob/c6c7208c521db3b7418dbc9cf5eab282a501250e/src/index.ts#L142

This Octokit object was the issue, it doesn't know how to reach my GitHub Enterprise Server

In my copy of the code, I changed this

    this.github = new Octokit({ auth: `token ${this.token}` })

becomes

this.github = new Octokit({
  auth: `token ${this.token}`,
  baseUrl:  `${process.env.GITHUB_URL}api/v3`
})

With this change, the Octokit object now knows how to reach my enterprise server