c-hive / gha-remove-artifacts

GitHub Action to customize artifact cleanup

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`TypeError: (s || "").replace is not a function` when trying to run action

ggarnier opened this issue · comments

I've created this yaml file:

name: "Delete old artifacts"
on:
  schedule:
  - cron: "0 * * * *" # every hour

jobs:
  delete-artifacts:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
    - uses: c-hive/gha-remove-artifacts@v1
      with:
        GITHUB_TOKEN: ${{ secrets.GITHUB_ACCESS_TOKEN }}
        age: '7 days'
        skip-tags: true

When the job runs, I get this error:

Error while requesting tags:  RequestError [HttpError]: Not Found
    at /home/runner/work/_actions/c-hive/gha-remove-artifacts/v1/dist/index.js:11376:23
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Job.doExecute (/home/runner/work/_actions/c-hive/gha-remove-artifacts/v1/dist/index.js:14132:18) {
  name: 'HttpError',
  status: 404,
  headers: {
    'access-control-allow-origin': '*',
    'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset',
    connection: 'close',
    'content-encoding': 'gzip',
    'content-security-policy': "default-src 'none'",
    'content-type': 'application/json; charset=utf-8',
    date: 'Mon, 30 Mar 2020 22:05:16 GMT',
    'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
    server: 'GitHub.com',
    status: '404 Not Found',
    'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
    'transfer-encoding': 'chunked',
    vary: 'Accept-Encoding, Accept, X-Requested-With',
    'x-accepted-oauth-scopes': '',
    'x-content-type-options': 'nosniff',
    'x-frame-options': 'deny',
    'x-github-media-type': 'github.v3; format=json',
    'x-github-request-id': '0401:29F9:8DB5F:EBC3D:5E826D1C',
    'x-oauth-scopes': 'workflow',
    'x-ratelimit-limit': '5000',
    'x-ratelimit-remaining': '4996',
    'x-ratelimit-reset': '1585606782',
    'x-xss-protection': '1; mode=block'
  },
  request: {
    method: 'GET',
    url: 'https://api.github.com/repos/***/test-repo/tags?per_page=100&ref=tags',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'octokit-action.js/2.0.0 octokit-core.js/2.4.2 Node.js/12.13.1 (Linux 5.0; x64)',
      authorization: 'token [REDACTED]'
    },
    request: { hook: [Function: bound bound register] }
  },
  documentation_url: 'https://developer.github.com/v3/repos/#list-tags'
}
(node:2466) UnhandledPromiseRejectionWarning: TypeError: (s || "").replace is not a function
    at escapeData (/home/runner/work/_actions/c-hive/gha-remove-artifacts/v1/dist/index.js:3435:10)
    at Command.toString (/home/runner/work/_actions/c-hive/gha-remove-artifacts/v1/dist/index.js:3429:35)
    at issueCommand (/home/runner/work/_actions/c-hive/gha-remove-artifacts/v1/dist/index.js:3392:30)
    at Object.issue (/home/runner/work/_actions/c-hive/gha-remove-artifacts/v1/dist/index.js:3396:5)
    at error (/home/runner/work/_actions/c-hive/gha-remove-artifacts/v1/dist/index.js:5557:15)
    at Object.setFailed (/home/runner/work/_actions/c-hive/gha-remove-artifacts/v1/dist/index.js:5531:5)
    at /home/runner/work/_actions/c-hive/gha-remove-artifacts/v1/dist/index.js:680:8
(node:2466) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2466) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Maximum artifact age: 7 days ( created before 2020-03-23T22:05:15+00:00 )

Thanks for reporting.

The TypeError is coming from the way we set the state of the job to failed: actions/toolkit#321. We'll fix that.

However, the underlying issue is a 404 coming from the tags endpoint. You seem to be using secrets.GITHUB_ACCESS_TOKEN. You're supposed to use secrets.GITHUB_TOKEN that is provided by default and is bound to the repo, no need for your own token. It's possible that you don't have the correct rights on it, hence the 404.

The TypeError should be resolved in https://github.com/c-hive/gha-remove-artifacts/releases/tag/v1.0.2 (you should continue using @v1 to run the action).

However, the underlying issue is a 404 coming from the tags endpoint. You seem to be using secrets.GITHUB_ACCESS_TOKEN. You're supposed to use secrets.GITHUB_TOKEN that is provided by default and is bound to the repo, no need for your own token. It's possible that you don't have the correct rights on it, hence the 404.

I thought I could use any secret in this line: GITHUB_TOKEN: ${{ secrets.MY_SECRET_NAME }}, and it would be injected as GITHUB_TOKEN in the action... 🤔
Anyway, I replaced the token line with GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}, and now it's working!

Thanks for the quick help!!! 🚀