octokit / request-action

A GitHub Action to send arbitrary requests to GitHub's REST API
https://github.com/marketplace/actions/GitHub-API-Request
MIT License
369 stars 47 forks source link

Suddenly API returned 404 #80

Closed rishubil closed 3 years ago

rishubil commented 3 years ago

I have been using request-action normally at https://github.com/yf-dev/majsoul-plus-korean until yesterday.

However, about 11 hours ago, I found that the return value of API requests using request-action was changed to 404 without any reason.

I checked the request in request-action debug logs and tried to request it again through curl on the local computer as it is, but I was confused when I saw API returned 204 well.

Is there anything else I can check?

Debug log

##[debug]Evaluating: secrets.GITHUB_TOKEN
##[debug]Evaluating Index:
##[debug]..Evaluating secrets:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'GITHUB_TOKEN'
##[debug]=> '***'
##[debug]Result: '***'
##[debug]Evaluating condition for step: 'Run octokit/request-action@v2.x'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: Run octokit/request-action@v2.x
##[debug]Loading inputs
##[debug]Evaluating: format('GET /repos/:repository/collaborators/{0}', github.actor)
##[debug]Evaluating format:
##[debug]..Evaluating String:
##[debug]..=> 'GET /repos/:repository/collaborators/{0}'
##[debug]..Evaluating Index:
##[debug]....Evaluating github:
##[debug]....=> Object
##[debug]....Evaluating String:
##[debug]....=> 'actor'
##[debug]..=> 'rishubil'
##[debug]=> 'GET /repos/:repository/collaborators/rishubil'
##[debug]Result: 'GET /repos/:repository/collaborators/rishubil'
##[debug]Evaluating: github.repository
##[debug]Evaluating Index:
##[debug]..Evaluating github:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'repository'
##[debug]=> 'yf-dev/majsoul-plus-korean'
##[debug]Result: 'yf-dev/majsoul-plus-korean'
Warning: Unexpected input(s) 'repository', valid inputs are ['route', 'mediaType']
##[debug]Loading env
Run octokit/request-action@v2.x
  with:
    route: GET /repos/:repository/collaborators/rishubil
    repository: yf-dev/majsoul-plus-korean
    mediaType: {}
  env:
    GITHUB_TOKEN: ***
