Skip to content

Commit

Permalink
Pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese committed Nov 28, 2023
1 parent 8616f88 commit a19365e
Showing 1 changed file with 38 additions and 37 deletions.
75 changes: 38 additions & 37 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
const core = require('@actions/core');
const github = require('@actions/github');
const core = require("@actions/core");
const github = require("@actions/github");

async function run() {
try {
//Get input
const tag = process.env.TAG || process.env.INPUT_TAG || "";
const repoInput = core.getInput("repo") || process.env.GITHUB_REPOSITORY;

console.log(`Searching for tag: ${tag} in ${repoInput}`);

if (!repoInput.includes("/")) {
throw new Error(`${repoInput} is not a valid repo`);
}

// Get owner and repo from context of payload that triggered the action
const [owner, ...repository] = repoInput.split("/");
const repo = repository.join("/");

const octokit = github.getOctokit(
process.env.GITHUB_TOKEN || core.getInput("github_token"),
);
var exists = "false";

try {
//Get input
const tag = process.env.TAG || process.env.INPUT_TAG || '';
const repoInput = core.getInput('repo') || process.env.GITHUB_REPOSITORY;

console.log(`Searching for tag: ${tag} in ${repoInput}`);

if (!repoInput.includes('/')) {
throw new Error(`${repoInput} is not a valid repo`);
}

// Get owner and repo from context of payload that triggered the action
const [ owner, ...repository ] = repoInput.split('/');
const repo = repository.join('/');

const octokit = github.getOctokit(process.env.GITHUB_TOKEN || core.getInput('github_token'));
var exists = 'false';

try {
const getRefResponse = await octokit.rest.git.getRef({
owner,
repo,
ref: `tags/${tag}`
});

if (getRefResponse.status === 200) {
console.log("Tag was found");
exists = 'true';
}

} catch(error) {
console.log("Tag was not found");
}

core.setOutput('exists', exists);
const getRefResponse = await octokit.rest.git.getRef({
owner,
repo,
ref: `tags/${tag}`,
});

if (getRefResponse.status === 200) {
console.log("Tag was found");
exists = "true";
}
} catch (error) {
core.setFailed(error.message);
console.log("Tag was not found");
}

core.setOutput("exists", exists);
} catch (error) {
core.setFailed(error.message);
}
}

run();

0 comments on commit a19365e

Please sign in to comment.