Skip to content

Commit

Permalink
Updates dependencies. (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
manovotny authored Nov 5, 2022
1 parent 00a1590 commit 7fab11d
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 231 deletions.
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const core = require('@actions/core');
const github = require('@actions/github');
const dotProp = require('dot-prop');
const fs = require('fs-extra');
const semver = require('semver');
const dedent = require('dedent');
Expand All @@ -10,14 +9,20 @@ const main = async () => {
const {draft: isDraft, prerelease: isPrerelease, tag_name: gitTag} = github.context.payload.release;
const gitTagWithoutV = gitTag.slice(1);
const packageJson = await fs.readJson('./package.json');
const packageJsonVersion = dotProp.get(packageJson, 'version', undefined);
const packageJsonVersion = packageJson?.version;

if (isDraft) {
core.setFailed('Release is a draft. Skip publish.');

return;
}

if (!packageJsonVersion) {
core.setFailed('Package.json is missing version.');

return;
}

if (!gitTag.startsWith('v')) {
core.setFailed('Release git tag does not start with `v`, ie. `v1.2.3`.');

Expand Down
14 changes: 14 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,22 @@ describe('index', () => {
expect(core.setFailed).toHaveBeenCalledWith('Release is a draft. Skip publish.');
});

test('should fail if package.json is missing version', async () => {
jest.spyOn(core, 'setFailed');
fs.readJSON.mockReturnValue({});
github.context = generateGitHubRelease({});

await action();

expect(core.setFailed).toHaveBeenCalledTimes(1);
expect(core.setFailed).toHaveBeenCalledWith('Package.json is missing version.');
});

test('should fail if release git tag does not start with a "v"', async () => {
jest.spyOn(core, 'setFailed');
fs.readJSON.mockReturnValue({
version: '1.2.3',
});
github.context = generateGitHubRelease({
gitTag: '1.2.3',
});
Expand Down
Loading

0 comments on commit 7fab11d

Please sign in to comment.