5 Commits

Author SHA1 Message Date
GitHub Actions
be3cb4b259 Foo 2021-12-10 18:02:09 +00:00
Stephan
788aa0d4b5 meh 2021-12-10 19:01:50 +01:00
Stephan
490cc0c703 muh 2021-12-10 18:58:57 +01:00
Stephan
cfd959c2e0 pii 2021-12-10 18:56:29 +01:00
Stephan
43287ec9cf exp 2021-12-10 18:56:12 +01:00
2 changed files with 25 additions and 85 deletions

View File

@@ -1,40 +0,0 @@
// see https://github.com/actions/github-script
// , core, glob, io, exec, require
module.exports = function (github, context) {
var module = {}
// this is *not* exported
function noop ( ) { }
// this *is* exported
module.getReleaseByTag = async function (tag_name) {
var rel = null
try {
// this does *not* return draft releases, so we have to list them
//rel = await github.repos.getReleaseByTag({ ... })
const rels = await github.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo
})
for (const r of rels.data) {
if (r.tag_name === tag_name) {
rel = r
break
}
}
}
catch (error) {
return null
}
return rel
}
module.getRefReleaseTag = function (ref) {
// test, must start with 'refs/heads/release/' 19 chars
return "v" + ref.substring(19)
}
return module;
}

View File

@@ -1,49 +1,25 @@
name: Publish
#meh
on:
workflow_dispatch:
inputs:
confirm:
description: "This is really going to release. Enter \'yolo\' to confirm that you really want to do it."
required: true
default: ""
name: Publish Release
on: workflow_dispatch
jobs:
job:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/heads/release/')
steps:
- name: Confirm
uses: actions/github-script@v4
with:
script: |
if ("${{ github.event.inputs.confirm }}" != "yolo") {
core.setFailed(`Not confirmed (confirm = '${{ github.event.inputs.confirm }}').`)
}
- name: Checkout
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Validate the release
uses: actions/github-script@v4
with:
# token needed to see draft releases when getting all releases
github-token: ${{ secrets.MY_GITHUB_TOKEN_TESTREPO }}
script: |
const hz = require("./.github/workflows/hz.js")(github, context)
const ref = "${{ github.ref }}"
const tag = hz.getRefReleaseTag(ref)
if (tag === null) {
core.setFailed(`Invalid reference ${ref} is not release/<version>.`)
return
const ver = "${{ github.ref }}".substring(19)
const tag = "v" + ver
var rel
try {
rel = await github.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: tag
})
}
var rel = await hz.getReleaseByTag(tag)
if (rel === null) {
catch (error) {
core.setFailed(`Could not find a release for tag ${tag}.`)
return
}
@@ -64,7 +40,12 @@ jobs:
// this is expected
}
// everything is OK
- name: Checkout
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure repository
shell: bash
run: |
@@ -85,14 +66,13 @@ jobs:
uses: actions/github-script@v4
with:
script: |
const hz = require("./.github/workflows/hz.js")(github, context)
const ref = "${{ github.ref }}"
const tag = hz.getRefReleaseTag(ref)
if (tag === null) {
core.setFailed(`Invalid reference ${ref} is not release/<version>.`)
return
}
var rel = await hz.getReleaseByTag(tag)
const ver = "${{ github.ref }}".substring(19)
const tag = "v" + ver
const rel = await github.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: tag
})
await github.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,