Skip to content

artifact.uploadArtifact Fails with "Unable to get the ACTIONS_RUNTIME_TOKEN env variable" #2009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jason89521 opened this issue Mar 28, 2025 · 0 comments

Comments

@jason89521
Copy link

Describe the Problem

Calling artifactClient.uploadArtifact results in the following error:

Error: Unable to get the ACTIONS_RUNTIME_TOKEN env variable

The Workflow File

name: FooBar

run-name: 'FooBar'

on:
  pull_request:
    branches:
      - master
    types: [opened, synchronize, reopened, ready_for_review]

jobs:
  exec-script:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '16'

      - name: Install dependencies
        run: npm ci

      - name: Execute the script
        run: node ./scripts/my-script.mjs
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          BASE_STATS_PATH: ./base/stats.json
          CURRENT_STATS_PATH: ./current/stats.json

Script File

import { DefaultArtifactClient } from '@actions/artifact'
import * as core from '@actions/core'
import { context, getOctokit } from '@actions/github'
import { createHTMLArtifact } from '@bundle-stats/cli-utils'
import { createJobs, createReport } from '@bundle-stats/utils'
import { readFile, writeFile } from 'fs/promises'
import process from 'node:process'

const {
	repo: { owner, repo: repoName },
	issue: { number: prNumber },
} = context
const githubToken = getEnv('GITHUB_TOKEN')
const baseStatsPath = getEnv('BASE_STATS_PATH')
const currentStatsPath = getEnv('CURRENT_STATS_PATH')
const octokit = getOctokit(githubToken)
const artifactClient = new DefaultArtifactClient()

;(async () => {
        // ...
        // Generate the report
	const bundleStatsHTML = createHTMLArtifact(jobs, report)
	await writeFile('bundle-stats.html', bundleStatsHTML)
	core.info('Uploading artifact')
	try {
		const { id: artifactId } = await artifactClient.uploadArtifact('bundle-stats-html', ['./bundle-stats.html'], './')
		if (!artifactId) {
			core.setFailed('Failed to upload artifact')
			return
		}
	} catch (error) {
		console.error(error)
	}

	// Create comment and so on...
        // ...
})()

Question

I'm unsure why calling artifactClient.uploadArtifact results in the error:

Error: Unable to get the ACTIONS_RUNTIME_TOKEN env variable

Do I need to manually set this environment variable? Or is there something missing in my workflow setup?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant