lowlighter / metrics

πŸ“Š An infographics generator with 30+ plugins and 300+ options to display stats about your GitHub account and render them as SVG, Markdown, PDF or JSON!
https://metrics.lecoq.io
MIT License
13.46k stars 1.67k forks source link

Error "Bad Credentials" when running github action #1581

Closed NikosDev closed 9 months ago

NikosDev commented 9 months ago

Discussed in https://github.com/lowlighter/metrics/discussions/1580

Originally posted by **NikosDev** December 11, 2023 I have used the [ github action setup](https://github.com/lowlighter/metrics/blob/master/.github/readme/partials/documentation/setup/action.md) to create my metrics but it fails with error "Bad Credentials" when github action is triggered. I have created a secret in my repository called METRICS_TOKEN and assigned the token value. My yaml file is this: ```yaml # Visit https://github.com/lowlighter/metrics#-documentation for full reference name: Metrics on: # Schedule updates (each hour) schedule: [{cron: "0 * * * *"}] # Lines below let you run workflow manually and on each commit workflow_dispatch: push: {branches: ["master", "main"]} jobs: github-metrics: runs-on: ubuntu-latest permissions: contents: write steps: - uses: lowlighter/metrics@latest with: # Your GitHub token # The following scopes are required: # - public_access (default scope) # The following additional scopes may be required: # - read:org (for organization related metrics) # - read:user (for user related data) # - read:packages (for some packages related data) # - repo (optional, if you want to include private repositories) token: ${{ secrets.METRICS_TOKEN }} # Options user: NikosDev template: classic base: header, activity, community, repositories, metadata config_timezone: Europe/Athens ``` My github action error: ![image](https://github.com/lowlighter/metrics/assets/16862640/001e7610-6d69-4add-9d2d-e1691688df6b) Github action error log: ```yaml ───── Metrics β”‚ Setup β”‚ complete Version β”‚ 3.34.0 Using prebuilt image β”‚ true Debug mode β”‚ false Debug flags β”‚ (none) GitHub token β”‚ (provided) GitHub token format β”‚ classic GitHub GraphQL API β”‚ ok GitHub GraphQL API endpoint β”‚ (default) GitHub REST API β”‚ ok GitHub REST API endpoint β”‚ (default) API requests (REST) β”‚ (unknown) API requests (GraphQL) β”‚ (unknown) API requests (Search) β”‚ (unknown) Token validity β”‚ (could not verify) GitHub account β”‚ NikosDev Current repository β”‚ NikosDev/NikosDev Committer token β”‚ (provided) Committer branch β”‚ main Committer head branch β”‚ main Committer REST API β”‚ ok Committer account β”‚ (github-actions) Committer head branch status β”‚ ok Previous render sha β”‚ (none) SVG output β”‚ github-metrics.svg SVG optimization β”‚ css, xml SVG verification after generation β”‚ false ──────────────────────────────────────────────────────────────────────────────────────── Templates β”‚ Community templates β”‚ (none) Template used β”‚ classic Query additional params β”‚ {} ──────────────────────────────────────────────────────────────────────────────────────── Core β”‚ Markdown template path β”‚ TEMPLATE.md Extra CSS β”‚ Extra JavaScript β”‚ Timezone for dates β”‚ Europe/Athens Plugin order β”‚ Use twemojis β”‚ false Use GitHub custom emojis β”‚ true Use GitHub octicons β”‚ false Display width (for image output formats) β”‚ regular Use CSS animations β”‚ true Base64-encoded images β”‚ true Output padding β”‚ 0, 8 + 11% Output format β”‚ auto Configuration presets β”‚ Notice about new releases of metrics β”‚ true Experimental features β”‚ Plugin errors β”‚ (displayed in generated image) ──────────────────────────────────────────────────────────────────────────────────────── Base content β”‚ Fetched repositories β”‚ 100 Indepth mode β”‚ false Show `Available for hire!` in header section β”‚ false Skip base content β”‚ false Fetched repositories per query β”‚ 100 Include forks β”‚ false Repositories affiliations β”‚ owner Default skipped repositories β”‚ Default ignored users β”‚ github-actions[bot],dependabot[bot],dependabot-preview[bot],actions-user,action@github.com Identifiers that has been used for authoring commits β”‚ .user.login Base sections β”‚ header, activity, community, repositories, metadata ──────────────────────────────────────────────────────────────────────────────────────── Rendering β”‚ RequestError [HttpError]: Bad credentials at /metrics/node_modules/@octokit/graphql/node_modules/@octokit/request/dist-node/index.js:112:21 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Object.default [as base] (file:///metrics/source/plugins/base/index.mjs:32:23) at async metrics (file:///metrics/source/app/metrics/index.mjs:79:5) at async retry.retries.retries (file:///metrics/source/app/action/index.mjs:407:40) at async retry (file:///metrics/source/app/action/index.mjs:57:22) at async file:///metrics/source/app/action/index.mjs:406:28 { ──────────────────────────────────────────────────────────────────────────────────────── undefined An error occurred, logging debug message : TypeError: Cannot read properties of null (reading 'oid') at file:///metrics/source/app/action/index.mjs:307:38 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) Attempt 1/3 metrics/compute/NikosDev > start { template: 'classic', 'debug.flags': '', markdown: 'TEMPLATE.md', 'extras.css': '', 'extras.js': '', 'config.timezone': 'Europe/Athens', 'config.order': [], 'config.twemoji': false, 'config.gemoji': true, 'config.octicon': false, 'config.display': 'regular', 'config.animations': true, 'config.base64': true, 'config.padding': '0, 8 + 11%', 'config.output': 'auto', 'config.presets': [], 'notice.releases': true, 'experimental.features': [], hireable: false, skip: false, 'repositories.batch': 100, 'repositories.forks': false, 'repositories.affiliations': [ 'owner' ], 'repositories.skipped': [], 'users.ignored': [ 'github-actions[bot]', 'dependabot[bot]', 'dependabot-preview[bot]', 'actions-user', 'action@github.com' ], 'commits.authoring': [ '.user.login' ], base: false, 'base.header': true, 'base.activity': true, 'base.community': true, 'base.repositories': true, 'base.metadata': true, 'base.indepth': false } metrics/compute/NikosDev > output format set to svg metrics/compute/NikosDev > content order : base.header,introduction,base.activity+community,base.repositories,lines,followup,discussions,languages,notable,projects,repositories,gists,pagespeed,habits,topics,music,nightscout,posts,rss,tweets,isocalendar,calendar,stars,starlists,stargazers,people,activity,reactions,anilist,wakatime,skyline,support,stackoverflow,leetcode,stock,achievements,screenshot,code,chess,sponsors,sponsorships,poopmap,16personalities,fortune,splatoon,steam metrics/compute/NikosDev > compute metrics/compute/NikosDev/base > started metrics/compute/NikosDev/base > affiliations constraints , ownerAffiliations: [OWNER], affiliations: [OWNER] metrics/compute/NikosDev/base > account user metrics/compute/NikosDev/base > account user > failed : HttpError: Bad credentials Warning: Bad credentials Attempt 2/3 Warning: Bad credentials Attempt 3/3 Warning: Bad credentials Error: Bad credentials Error: Process completed with exit code 1. ```
NikosDev commented 9 months ago

I solved the issue by adding an environment key-value to the yaml file πŸŽ‰πŸŽ‰πŸŽ‰

This is my working yaml file:

# Visit https://github.com/lowlighter/metrics#-documentation for full reference
name: Metrics
on:
  # Schedule updates (each hour)
  schedule: [{cron: "0 * * * *"}]
  # Lines below let you run workflow manually and on each commit
  workflow_dispatch:
  push: {branches: ["master", "main"]}
jobs:
  github-metrics:
    runs-on: ubuntu-latest
    environment: 
      name: production
    permissions:
      contents: write
    steps:
      - uses: lowlighter/metrics@latest
        with:
          # Your GitHub token
          # The following scopes are required:
          #  - public_access (default scope)
          # The following additional scopes may be required:
          #  - read:org      (for organization related metrics)
          #  - read:user     (for user related data)
          #  - read:packages (for some packages related data)
          #  - repo          (optional, if you want to include private repositories)
          token: ${{ secrets.METRICS_TOKEN }}

          # Options
          user: NikosDev
          template: classic
          base: header, activity, community, repositories, metadata
          config_timezone: Europe/Athens

And this is the METRICS_TOKEN that i specified in my personal repository: image