GET /repos/:repository/collaborators/rishubil
> repository: yf-dev/majsoul-plus-korean
> mediaType: [object Object]
##[debug]route: 'GET /repos/:repository/collaborators/rishubil'
##[debug]parameters: { repository: 'yf-dev/majsoul-plus-korean', mediaType: {} }
##[debug]parsed request options: {
##[debug]  method: 'GET',
##[debug]  headers: {
##[debug]    accept: 'application/vnd.github.v3+json',
##[debug]    'user-agent': 'octokit-action.js/3.2.0 octokit-core.js/3.2.4 Node.js/12.13.1 (linux; x64)'
##[debug]  },
##[debug]  request: { hook: [Function: bound bound register] },
##[debug]  data: undefined,
##[debug]  url: 'https://api.github.com/repos/yf-dev/majsoul-plus-korean/collaborators/rishubil'
##[debug]}
##[debug]RequestError [HttpError]: Not Found
##[debug]    at /home/runner/work/_actions/octokit/request-action/v2.x/dist/index.js:6214:23
##[debug]    at processTicksAndRejections (internal/process/task_queues.js:93:5)
##[debug]    at async main (/home/runner/work/_actions/octokit/request-action/v2.x/dist/index.js:404:39) {
##[debug]  name: 'HttpError',
##[debug]  status: 404,
##[debug]  headers: {
##[debug]    'access-control-allow-origin': '*',
##[debug]    'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset',
##[debug]    connection: 'close',
##[debug]    'content-encoding': 'gzip',
##[debug]    'content-security-policy': "default-src 'none'",
##[debug]    'content-type': 'application/json; charset=utf-8',
##[debug]    date: 'Tue, 23 Feb 2021 01:33:33 GMT',
##[debug]    'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
##[debug]    server: 'GitHub.com',
##[debug]    'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
##[debug]    'transfer-encoding': 'chunked',
##[debug]    vary: 'Accept-Encoding, Accept, X-Requested-With',
##[debug]    'x-content-type-options': 'nosniff',
##[debug]    'x-frame-options': 'deny',
##[debug]    'x-github-media-type': 'github.v3; format=json',
##[debug]    'x-github-request-id': '07C1:5299:3B87212:5F6507E:60345B6D',
##[debug]    'x-ratelimit-limit': '1000',
##[debug]    'x-ratelimit-remaining': '996',
##[debug]    'x-ratelimit-reset': '1614046910',
##[debug]    'x-ratelimit-used': '4',
##[debug]    'x-xss-protection': '1; mode=block'
##[debug]  },
##[debug]  request: {
##[debug]    method: 'GET',
##[debug]    url: 'https://api.github.com/repos/yf-dev/majsoul-plus-korean/collaborators/rishubil',
##[debug]    headers: {
##[debug]      accept: 'application/vnd.github.v3+json',
##[debug]      'user-agent': 'octokit-action.js/3.2.0 octokit-core.js/3.2.4 Node.js/12.13.1 (linux; x64)',
##[debug]      authorization: 'token [REDACTED]'
##[debug]    },
##[debug]    request: { hook: [Function: bound bound register] }
##[debug]  },
##[debug]  documentation_url: 'https://docs.github.com/rest/reference/repos#check-if-a-user-is-a-repository-collaborator'
##[debug]}
Error: Not Found
##[debug]Node Action run completed with exit code 1
##[debug]Finishing: Run octokit/request-action@v2.x

Curl log

$ curl -i --request GET --url https://api.github.com/repos/yf-dev/majsoul-plus-korean/collaborators/rishubil --header 'accept: application/vnd.github.v3+json' --header 'authorization: token [mytoken]' --header 'user-agent: octokit-action.js/3.2.0 octokit-core.js/3.2.4 Node.js/12.13.1 (linux; x64)'

HTTP/2 204
server: GitHub.com
date: Tue, 23 Feb 2021 01:39:18 GMT
x-oauth-scopes: repo, workflow
x-accepted-oauth-scopes:
x-github-media-type: github.v3; format=json
x-ratelimit-limit: 5000
x-ratelimit-remaining: 4968
x-ratelimit-reset: 1614046873
x-ratelimit-used: 32
access-control-expose-headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset
access-control-allow-origin: *
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'
vary: Accept-Encoding, Accept, X-Requested-With
x-github-request-id: FC7E:4120:24361D:6E749F:60345CC6
gr2m commented 3 years ago

There was a lock file update in that time frame. Can you check if the error persist with the prior version (01a594f812f65f72258093beb52b2b89429eb853)

octokit/request-action@01a594f812f65f72258093beb52b2b89429eb853
rishubil commented 3 years ago

I just applied and tested it, but It's still the same. When the problem occurred, I was using a specific version(octokit/request-action@v2.0.0) so I don't think it's an issue related to that.

I think I should test it using curl directly in github action.

rishubil commented 3 years ago

I tried to use curl by accessing github action with ssh using debugging-with-tmate. I have checked that 204 will be returned normally if requested by curl. It's hard to understand why this is happening, is there anything else I can test?

gr2m commented 3 years ago

I tried to reproduce your problem, but no luck.

Here is my workflow file:

https://github.com/gr2m/sandbox/blob/5e75f95f76825b8bc402916f16207dbfa4866ad4/.github/workflows/debug.yml

Here is the action run

https://github.com/gr2m/sandbox/runs/1963580718

