Skip to content

Commit

Permalink
Rewrote to TS
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Simko committed Dec 1, 2022
1 parent 19ed3e8 commit 5c6b135
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,7 @@ typings/

# TernJS port file
.tern-port

node_modules/typescript
node_modules/.bin/tsc
node_modules/.bin/tsserver
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ inputs:

runs:
using: "node16"
main: "src/main.js"
main: "dist/main.js"
branding:
icon: "tag"
color: "green"
1 change: 1 addition & 0 deletions dist/main.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
56 changes: 56 additions & 0 deletions dist/main.js

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

1 change: 1 addition & 0 deletions dist/main.js.map

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

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
"repository": "git@github.com:richardsimko/github-tag-action.git",
"author": "Richard Simko <rick.simko@gmail.com>",
"license": "MIT",
"scripts": {
"build": "tsc"
},
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/github": "^5.0.0"
},
"devDependencies": {
"typescript": "4.9.3"
}
}
28 changes: 12 additions & 16 deletions src/main.js → src/main.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
const core = require('@actions/core');
const github = require('@actions/github');
import core from "@actions/core";
import github from "@actions/github";
const context = github.context;
async function run() {

try {
const { GITHUB_SHA, GITHUB_TOKEN } = process.env;
const tagName = core.getInput('tag_name');
const tagName = core.getInput("tag_name");
if (!GITHUB_SHA) {
core.setFailed('Missing GITHUB_SHA');
core.setFailed("Missing GITHUB_SHA");
return;
}

if (!GITHUB_TOKEN) {
core.setFailed('Missing GITHUB_TOKEN');
core.setFailed("Missing GITHUB_TOKEN");
return;
}

if (!tagName) {
core.setFailed('Missing tag_name');
core.setFailed("Missing tag_name");
return;
}


const octokit = github.getOctokit(GITHUB_TOKEN);
let ref;
try {

ref = await octokit.git.getRef({
ref = await octokit.rest.git.getRef({
...context.repo,
ref: `tags/${tagName}`
ref: `tags/${tagName}`,
});
} catch (e) {
if (e.status === 404) {
Expand All @@ -38,19 +35,18 @@ async function run() {
}
}
if (!ref) {
await octokit.git.createRef({
await octokit.rest.git.createRef({
...context.repo,
ref: `refs/tags/${tagName}`,
sha: GITHUB_SHA
sha: GITHUB_SHA,
});
} else {
await octokit.git.updateRef({
await octokit.rest.git.updateRef({
...context.repo,
ref: `tags/${tagName}`,
sha: GITHUB_SHA
sha: GITHUB_SHA,
});
}

} catch (error) {
core.setFailed(error.message);
}
Expand Down
28 changes: 28 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"allowUnusedLabels": false,
"allowUnreachableCode": false,
"alwaysStrict": true,
"noImplicitOverride": true,
"strictBindCallApply": true,
"strictFunctionTypes": true,
"module": "ESNext",
"moduleResolution": "node",
"declaration": true,
"target": "ES2022",
"allowJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"sourceMap": true,
"strictNullChecks": true,
"outDir": "dist"
},
"ts-node": {
"files": true,
"swc": true
},
"lib": ["ES2022"],
"include": ["**/*.ts"],
"exclude": ["node_modules", "dist/**/*.*"]
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ tunnel@^0.0.6:
resolved "https://registry.yarnpkg.com/tunnel/-/tunnel-0.0.6.tgz#72f1314b34a5b192db012324df2cc587ca47f92c"
integrity sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==

typescript@4.9.3:
version "4.9.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.3.tgz#3aea307c1746b8c384435d8ac36b8a2e580d85db"
integrity sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==

universal-user-agent@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/universal-user-agent/-/universal-user-agent-6.0.0.tgz#3381f8503b251c0d9cd21bc1de939ec9df5480ee"
Expand Down

0 comments on commit 5c6b135

Please sign in to comment.