Skip to content

Commit

Permalink
feat: add skipInvalidTags option
Browse files Browse the repository at this point in the history
  • Loading branch information
NGPixel committed Nov 16, 2022
1 parent 308beb2 commit 4eb6fb4
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 126 deletions.
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ inputs:
patchAll:
description: If set to true, will ignore patchList and count any commit as a Patch
required: false
default: false
default: 'false'
skipInvalidTags:
description: If set to true, will skip tags that are not valid semver until it finds a proper one (up to 10 from latest).
required: false
default: 'false'
outputs:
current:
description: Current version number
Expand Down
22 changes: 19 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31049,6 +31049,7 @@ async function main () {
const gh = github.getOctokit(token)
const owner = github.context.repo.owner
const repo = github.context.repo.repo
const skipInvalidTags = core.getBooleanInput('skipInvalidTags')

const bumpTypes = {
major: core.getInput('majorList').split(',').map(p => p.trim()).filter(p => p),
Expand All @@ -31062,7 +31063,7 @@ async function main () {
const tagsRaw = await gh.graphql(`
query lastTags ($owner: String!, $repo: String!) {
repository (owner: $owner, name: $repo) {
refs(first: 1, refPrefix: "refs/tags/", orderBy: { field: TAG_COMMIT_DATE, direction: DESC }) {
refs(first: 10, refPrefix: "refs/tags/", orderBy: { field: TAG_COMMIT_DATE, direction: DESC }) {
nodes {
name
target {
Expand All @@ -31077,10 +31078,25 @@ async function main () {
repo
})

const latestTag = _.get(tagsRaw, 'repository.refs.nodes[0]')
const tagsList = _.get(tagsRaw, 'repository.refs.nodes', [])
if (tagsList.length < 1) {
return core.setFailed('Couldn\'t find the latest tag. Make sure you have at least one tag created first!')
}

let latestTag = null
let idx = 0
for (const tag of tagsList) {
if (semver.valid(tag.name)) {
latestTag = tag
break
} else if (idx === 0 && !skipInvalidTags) {
break
}
idx++
}

if (!latestTag) {
return core.setFailed('Couldn\'t find the latest tag. Make sure you have at least one tag created first.')
return core.setFailed(skipInvalidTags ? 'None of the 10 latest tags are valid semver!' : 'Latest tag is invalid (does not conform to semver)!')
}

core.info(`Comparing against latest tag: ${latestTag.name}`)
Expand Down
22 changes: 19 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ async function main () {
const gh = github.getOctokit(token)
const owner = github.context.repo.owner
const repo = github.context.repo.repo
const skipInvalidTags = core.getBooleanInput('skipInvalidTags')

const bumpTypes = {
major: core.getInput('majorList').split(',').map(p => p.trim()).filter(p => p),
Expand All @@ -23,7 +24,7 @@ async function main () {
const tagsRaw = await gh.graphql(`
query lastTags ($owner: String!, $repo: String!) {
repository (owner: $owner, name: $repo) {
refs(first: 1, refPrefix: "refs/tags/", orderBy: { field: TAG_COMMIT_DATE, direction: DESC }) {
refs(first: 10, refPrefix: "refs/tags/", orderBy: { field: TAG_COMMIT_DATE, direction: DESC }) {
nodes {
name
target {
Expand All @@ -38,10 +39,25 @@ async function main () {
repo
})

const latestTag = _.get(tagsRaw, 'repository.refs.nodes[0]')
const tagsList = _.get(tagsRaw, 'repository.refs.nodes', [])
if (tagsList.length < 1) {
return core.setFailed('Couldn\'t find the latest tag. Make sure you have at least one tag created first!')
}

let latestTag = null
let idx = 0
for (const tag of tagsList) {
if (semver.valid(tag.name)) {
latestTag = tag
break
} else if (idx === 0 && !skipInvalidTags) {
break
}
idx++
}

if (!latestTag) {
return core.setFailed('Couldn\'t find the latest tag. Make sure you have at least one tag created first.')
return core.setFailed(skipInvalidTags ? 'None of the 10 latest tags are valid semver!' : 'Latest tag is invalid (does not conform to semver)!')
}

core.info(`Comparing against latest tag: ${latestTag.name}`)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
},
"devDependencies": {
"@vercel/ncc": "0.34.0",
"eslint": "8.25.0",
"eslint": "8.27.0",
"eslint-config-standard": "17.0.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "6.1.0"
"eslint-plugin-promise": "6.1.1"
}
}
Loading

0 comments on commit 4eb6fb4

Please sign in to comment.