version-check icon indicating copy to clipboard operation
version-check copied to clipboard

Error: Cannot read properties of undefined (reading '_links')

Open allenyummy opened this issue 2 years ago • 12 comments

Hello,

I used version_check in my GitHub action workflow, and encountered the problem below. Does anyone face the same problem ?

image

I found the source code _links here https://github.com/EndBug/version-check/blob/main/src/main.ts#L124

allenyummy avatar Apr 23 '23 07:04 allenyummy

Hmm, that's weird, with what event are you using the actions?

EndBug avatar Apr 23 '23 14:04 EndBug

I have this too :/

Using actions/checkout@v3 in my workflow right before using this action and the event is workflow_dispatch for testing purposes

lkreimann avatar May 12 '23 12:05 lkreimann

Oh, ok, then I get what's the issue: here I'm checking for the commit list to create get the diff, and I can't get it from the event unless it's a PR or push event.
The solution would be using the static-checking input when running on workflow dispatch.

Anyway, there should be a user-friendly error telling you this, so I'm going to keep this issue open until I add it (it might take a while tho, PR appreciated ✨)

Thanks for reporting the issue!

EndBug avatar May 12 '23 13:05 EndBug

Im getting this error too when using workflow_call to trigger my action

ljukas avatar Oct 30 '23 13:10 ljukas

Hey @ljukas, as mentioned above,

The solution would be using the static-checking input when running on workflow dispatch.

If you're having issues while doing that, feel free to let me know, maybe in a new issue so that we don't ping previous participants ;)

EndBug avatar Oct 30 '23 14:10 EndBug

@EndBug I'm seeing the same error when running the workflow locally using act. Any tips?

lizozom avatar Feb 29 '24 10:02 lizozom

Hey @lizozom, have you tried the solution described above? Using act may affect the action's behavior, as it's heavily based on the event that triggers the (normal) action run

EndBug avatar Mar 01 '24 10:03 EndBug

Did we figure out how to make it work with workflow_call? I'm getting Error: Cannot read properties of undefined (reading '_links')

name: Publish To NPM

on:
  workflow_call:
    inputs:
      project-path:
        required: true
        type: string
    secrets:
      TOKEN:
        required: true

jobs:
  check-npm-version-changes:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          token: ${{ secrets.TOKEN }}

      - name: Check if NPM version has been updated
        uses: EndBug/version-check@v2
        id: version-check
        with:
          diff-search: true
          file-name: ${{ inputs.project-path }}/package.json

Edit: We're using private npm packages on github, so I don't think I can use static-checking since I can't provide a public file-url endpoint? Correct me if I'm wrong

Hello, just came across this issue too, using the workflow_run trigger.

The static-checking fix doesn't help, the error then becomes:

Static checking cannot be performed without a `file-url` argument.

I'm using all default options and no private packages.

Cheers

dmca-glasgow avatar Nov 14 '25 16:11 dmca-glasgow

Edit: We're using private npm packages on github, so I don't think I can use static-checking since I can't provide a public file-url endpoint? Correct me if I'm wrong

@guillaume-docquier-vention Sorry, just saw the edit. I think you should be able to use a GitHub Raw user content URL with an embedded token. I'm not 100% sure, but I remember seeing that somewhere

EndBug avatar Nov 15 '25 17:11 EndBug

@dmca-glasgow Yeah you have to set a file URL when using static-checking, see https://github.com/EndBug/version-check?tab=readme-ov-file#publishing-automatically-to-both-npm--github-package-registry

EndBug avatar Nov 15 '25 17:11 EndBug

@EndBug Thanks for your help.. I think I'm tying to use this package in a way that wasn't intended.. I just want to run actions if I have updated the version.. no NPM involved. I ended up writing my own solution and it works for my purposes. The main bits:

import { exec } from '@actions/exec';
import { readFile } from 'fs/promises';
import { context } from '@actions/github';

const { owner, repo } = context.repo;

const execOptions = {
  cwd: 'workspace',
  silent: true,
};

const url = `https://github.com/${owner}/${repo}.git`;

await exec('git', ['clone', url, '.'], execOptions);
const newVersion = await getVersion();

await exec('git', ['checkout', 'HEAD^'], execOptions);
const oldVersion = await getVersion();

if (newVersion !== oldVersion) {
  // changed
}

async function getVersion(): Promise<string> {
  const filePath = `${execOptions.cwd}/package.json`;
  const contents = await readFile(filePath, 'utf-8');
  return JSON.parse(contents).version;
}

Cheers.

dmca-glasgow avatar Nov 17 '25 10:11 dmca-glasgow