This commit is contained in:
Stephan 2022-03-18 16:56:06 +01:00
parent ac561c87a4
commit 13a337a9b8
2 changed files with 58 additions and 8 deletions

View File

@ -34,13 +34,24 @@ module.exports = /*async*/ ({github, context, core}) => {
return return
} }
// github milestone must exist and be open
const milestone = getMilestone()
if (milestone == null) {
core.setFailed(`Could not find milestone '${version}'.`)
return
}
if (milestone.state != "open") {
core.setFailed(`Milestone '${version}' is already closed.`)
return
}
// github release must exist and not be published yet // github release must exist and not be published yet
try { try {
const release = restapi.repos.getReleaseByTag({ const release = restapi.repos.getReleaseByTag({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
tag: tag tag: tag
}) })
if (release === null) { if (release === null) {
core.setFailed(`Could not find a GitHub release for tag '${tag}'.`) core.setFailed(`Could not find a GitHub release for tag '${tag}'.`)
return return
@ -73,12 +84,50 @@ module.exports = /*async*/ ({github, context, core}) => {
console.log(`Found branch 'release/${version}', a yet-unpublished GitHub Release for tag '${tag}' which does not exist yet.`) console.log(`Found branch 'release/${version}', a yet-unpublished GitHub Release for tag '${tag}' which does not exist yet.`)
} }
function test() { async function publishRelease() {
console.log('TEST')
const version = context.payload.inputs.version
const tag = "v" + version
console.log(`Publish GitHub release '${version}'.`)
const release = restapi.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: tag
})
await restapi.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.id,
draft: false
})
}
async function closeMilestone() {
const version = context.payload.inputs.version
const tag = "v" + version
console.log(`Close milestone '${version}'.`)
const milestone = await getMilestone()
//...
}
async function getMilestone() {
const version = context.payload.inputs.version
const milestonesResponse = await restapi.issues.listMilestones({
owner: context.repo.owner,
repo: context.repo.repo
})
const milestones = milestonesResponse.data
return firstOrDefault(milestones, (x) => x.title == version)
} }
return { return {
test: test, validateRelease: validateRelease,
validateRelease: validateRelease publishRelease: publishRelease,
closeMilestone: closeMilestone
} }
} }

View File

@ -28,6 +28,7 @@ jobs:
script: | script: |
const scriptf = require('./.github/workflows/publish-release.js') const scriptf = require('./.github/workflows/publish-release.js')
const script = scriptf({github, context, core}) const script = scriptf({github, context, core})
console.log(script) await script.validateRelease()
script.test() // rest should be in a different step
await script.validateRelease() // await script.publishRelease()
// await script.closeMilestone()