-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pierregee
committed
Nov 9, 2023
1 parent
d7d5907
commit 52a5e7e
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Release Tags | ||
* | ||
* Creating release tag based on each release version for AWS ECR Public | ||
* | ||
*/ | ||
|
||
module.exports = ({ context }) => { | ||
if (context.eventName === "release") { | ||
return getReleaseTag(context); | ||
} | ||
if (isStaging(context) === true) { | ||
return getMainTag(context); | ||
} | ||
if (isDev(context) === true) { | ||
return getPullRequestTag(context); | ||
} | ||
throw new Error( | ||
"Release Violation: Could not determine the required release tags." | ||
); | ||
}; | ||
|
||
function getReleaseTag(context) { | ||
const semver = context.payload.release.tag_name; | ||
if (semver.match(/^v[0-9]+\.[0-9]+\.[0-9]+$/) === null) { | ||
throw new Error( | ||
`Release Violation: Provided version '${semver}' is not valid semver.` | ||
); | ||
} | ||
return semver.replace("v", ""); | ||
} | ||
|
||
function getMainTag({ sha }) { | ||
return `${sha}`; | ||
} | ||
|
||
function getPullRequestTag({ payload: { number }, sha }) { | ||
return `pr-${number}`; | ||
} | ||
|
||
function isStaging(context) { | ||
return context.eventName === "push" && context.ref === "refs/heads/main"; | ||
} | ||
|
||
function isDev(context) { | ||
return context.eventName === "pull_request"; | ||
} |