-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into vacuum_agg_index
- Loading branch information
Showing
6 changed files
with
222 additions
and
91 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 |
---|---|---|
@@ -1,77 +1,174 @@ | ||
module.exports = async ({ github, context, core }) => { | ||
const knownEvents = ["schedule", "workflow_dispatch", "release"]; | ||
const knownEvents = ["schedule", "workflow_dispatch"]; | ||
if (!knownEvents.includes(context.eventName)) { | ||
core.setFailed(`Triggerd by unknown event: ${context.eventName}`); | ||
return; | ||
} | ||
|
||
const { STABLE, TAG } = process.env; | ||
const { TYPE, TAG } = process.env; | ||
|
||
// trigger by release event | ||
if (context.ref.startsWith("refs/tags/")) { | ||
let tag = context.ref.replace("refs/tags/", ""); | ||
core.setOutput("tag", tag); | ||
core.setOutput("sha", context.sha); | ||
core.info(`Tag event triggered by ${tag}.`); | ||
return; | ||
} | ||
const RE_TAG_STABLE = /^v(\d+)\.(\d+)\.(\d+)$/g; | ||
const RE_TAG_NIGHTLY = /^v(\d+)\.(\d+)\.(\d+)-nightly$/g; | ||
const RE_TAG_PATCH = /^v(\d+)\.(\d+)\.(\d+)-p(\d+)$/g; | ||
|
||
switch (TYPE) { | ||
case "": | ||
case "nightly": { | ||
core.setOutput("sha", context.sha); | ||
core.info(`Nightly release triggered by ${TAG} (${context.sha})`); | ||
|
||
// trigger by schedule or workflow_dispatch event | ||
if (STABLE == "true") { | ||
if (TAG) { | ||
// trigger stable release by workflow_dispatch with a tag | ||
let result = /v(\d+)\.(\d+)\.(\d+)-nightly/g.exec(TAG); | ||
let previous = null; | ||
const releases = await github.rest.repos.listReleases({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
}); | ||
for (const release of releases.data) { | ||
const result = RE_TAG_NIGHTLY.exec(release.tag_name); | ||
if (result) { | ||
previous = release.tag_name; | ||
break; | ||
} | ||
} | ||
core.setOutput("previous", previous); | ||
core.info(`Nightly release with previous release: ${previous}`); | ||
|
||
if (TAG) { | ||
core.setOutput("tag", TAG); | ||
core.info(`Release create manually with tag ${TAG}`); | ||
return; | ||
} | ||
const result = RE_TAG_NIGHTLY.exec(previous); | ||
if (!result) { | ||
core.setFailed(`The tag ${TAG} to stablize is invalid, ignoring`); | ||
core.setFailed(`The previous tag ${previous} is invalid.`); | ||
return; | ||
} | ||
let major = result[1]; | ||
let minor = result[2]; | ||
let patch = result[3]; | ||
let stableTag = `v${major}.${minor}.${patch}`; | ||
core.setOutput("tag", stableTag); | ||
let ref = await github.rest.git.getRef({ | ||
const major = result[1]; | ||
const minor = result[2]; | ||
const patch = (parseInt(result[3]) + 1).toString(); | ||
const nextTag = `v${major}.${minor}.${patch}-nightly`; | ||
core.setOutput("tag", nextTag); | ||
core.info(`Release create new nightly ${nextTag}`); | ||
return; | ||
} | ||
|
||
case "stable": { | ||
core.setOutput("sha", context.sha); | ||
if (!TAG) { | ||
core.setFailed("Stable release must be triggered with a nightly tag"); | ||
return; | ||
} | ||
core.info(`Stable release triggered by ${TAG} (${context.sha})`); | ||
const result = RE_TAG_NIGHTLY.exec(TAG); | ||
if (!result) { | ||
core.setFailed(`The tag ${TAG} is invalid, ignoring`); | ||
return; | ||
} | ||
const major = result[1]; | ||
const minor = result[2]; | ||
const patch = result[3]; | ||
const nextTag = `v${major}.${minor}.${patch}`; | ||
core.setOutput("tag", nextTag); | ||
core.info(`Stable release ${nextTag} from ${TAG}`); | ||
|
||
let previous = null; | ||
let page = 1; | ||
while (true) { | ||
const releases = await github.rest.repos.listReleases({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
page, | ||
}); | ||
if (releases.data.length === 0) { | ||
break; | ||
} | ||
page++; | ||
for (const release of releases.data) { | ||
const ret = RE_TAG_STABLE.exec(release.tag_name); | ||
if (ret) { | ||
previous = release.tag_name; | ||
break; | ||
} | ||
} | ||
} | ||
if (!previous) { | ||
core.setFailed(`No previous stable release found, ignoring`); | ||
return; | ||
} | ||
core.setOutput("previous", previous); | ||
core.info(`Stable release with previous release: ${previous}`); | ||
} | ||
|
||
case "patch": { | ||
if (!TAG) { | ||
core.setFailed("Patch release must be triggered with a stable tag"); | ||
return; | ||
} | ||
core.info(`Patch release triggered by ${TAG}`); | ||
const result = RE_TAG_STABLE.exec(TAG); | ||
if (!result) { | ||
core.setFailed(`The tag ${TAG} is invalid, ignoring`); | ||
return; | ||
} | ||
|
||
const branch = await github.rest.repos.getBranch({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
ref: `tags/${TAG}`, | ||
branch: `backport/${TAG}`, | ||
}); | ||
core.setOutput("sha", ref.data.object.sha); | ||
core.setOutput("sha", branch.data.commit.sha); | ||
core.info( | ||
`Stable release ${stableTag} from ${TAG} (${ref.data.object.sha})` | ||
`Patch release triggered by ${TAG} (${branch.data.commit.sha})` | ||
); | ||
} else { | ||
core.setFailed("Stable release must be triggered with a nightly tag"); | ||
} | ||
} else { | ||
core.setOutput("sha", context.sha); | ||
if (TAG) { | ||
core.setOutput("tag", TAG); | ||
core.info(`Release create manually with tag ${TAG} (${context.sha})`); | ||
} else { | ||
let releases = await github.rest.repos.listReleases({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
per_page: 10, | ||
}); | ||
let tag = releases.data.filter( | ||
(r) => r.tag_name.startsWith("v") && r.tag_name.endsWith("-nightly") | ||
)[0]; | ||
if (!tag) { | ||
core.setFailed(`No previous nightly release found, ignoring`); | ||
return; | ||
|
||
let pv = 1; | ||
let previous = null; | ||
let page = 1; | ||
while (true) { | ||
const releases = await github.rest.repos.listReleases({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
page, | ||
}); | ||
if (releases.data.length === 0) { | ||
break; | ||
} | ||
page++; | ||
for (const release of releases.data) { | ||
if (!release.tag_name.startsWith(TAG)) { | ||
continue; | ||
} | ||
if (release.tag_name === TAG) { | ||
previous = release.tag_name; | ||
break; | ||
} | ||
const ret = RE_TAG_PATCH.exec(release.tag_name); | ||
if (!ret) { | ||
core.warning(`Ignore previous release ${release.tag_name}`); | ||
continue; | ||
} | ||
pv = parseInt(result[4]) + 1; | ||
previous = release.tag_name; | ||
} | ||
} | ||
let lastTag = tag.tag_name; | ||
let result = /v(\d+)\.(\d+)\.(\d+)/g.exec(lastTag); | ||
if (!result) { | ||
core.setFailed(`The previous tag ${lastTag} is invalid, ignoring`); | ||
if (!previous) { | ||
core.setFailed(`No previous stable release found, ignoring`); | ||
return; | ||
} | ||
let major = result[1]; | ||
let minor = result[2]; | ||
let patch = (parseInt(result[3]) + 1).toString(); | ||
let nextTag = `v${major}.${minor}.${patch}-nightly`; | ||
core.setOutput("previous", previous); | ||
core.info(`Patch release with previous release: ${previous}`); | ||
|
||
const major = result[1]; | ||
const minor = result[2]; | ||
const patch = result[3]; | ||
const nextTag = `v${major}.${minor}.${patch}-p${pv}`; | ||
core.setOutput("tag", nextTag); | ||
core.info(`Nightly release ${nextTag} from ${lastTag} (${context.sha})`); | ||
core.info(`Patch release ${nextTag} from ${TAG}`); | ||
return; | ||
} | ||
|
||
default: { | ||
core.setFailed(`Unknown release type: ${TYPE}`); | ||
return; | ||
} | ||
} | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.