Skip to content

Commit

Permalink
added prerelease check
Browse files Browse the repository at this point in the history
  • Loading branch information
smac89 committed Apr 1, 2020
1 parent 30b4dc3 commit 396a049
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
31 changes: 31 additions & 0 deletions __tests__/action.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as core from '@actions/core';
import {context} from '@actions/github';
import {isPrelease} from '../src/action';

describe("publish_latest tests", () => {
test("not published when false", () => {
process.env.INPUT_PUBLISH_LATEST = 'false';
expect(core.getInput('publish_latest')).toBe('false')
});

test("published when true", () => {
process.env.INPUT_PUBLISH_LATEST = "true";
expect(core.getInput('publish_latest')).toBe('true')
});
});

describe("release tests", () => {
test("Will return true if Pre-release detected", () => {
context.payload = {action: 'published', release: {
"prerelease": true
}}
expect(isPrelease()).toBe(true);
});

test("Will return false if not Pre-release", () => {
context.payload = {action: 'published', release: {
"prerelease": false
}}
expect(isPrelease()).toBe(false);
});
});
13 changes: 0 additions & 13 deletions __tests__/main.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion lib/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,23 @@ import { TaggedRelease } from ".";
/**
* Checks if the event that triggered this action was a release
* See: https://developer.github.com/v3/activity/events/types/#releaseevent
*
* @returns {boolean}
*/
function isRelease(): boolean {
return context.payload.action === "published" && valid(context.payload.release?.tag_name) !== null;
}

/**
* Check if the event that triggered this actions was as a result
* of a prerelease or not
*
* @returns {boolean}
*/
export function isPrelease(): boolean {
return context.payload.action === "published" && context.payload.release?.prerelease === true;
}

/**
* Creates the tags required and optionally a 'latest' tag
*
Expand Down Expand Up @@ -79,6 +91,12 @@ async function run() {
return;
}

if (isPrelease()) {
core.info("Pre-release detected. Nothing to be done.");
core.info("See https://github.com/Actions-R-Us/actions-tagger/issues/23");
return;
}

if (process.env.GITHUB_TOKEN) {
const { tag, latest } = await createTagRefs();
core.setOutput("tag", tag);
Expand Down

0 comments on commit 396a049

Please sign in to comment.