Skip to content
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

Upgrading deps and node to 20 #6

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions __tests__/getInputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getInputs } from "../src/getInputs";
const MANDATORY_INPUTS = {
GITHUB_REPOSITORY: "foo/bar",
GITHUB_REF: "refs/tags/1.2.5",
GITHUB_SHA: "79bafdf08707fbc63c74ff5df5eed1ee15157d64",
GITHUB_SHA: "79bafdf08707fbc63c74ff5df5eed1ee15157d64"
};

it("should extract defaults from env vars", function() {
Expand All @@ -13,21 +13,28 @@ it("should extract defaults from env vars", function() {
expect(inputs).toHaveProperty("owner", "foo");
expect(inputs).toHaveProperty("repo", "bar");
expect(inputs).toHaveProperty("tag_name", "1.2.5");
expect(inputs).toHaveProperty("target_commitish", "79bafdf08707fbc63c74ff5df5eed1ee15157d64");
expect(inputs).toHaveProperty(
"target_commitish",
"79bafdf08707fbc63c74ff5df5eed1ee15157d64"
);
});

it("should require tag_name to be set if GITHUB_REF is missing", function() {
expect(() => morph(getInputs, {
...MANDATORY_INPUTS,
GITHUB_REF: "refs/heads/dev"
})).toThrowError("Input required and not supplied: tag_name")
expect(() =>
morph(getInputs, {
...MANDATORY_INPUTS,
GITHUB_REF: "refs/heads/dev"
})
).toThrowError("Input required and not supplied: tag_name");
});

it("should require tag_name to be set if GITHUB_REF is not a tag", function() {
expect(() => morph(getInputs, {
GITHUB_REPOSITORY: "foo/bar",
GITHUB_SHA: "79bafdf08707fbc63c74ff5df5eed1ee15157d64",
})).toThrowError("Input required and not supplied: tag_name")
expect(() =>
morph(getInputs, {
GITHUB_REPOSITORY: "foo/bar",
GITHUB_SHA: "79bafdf08707fbc63c74ff5df5eed1ee15157d64"
})
).toThrowError("Input required and not supplied: tag_name");
});

it('should parse "false" for prerelease as false', function() {
Expand Down Expand Up @@ -63,5 +70,8 @@ it("should allow to override target_commitish", function() {
INPUT_TARGET_COMMITISH: "9d9db5e79961731f4e1dfcbe758340e1aa6edb0e"
});

expect(inputs).toHaveProperty("target_commitish", "9d9db5e79961731f4e1dfcbe758340e1aa6edb0e");
expect(inputs).toHaveProperty(
"target_commitish",
"9d9db5e79961731f4e1dfcbe758340e1aa6edb0e"
);
});
30 changes: 15 additions & 15 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
name: 'Just Create A Release'
description: 'Creates releases on Github.'
author: 'Thomas Eizinger'
name: "Just Create A Release"
description: "Creates releases on Github."
author: "Thomas Eizinger"
branding:
icon: star
color: white
inputs:
github_token:
description: 'A GitHub API token'
description: "A GitHub API token"
required: true
tag_name:
description: 'The name of the tag for this release. If GITHUB_REF points to a tag (i.e. you are running this action in the context of a tag being pushed), this tag is going to be used. If not, this input is required.'
description: "The name of the tag for this release. If GITHUB_REF points to a tag (i.e. you are running this action in the context of a tag being pushed), this tag is going to be used. If not, this input is required."
required: false
target_commitish:
description: "The commit this release should point to. Defaults to GITHUB_SHA."
required: false
prerelease:
description: 'Whether this release is a prerelease.'
description: "Whether this release is a prerelease."
required: false
draft:
description: 'Whether this should be a draft release.'
description: "Whether this should be a draft release."
required: false
body:
description: 'The body of the release.'
description: "The body of the release."
required: false
name:
description: 'The name of the release.'
description: "The name of the release."
required: false
outputs:
id:
description: 'The ID of the created release.'
description: "The ID of the created release."
url:
description: 'The API url to the created release.'
description: "The API url to the created release."
html_url:
description: 'The URL a user can use to view the created release in a web browser.'
description: "The URL a user can use to view the created release in a web browser."
upload_url:
description: 'The URL for uploading assets to the created release.'
description: "The URL for uploading assets to the created release."
runs:
using: 'node12'
main: 'dist/index.js'
using: "node20"
main: "dist/index.js"
31 changes: 2 additions & 29 deletions dist/index.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions dist/index.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*!
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/

/*! formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */

/*! ws. MIT License. Einar Otto Stangvik <einaros@gmail.com> */
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@
"author": "Thomas Eizinger",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.0",
"@actions/core": "^1.10.1",
"@octokit/action": "^1.3.0"
},
"devDependencies": {
"@types/jest": "^24.0.23",
"@types/node": "^12.7.12",
"eslint": "^5.16.0",
"eslint-plugin-github": "^2.0.0",
"eslint-plugin-jest": "^22.21.0",
"jest": "^24.9.0",
"jest-circus": "^25.1.0",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.10",
"eslint": "^9.6.0",
"eslint-plugin-github": "^5.0.1",
"eslint-plugin-jest": "^28.6.0",
"jest": "^29.7.0",
"jest-circus": "^29.7.0",
"mock-env": "^0.2.0",
"prettier": "^1.19.1",
"ts-jest": "^24.2.0",
"ts-loader": "^6.2.1",
"typescript": "^3.7.3",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10"
"prettier": "^3.3.2",
"ts-jest": "^29.2.1",
"ts-loader": "^9.5.1",
"typescript": "^5.5.3",
"webpack": "^5.92.1",
"webpack-cli": "^5.1.4"
}
}
24 changes: 13 additions & 11 deletions src/getInputs.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { getInput } from "@actions/core/lib/core";
import {ReposCreateReleaseParams} from '@octokit/plugin-rest-endpoint-methods/dist-types/generated/rest-endpoint-methods-types'
import { ReposCreateReleaseParams } from "@octokit/plugin-rest-endpoint-methods/dist-types/generated/rest-endpoint-methods-types";

