Error: Cannot read properties of undefined (reading '_links')
Hello,
I used version_check in my GitHub action workflow, and encountered the problem below. Does anyone face the same problem ?
I found the source code _links here
https://github.com/EndBug/version-check/blob/main/src/main.ts#L124
Hmm, that's weird, with what event are you using the actions?
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
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!
Im getting this error too when using workflow_call to trigger my action
Hey @ljukas, as mentioned above,
The solution would be using the
static-checkinginput 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 I'm seeing the same error when running the workflow locally using act.
Any tips?
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
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
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
@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 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.