-
-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const core = __importStar(require("@actions/core")); | ||
const semver_1 = require("semver"); | ||
const commit_analyzer_1 = require("@semantic-release/commit-analyzer"); | ||
const release_notes_generator_1 = require("@semantic-release/release-notes-generator"); | ||
const utils_1 = require("./utils"); | ||
function run() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const defaultBump = core.getInput("default_bump"); | ||
const tagPrefix = core.getInput("tag_prefix"); | ||
const customTag = core.getInput("custom_tag"); | ||
const releaseBranches = core.getInput("release_branches"); | ||
const preReleaseBranches = core.getInput("pre_release_branches"); | ||
const appendToPreReleaseTag = core.getInput("append_to_pre_release_tag"); | ||
const createAnnotatedTag = !!core.getInput("create_annotated_tag"); | ||
const dryRun = core.getInput("dry_run"); | ||
const { GITHUB_REF, GITHUB_SHA } = process.env; | ||
if (!GITHUB_REF) { | ||
core.setFailed("Missing GITHUB_REF."); | ||
return; | ||
} | ||
if (!GITHUB_SHA) { | ||
core.setFailed("Missing GITHUB_SHA."); | ||
return; | ||
} | ||
const currentBranch = utils_1.getBranchFromRef(GITHUB_REF); | ||
const isReleaseBranch = releaseBranches | ||
.split(",") | ||
.some((branch) => currentBranch.match(branch)); | ||
const isPreReleaseBranch = preReleaseBranches | ||
.split(",") | ||
.some((branch) => currentBranch.match(branch)); | ||
const isPrerelease = !isReleaseBranch && isPreReleaseBranch; | ||
const identifier = appendToPreReleaseTag ? appendToPreReleaseTag : currentBranch; | ||
const validTags = yield utils_1.getValidTags(); | ||
const latestTag = utils_1.getLatestTag(validTags); | ||
const latestPrereleaseTag = utils_1.getLatestPrereleaseTag(validTags, identifier); | ||
const commits = yield utils_1.getCommits(latestTag.commit.sha); | ||
let newVersion; | ||
if (customTag) { | ||
newVersion = customTag; | ||
} | ||
else { | ||
let previousTag; | ||
if (!latestPrereleaseTag) { | ||
previousTag = semver_1.parse(latestTag.name); | ||
} | ||
else { | ||
previousTag = semver_1.parse(semver_1.gte(latestTag.name, latestPrereleaseTag.name) | ||
? latestTag.name | ||
: latestPrereleaseTag.name); | ||
} | ||
if (!previousTag) { | ||
core.setFailed("Could not parse previous tag."); | ||
return; | ||
} | ||
core.info(`Previous tag was ${previousTag}.`); | ||
core.setOutput("previous_tag", previousTag.version); | ||
const bump = yield commit_analyzer_1.analyzeCommits({}, { commits, logger: { log: console.info.bind(console) } }); | ||
if (!bump && defaultBump === "false") { | ||
core.debug("No commit specifies the version bump. Skipping the tag creation."); | ||
return; | ||
} | ||
const releaseType = isPrerelease | ||
? "prerelease" | ||
: bump || defaultBump; | ||
const incrementedVersion = semver_1.inc(previousTag, releaseType, identifier); | ||
if (!incrementedVersion) { | ||
core.setFailed("Could not increment version."); | ||
return; | ||
} | ||
if (!semver_1.valid(incrementedVersion)) { | ||
core.setFailed(`${incrementedVersion} is not a valid semver.`); | ||
return; | ||
} | ||
newVersion = incrementedVersion; | ||
} | ||
core.info(`New version is ${newVersion}.`); | ||
core.setOutput("new_version", newVersion); | ||
const newTag = `${tagPrefix}${newVersion}`; | ||
core.info(`New tag after applying prefix is ${newTag}.`); | ||
core.setOutput("new_tag", newTag); | ||
const changelog = yield release_notes_generator_1.generateNotes({}, { | ||
commits, | ||
logger: { log: console.info.bind(console) }, | ||
options: { | ||
repositoryUrl: `https://github.com/${process.env.GITHUB_REPOSITORY}`, | ||
}, | ||
lastRelease: { gitTag: latestTag.name }, | ||
nextRelease: { gitTag: newTag, version: newVersion }, | ||
}); | ||
core.info(`Changelog is ${changelog}.`); | ||
core.setOutput("changelog", changelog); | ||
if (!isReleaseBranch && !isPreReleaseBranch) { | ||
core.info("This branch is neither a release nor a pre-release branch. Skipping the tag creation."); | ||
return; | ||
} | ||
if (validTags.map((tag) => tag.name).includes(newTag)) { | ||
core.info("This tag already exists. Skipping the tag creation."); | ||
return; | ||
} | ||
if (/true/i.test(dryRun)) { | ||
core.info("Dry run: not performing tag action."); | ||
return; | ||
} | ||
yield utils_1.createTag(newTag, createAnnotatedTag, GITHUB_SHA); | ||
} | ||
catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
}); | ||
} | ||
run(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getLatestPrereleaseTag = exports.getLatestTag = exports.createTag = exports.getBranchFromRef = exports.getCommits = exports.getValidTags = void 0; | ||
const core = __importStar(require("@actions/core")); | ||
const github_1 = require("@actions/github"); | ||
const semver_1 = require("semver"); | ||
const githubToken = core.getInput("github_token"); | ||
const octokit = new github_1.GitHub(githubToken); | ||
function getValidTags() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const tags = yield octokit.repos.listTags(Object.assign(Object.assign({}, github_1.context.repo), { per_page: 100 })); | ||
const invalidTags = tags.data | ||
.map((tag) => tag.name) | ||
.filter((name) => !semver_1.valid(name)); | ||
invalidTags.forEach((name) => core.debug(`Found Invalid Tag: ${name}.`)); | ||
const validTags = tags.data | ||
.filter((tag) => semver_1.valid(tag.name)) | ||
.sort((a, b) => semver_1.rcompare(a.name, b.name)); | ||
validTags.forEach((tag) => core.debug(`Found Valid Tag: ${tag.name}.`)); | ||
return validTags; | ||
}); | ||
} | ||
exports.getValidTags = getValidTags; | ||
function getCommits(sha) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const commits = yield octokit.repos.compareCommits(Object.assign(Object.assign({}, github_1.context.repo), { base: sha, head: "HEAD" })); | ||
return commits.data.commits | ||
.filter((commit) => !!commit.commit.message) | ||
.map((commit) => ({ | ||
message: commit.commit.message, | ||
hash: commit.sha, | ||
})); | ||
}); | ||
} | ||
exports.getCommits = getCommits; | ||
function getBranchFromRef(ref) { | ||
return ref.replace("refs/heads/", ""); | ||
} | ||
exports.getBranchFromRef = getBranchFromRef; | ||
function createTag(newTag, createAnnotatedTag, GITHUB_SHA) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let annotatedTag = undefined; | ||
if (createAnnotatedTag) { | ||
core.debug(`Creating annotated tag.`); | ||
annotatedTag = yield octokit.git.createTag(Object.assign(Object.assign({}, github_1.context.repo), { tag: newTag, message: newTag, object: GITHUB_SHA, type: "commit" })); | ||
} | ||
core.debug(`Pushing new tag to the repo.`); | ||
yield octokit.git.createRef(Object.assign(Object.assign({}, github_1.context.repo), { ref: `refs/tags/${newTag}`, sha: annotatedTag ? annotatedTag.data.sha : GITHUB_SHA })); | ||
}); | ||
} | ||
exports.createTag = createTag; | ||
function getLatestTag(tags) { | ||
return (tags.find((tag) => !semver_1.prerelease(tag.name)) || { | ||
name: "0.0.0", | ||
commit: { | ||
sha: "HEAD", | ||
}, | ||
}); | ||
} | ||
exports.getLatestTag = getLatestTag; | ||
function getLatestPrereleaseTag(tags, identifier) { | ||
return tags | ||
.filter((tag) => semver_1.prerelease(tag.name)) | ||
.find((tag) => tag.name.match(identifier)); | ||
} | ||
exports.getLatestPrereleaseTag = getLatestPrereleaseTag; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.