type Inputs = ReposCreateReleaseParams;

export function getInputs(): Inputs {
const draft = getInput("draft") ? JSON.parse(getInput("draft")) : undefined;
const prerelease = getInput("prerelease") ? JSON.parse(getInput("prerelease")) : undefined;
const prerelease = getInput("prerelease")
? JSON.parse(getInput("prerelease"))
: undefined;
const body = getInput("body") || undefined;
const name = getInput("name") || undefined;

Expand All @@ -15,7 +17,7 @@ export function getInputs(): Inputs {
throw new Error("GITHUB_REPOSITORY is not set");
}

const targetCommitish = determineTargetCommitish()
const targetCommitish = determineTargetCommitish();
const tagName = determineTagName();

const [owner, repo] = githubRepository.split("/");
Expand All @@ -33,32 +35,32 @@ export function getInputs(): Inputs {
}

function determineTargetCommitish() {
const currentCommit = process.env.GITHUB_SHA
const currentCommit = process.env.GITHUB_SHA;

if (!currentCommit) {
throw new Error("GITHUB_SHA not set. What is this environment?")
throw new Error("GITHUB_SHA not set. What is this environment?");
}

const targetCommitishInput = getInput('target_commitish')
const targetCommitishInput = getInput("target_commitish");

if (targetCommitishInput) {
return targetCommitishInput
return targetCommitishInput;
} else {
return currentCommit
return currentCommit;
}
}

function determineTagName(): string {
const currentRef = process.env.GITHUB_REF;

if (!currentRef) {
return getInput("tag_name", {required: true})
return getInput("tag_name", { required: true });
}

const isTag = currentRef.startsWith("refs/tags")
const isTag = currentRef.startsWith("refs/tags");

if (!isTag) {
return getInput("tag_name", {required: true})
return getInput("tag_name", { required: true });
}

return currentRef.replace("refs/tags/", "");
Expand Down
18 changes: 9 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import {setFailed, setOutput} from '@actions/core'
import {Octokit} from '@octokit/action'
import {getInputs} from './getInputs'
import { setFailed, setOutput } from "@actions/core";
import { Octokit } from "@octokit/action";
import { getInputs } from "./getInputs";

async function run(): Promise<void> {
try {
const releaseParams = getInputs();

const octokit = new Octokit();
const response = await octokit.repos.createRelease(releaseParams)
const response = await octokit.repos.createRelease(releaseParams);

const {
data: { id: releaseId, html_url: htmlUrl, upload_url: uploadUrl, url }
} = response;

setOutput('id', releaseId.toString());
setOutput('url', url);
setOutput('html_url', htmlUrl);
setOutput('upload_url', uploadUrl);
setOutput("id", releaseId.toString());
setOutput("url", url);
setOutput("html_url", htmlUrl);
setOutput("upload_url", uploadUrl);
} catch (error) {
setFailed(error.message);
setFailed((error as any).message);
}
}

Expand Down
Loading