Skip to content

Commit

Permalink
Try to check for the release already
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatskaari committed Sep 30, 2021
1 parent 1e363b9 commit a41d3d5
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 42 deletions.
60 changes: 39 additions & 21 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8499,34 +8499,50 @@ const core = __nccwpck_require__(6964);
const github = __nccwpck_require__(8033);
const fs = __nccwpck_require__(5747)

try {
const octokit = github.getOctokit(process.env.GITHUB_TOKEN);
async function run() {
try {
const octokit = github.getOctokit(process.env.GITHUB_TOKEN);

// TODO(jpoole): validate this is a semver version
const version = fs.readFileSync("VERSION").toString().trim()
const changeLog = fs.readFileSync("ChangeLog").toString()
// TODO(jpoole): validate this is a semver version
const version = fs.readFileSync("VERSION").toString().trim()
const changeLog = fs.readFileSync("ChangeLog").toString()

const changes = findTagChangelogs(changeLog, version)
const changes = findTagChangelogs(changeLog, version)

if (changes === undefined || changes === "") {
core.setFailed("Couldn't find changes for v" + version);
}
if (changes === undefined || changes === "") {
core.setFailed("Couldn't find changes for v" + version);
}


const releaseUrl = await octokit.rest.repos.getReleaseByTag({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
tag: "v" + version,
})

if (releaseUrl !== undefined) {
core.info("Release already created. Nothing to do.")
}

octokit.rest.repos.createRelease({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
tag_name: "v"+version,
name: "v"+version,
body: changes,
prerelease: version.includes("beta") || version.includes("alpha") || version.includes("prerelease"),
target_commitish: github.context.sha,
}).catch(error => {
const url = await octokit.rest.repos.createRelease({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
tag_name: "v" + version,
name: "v" + version,
body: changes,
prerelease: version.includes("beta") || version.includes("alpha") || version.includes("prerelease"),
target_commitish: github.context.sha,
})

core.info(url)

} catch (error) {
core.setFailed(error.message);
})
} catch (error) {
core.setFailed(error.message);
}

}


function findTagChangelogs(changelog, tag) {
const versionString = "Version " + tag

Expand Down Expand Up @@ -8564,6 +8580,8 @@ function findTagChangelogs(changelog, tag) {
return logs.join("\n")
}

run()

exports.findTagChangelogs = findTagChangelogs
})();

Expand Down
60 changes: 39 additions & 21 deletions src/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,50 @@ const core = require('@actions/core');
const github = require('@actions/github');
const fs = require('fs')

try {
const octokit = github.getOctokit(process.env.GITHUB_TOKEN);
async function run() {
try {
const octokit = github.getOctokit(process.env.GITHUB_TOKEN);

// TODO(jpoole): validate this is a semver version
const version = fs.readFileSync("VERSION").toString().trim()
const changeLog = fs.readFileSync("ChangeLog").toString()
// TODO(jpoole): validate this is a semver version
const version = fs.readFileSync("VERSION").toString().trim()
const changeLog = fs.readFileSync("ChangeLog").toString()

const changes = findTagChangelogs(changeLog, version)
const changes = findTagChangelogs(changeLog, version)

if (changes === undefined || changes === "") {
core.setFailed("Couldn't find changes for v" + version);
}
if (changes === undefined || changes === "") {
core.setFailed("Couldn't find changes for v" + version);
}


const releaseUrl = await octokit.rest.repos.getReleaseByTag({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
tag: "v" + version,
})

if (releaseUrl !== undefined) {
core.info("Release already created. Nothing to do.")
}

octokit.rest.repos.createRelease({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
tag_name: "v"+version,
name: "v"+version,
body: changes,
prerelease: version.includes("beta") || version.includes("alpha") || version.includes("prerelease"),
target_commitish: github.context.sha,
}).catch(error => {
const url = await octokit.rest.repos.createRelease({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
tag_name: "v" + version,
name: "v" + version,
body: changes,
prerelease: version.includes("beta") || version.includes("alpha") || version.includes("prerelease"),
target_commitish: github.context.sha,
})

core.info(url)

} catch (error) {
core.setFailed(error.message);
})
} catch (error) {
core.setFailed(error.message);
}

}


function findTagChangelogs(changelog, tag) {
const versionString = "Version " + tag

Expand Down Expand Up @@ -67,4 +83,6 @@ function findTagChangelogs(changelog, tag) {
return logs.join("\n")
}

run()

exports.findTagChangelogs = findTagChangelogs

0 comments on commit a41d3d5

Please sign in to comment.