actions / github-script

Write workflows scripting the GitHub API in JavaScript
MIT License
4.24k stars 424 forks source link

Make an API call to a self-hosted/enterprise instance #428

Closed robandpdx closed 1 year ago

robandpdx commented 1 year ago

Is your feature request related to a problem? Please describe. Users would like to make API calls to a self-hosted instance of GitHub Enterprise Server using this action. Currently that is not possible by setting GITHUB_API_URL, as this environment variable is not honored. To demonstrate this issue, use the following workflow...

name: Test

on:
  workflow_dispatch:

jobs:
  test:
    name: Test
    runs-on: ubuntu-latest

    env:
      GHES_API_URL: https://my.github-enterprise-server.com/api/v3

    steps:
      - name: Demonstrate GITHUB_API_URL
        uses: actions/github-script@v6
        env:
          GITHUB_API_URL: ${{ env.GHES_API_URL }}
        with:
          github-token: xxxxx
          script: |
            console.log(`Demonstrate the resolution of GITHUB_API_URL environment variable...`);
            console.log(`GITHUB_API_URL: ${process.env.GITHUB_API_URL}`);

The log of this workflow shows that the GITHUB_API_URL is set to https://api.github.com/ despite being explicitly set otherwise in the workflow. Here is the output...

Run actions/github-script@v6
  with:
    github-token: xxxxx
    script: console.log(`Demonstrate the resolution of GITHUB_API_URL environment variable...`);
  console.log(`GITHUB_API_URL: ${process.env.GITHUB_API_URL}`);

    debug: false
    user-agent: actions/github-script
    result-encoding: json
    retries: 0
    retry-exempt-status-codes: 400,401,403,404,4[2](https://github.com/robandpdx/junk/actions/runs/6589941226/job/17905485324#step:2:2)2
  env:
    GHES_API_URL: https://my.github-enterprise-server.com/api/v[3](https://github.com/robandpdx/junk/actions/runs/6589941226/job/17905485324#step:2:3)
    GITHUB_API_URL: https://my.github-enterprise-server.com/api/v3
Demonstrate the resolution of GITHUB_API_URL environment variable...
GITHUB_API_URL: https://api.github.com/

This was previously discussed in #150 and in #151. However the proposed solution in #151 does not work, as demonstrated above.

Describe the solution you'd like Adding an optional BASE_URL as proposed in #151 would solve this issue.

Describe alternatives you've considered I have forked this repo and added the needed option. However, others would benefit from this change as well

Additional context Nothing to see here.