This commit is contained in:
Stephan 2022-03-18 15:47:17 +01:00
parent af2ea06031
commit c0b18d2f43
2 changed files with 20 additions and 71 deletions

15
.github/workflows/publish-release.js vendored Normal file
View File

@ -0,0 +1,15 @@
module.exports = async ({github, context, core}) => {
const restapi = github.rest
function firstOrDefault(items, predicate) {
for (const item of items) {
if (predicate(item)) {
return item
}
}
return null
}
console.log("script")
}

View File

@ -3,78 +3,12 @@ on: workflow_dispatch
jobs: jobs:
job: job:
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/heads/release/') if: startsWith(github.ref, 'refs/heads/release/') # 19 leading chars
steps: steps:
- name: Validate the release - name: Validate the release
uses: actions/github-script@v4 uses: actions/github-script@v5
with: with:
script: | script: |
const ver = "${{ github.ref }}".substring(19) const script = require('./.github/workflows/publish-release.js')
const tag = "v" + ver console.log(script)
try {
const rel = await github.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: tag
})
}
catch (error) {
core.setFailed(`Could not find a release for tag '${tag}'.`)
return
}
if (rel.draft) {
core.setFailed(`Release for tag '${tag}' is already published.`)
return
}
try {
const ref = await github.git.getRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'tags/' + tag
})
core.setFailed(`Tag '${tag}' already exists.`)
return
}
catch (error) {
// this is expected
}
// everything is OK
- name: Checkout
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure repository
shell: bash
run: |
git config user.email "github-actions@hazelcast.com"
git config user.name "GitHub Actions (Build Release)"
- name: Finalize the release
run: |
ref="${{ github.ref }}"
branch="${ref:11}" # trim starting 'refs/heads/' (11 chars)
version="${ref:19}" # trim starting 'refs/heads/release/' (19 chars)
echo "Tag branch $branch as v$version"
git tag v$version
git push --tags
#git push :$branch
- name: Publish the release
uses: actions/github-script@v4
with:
script: |
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,
release_id: rel.id,
draft: false
})