Skip to content

release-command

release-command #778

# trigger by chatops '/release' or '/release bump=minor' or '/release tag=v1.2.3'
#
# By default, the latest release is retrieved, it's tag parsed as a semantic version
# and the patch number is increased by 1 (latest v2.2.2 -> v2.2.3).
# If there's no latest release, version will default to v1.0.0 (only if no other args specified).
#
# 'bump' and 'tag' are exclusive (one or the other).
#
# 'bump' can be either 'minor' or 'major' and specifies which part should be increased:
# - minor: latest v2.2.2 -> v2.3.0
# - major: latest v2.2.2 -> v3.0.0
#
# 'tag' specifies release tag manually.
#
# 'target' optionally specifies 'target_commitish' (branch or commit SHA) for tag creation;
# - if not specified, default branch is used by GitHub
# - see https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#create-a-release
name: Release command
on:
repository_dispatch:
types: [release-command]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Link to this workflow in command comment
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ secrets.BSDATA_BOT_TOKEN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
<!-- Command output -->
---
[Workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
- name: Checkout script
uses: actions/checkout@v3
with:
repository: BSData/process-release-command
path: script
ref: master
- name: Calculate new version, title, description
uses: Amadevus/pwsh-script@v2
id: get_values
with:
script: |
$cp = $github.event.client_payload
$args = @{
Repository = $cp.github.payload.repository.full_name
Bump = $cp.slash_command.args.named.bump
NextTag = $cp.slash_command.args.named.tag
CommentBody = $cp.github.payload.comment.body
}
return ./script/ConvertFrom-ReleaseCommand @args
- name: Create a release
uses: actions/github-script@v6
id: create_release
env:
RELEASE_INFO: ${{ steps.get_values.outputs.result }}
with:
github-token: ${{ secrets.BSDATA_BOT_TOKEN }}
script: |
const rel = JSON.parse(process.env.RELEASE_INFO)
const targetCommitish = context.payload.client_payload.slash_command.args.named.target
const [owner, repo] = context.payload.client_payload.github.payload.repository.full_name.split('/')
const { data: release } = await github.rest.repos.createRelease({
owner,
repo,
tag_name: rel.tag,
target_commitish: targetCommitish ? targetCommitish : undefined,
name: rel.name,
body: rel.body
})
core.setOutput('tag_name', release.tag_name)
core.setOutput('name', release.name)
core.setOutput('html_url', release.html_url)
- name: Add reaction to command comment on success
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ secrets.BSDATA_BOT_TOKEN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
Created release:
[${{ steps.create_release.outputs.tag_name }}](${{ steps.create_release.outputs.html_url }})
**${{ steps.create_release.outputs.name }}**
reactions: hooray
- name: Add reaction to command comment on failure
uses: peter-evans/create-or-update-comment@v2
if: failure()
with:
token: ${{ secrets.BSDATA_BOT_TOKEN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: "**Error**: ${{ steps.get_values.outputs.error || 'failed to create the release.' }}"
reactions: "-1"