I'm running out of ideas what the problem might be. Can you try this?

      - uses: octokit/request-action@v2.x
        with:
          route: GET /repos/:repository/collaborators/rishubil 
          repository: ${{ github.repository }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

If that is failing, can you copy and past my debug.yml file into your repository and run the workflow using the manual dispatch? Make sure to replace gr2m with rishubil

If that's all failing, I'd suggest you contact support, they will be able to help you better: https://support.github.com/contact

rishubil commented 3 years ago

I don't know why, but about 9 hours ago, github action started returning 204 normally! Perhaps it was an issue of github action itself.

Thank you for your kind response.

gr2m commented 3 years ago

no worries! Glad to hear it's all working again!

praneetloke commented 2 years ago

Apologies for commenting on a closed issue but I seem to be running into this. No matter what I do the action always fails with a 404 and nothing in the debug logs looks out-of-place.

Logs ``` 0s ##[debug]Evaluating: secrets.GITHUB_TOKEN ##[debug]Evaluating Index: ##[debug]..Evaluating secrets: ##[debug]..=> Object ##[debug]..Evaluating String: ##[debug]..=> 'GITHUB_TOKEN' ##[debug]=> '***' ##[debug]Result: '***' ##[debug]Evaluating condition for step: 'Run octokit/request-action@v2.x' ##[debug]Evaluating: success() ##[debug]Evaluating success: ##[debug]=> true ##[debug]Result: true ##[debug]Starting: Run octokit/request-action@v2.x ##[debug]Loading inputs ##[debug]Evaluating: format('GET /repos/:repository/releases/{0}', env.RELEASE_TAG) ##[debug]Evaluating format: ##[debug]..Evaluating String: ##[debug]..=> 'GET /repos/:repository/releases/{0}' ##[debug]..Evaluating Index: ##[debug]....Evaluating env: ##[debug]....=> Object ##[debug]....Evaluating String: ##[debug]....=> 'RELEASE_TAG' ##[debug]..=> 'v0.0.47' ##[debug]=> 'GET /repos/:repository/releases/v0.0.47' ##[debug]Result: 'GET /repos/:repository/releases/v0.0.47' ##[debug]Evaluating: github.repository ##[debug]Evaluating Index: ##[debug]..Evaluating github: ##[debug]..=> Object ##[debug]..Evaluating String: ##[debug]..=> 'repository' ##[debug]=> 'praneetloke/[redactedRepo]' ##[debug]Result: 'praneetloke/[redactedRepo]' Warning: Unexpected input(s) 'repository', valid inputs are ['route', 'mediaType'] ##[debug]Loading env Run octokit/request-action@v2.x GET /repos/:repository/releases/v0.0.47 > repository: praneetloke/[redactedRepo] > mediaType: [object Object] ##[debug]route: 'GET /repos/:repository/releases/v0.0.47' ##[debug]parameters: { repository: 'praneetloke/[redactedRepo]', mediaType: {} } ##[debug]parsed request options: { ##[debug] method: 'GET', ##[debug] headers: { ##[debug] accept: 'application/vnd.github.v3+json', ##[debug] 'user-agent': 'octokit-action.js/3.7.1 octokit-core.js/3.4.0 Node.js/12.13.1 (linux; x64)' ##[debug] }, ##[debug] request: { hook: [Function: bound bound register] }, ##[debug] data: undefined, ##[debug] url: 'https://api.github.com/repos/praneetloke/[redactedRepo]/releases/v0.0.47' ##[debug]} < 404 159ms ::set-output name=status::404 ##[debug]steps.get_release.outputs.status='404' ##[debug]RequestError [HttpError]: Not Found ##[debug] at /home/runner/work/_actions/octokit/request-action/v2.x/dist/index.js:6251:23 ##[debug] at processTicksAndRejections (internal/process/task_queues.js:93:5) ##[debug] at async main (/home/runner/work/_actions/octokit/request-action/v2.x/dist/index.js:404:39) { ##[debug] name: 'HttpError', ##[debug] status: 404, ##[debug] headers: { ##[debug] 'access-control-allow-origin': '*', ##[debug] 'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset', ##[debug] connection: 'close', ##[debug] 'content-encoding': 'gzip', ##[debug] 'content-security-policy': "default-src 'none'", ##[debug] 'content-type': 'application/json; charset=utf-8', ##[debug] date: 'Wed, 29 Dec 2021 15:12:02 GMT', ##[debug] 'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin', ##[debug] server: 'GitHub.com', ##[debug] 'strict-transport-security': 'max-age=31536000; includeSubdomains; preload', ##[debug] 'transfer-encoding': 'chunked', ##[debug] vary: 'Accept-Encoding, Accept, X-Requested-With', ##[debug] 'x-content-type-options': 'nosniff', ##[debug] 'x-frame-options': 'deny', ##[debug] 'x-github-media-type': 'github.v3; format=json', ##[debug] 'x-github-request-id': '07C0:340E:3711DF4:78398FE:61CC7AC2', ##[debug] 'x-ratelimit-limit': '1000', ##[debug] 'x-ratelimit-remaining': '983', ##[debug] 'x-ratelimit-reset': '1640793446', ##[debug] 'x-ratelimit-resource': 'core', ##[debug] 'x-ratelimit-used': '17', ##[debug] 'x-xss-protection': '0' ##[debug] }, ##[debug] request: { ##[debug] method: 'GET', ##[debug] url: 'https://api.github.com/repos/praneetloke/[redactedRepo]/releases/v0.0.47', ##[debug] headers: { ##[debug] accept: 'application/vnd.github.v3+json', ##[debug] 'user-agent': 'octokit-action.js/3.7.1 octokit-core.js/3.4.0 Node.js/12.13.1 (linux; x64)', ##[debug] authorization: 'token [REDACTED]' ##[debug] }, ##[debug] request: { hook: [Function: bound bound register] } ##[debug] }, ##[debug] documentation_url: 'https://docs.github.com/rest/reference/repos#get-a-release' ##[debug]} ```

I tried creating a new PAT with the repo scope and using that and yet I can't seem to be able to call the /releases API using this GH action. The same token works just fine when I make a curl request directly.

gr2m commented 2 years ago

Most likely an authentication problem. What do you pass as GITHUB_TOKEN? If you set it to ${{ secrets.GITHUB_TOKEN }}, is the request going to the same repository where you run the action? If not, then you will need a different means of authentication

praneetloke commented 2 years ago

Yeah the request is going to the same repo which is private. Suspecting a problem with the token perms, I created a new PAT and mapped that to GITHUB_TOKEN in the env map for the step. That still does not work with this action. As noted in my earlier comment, I can make the API call manually using curl with that new token just fine.

praneetloke commented 2 years ago

🤦‍♂️ so it was my fault. The action is working just fine. I was calling the wrong URL in the action. To be able to get a release by a tag, the correct endpoint is repos/:repository/releases/tags/:tag_name. When I ran the curl test I ran one from my command history where I evidently had the correct URL. I can't tell you how silly I feel right now!

gr2m commented 2 years ago

Glad you got it working!

🤔 we could compare the path to all known pats based on the OpenAPI spec, might have saved you and probably many others lots of headaches. We could log a warning? What do you think

praneetloke commented 2 years ago

@gr2m hmm I don't think I follow...

gr2m commented 2 years ago

Here is how it would work in case anyone wants to work on it:

The setup would work similar to how https://github.com/octokit/plugin-paginate-rest.js updates src/generated/paginating-endpoints.ts.

  1. Create an update workflow like octokit/plugin-paginate-rest.js:.github/workflows/update.ym
  2. Create an update-endpoints script that will take the OpenAPI specification from @octokit/openapi, create/update a generated/rest-api-routes.js file, which would be an array of all REST API routes that GitHub supports
  3. When sending a request, compare the given route to the known routes defined in generated/rest-api-routes.js. If the route is unknown, log a warning if the response is a 404.

No worries if that doesn't make sense @praneetloke, there is lots of inside knowledge behind how the automated updates work for the@octokit/* packages based updates to GitHub's OpenAPI specifications