Skip to content

Commit

Permalink
Merge pull request #11 from amitsingh-007/b-fix-no-release-yet
Browse files Browse the repository at this point in the history
  • Loading branch information
amitsingh-007 authored Oct 2, 2022
2 parents f88b0c8 + 06a13c8 commit de6e796
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions src/fetchLatestReleaseTag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { getInput } from "@actions/core";
import { getOctokit, context } from "@actions/github";

const fetchLatestReleaseTag = async () => {
try {
const github_token = getInput("github_token");
const octokit = getOctokit(github_token);
const { owner, repo } = context.repo;
const response = await octokit.rest.repos.getLatestRelease({
owner,
repo,
});
return response.data.tag_name;
} catch (error) {
// No releases yet
if (error.response.status === 404) {
return null;
}
throw error;
}
};

export default fetchLatestReleaseTag;
13 changes: 3 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import { getInput, exportVariable, setFailed } from "@actions/core";
import { getOctokit, context } from "@actions/github";
import { exportVariable, setFailed } from "@actions/core";
import fetchLatestReleaseTag from "./fetchLatestReleaseTag";
import getNewReleaseTag from "./getReleaseTag";

const generateNextReleaseTag = async () => {
try {
const github_token = getInput("github_token");
const octokit = getOctokit(github_token);
const { owner, repo } = context.repo;
const response = await octokit.rest.repos.getLatestRelease({
owner,
repo,
});
const { tag_name: oldReleaseTag } = response.data;
const oldReleaseTag = await fetchLatestReleaseTag();
const newReleaseTag = getNewReleaseTag(oldReleaseTag);
console.log(`Previous Release Tag: ${oldReleaseTag}`);
console.log(`New Release Tag: ${newReleaseTag}`);
Expand Down

0 comments on commit de6e796

Please sign in to comment.