Skip to content

create-draft-release #83

create-draft-release

create-draft-release #83

Workflow file for this run

on: create
name: create-draft-release
env:
# adapted from <https://gist.github.com/rverst/1f0b97da3cbeb7d93f4986df6e8e5695#file-check_semver-sh-L5>
TAG_RE: '^(.+)-v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$'
PARSE_CHANGELOG_URL: "https://github.com/taiki-e/parse-changelog/releases/download/v0.4.5/parse-changelog-x86_64-unknown-linux-gnu.tar.gz"
jobs:
release:
if: ${{ github.ref_type == 'tag' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Parse version
id: version
# adapted from
# <https://github.com/taiki-e/create-gh-release-action/blob/3d89f8d1ab8d63913861d1a4ec424395f1a60e67/main.sh#L28>
run: |
tag=$(echo "${{ github.ref }}" | rev | cut -d '/' -f 1 | rev)
if [[ ! "${tag}" =~ $TAG_RE ]]; then
echo "invalid tag format: '${tag}'"
exit 1
fi
package="${BASH_REMATCH[1]}"
prerelease="${BASH_REMATCH[5]}"
echo ::set-output name=package::$package
echo ::set-output name=version::${tag#"${package}-"}
echo ::set-output name=prerelease::false
echo ::set-output name=raw::$tag
if [[ ${#prerelease} -ne 0 ]]; then
echo ::set-output name=prerelease::true
fi
- name: Create draft release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# TODO see about using Docker image instead of downloading parse-changelog at runtime
# code adapted from <https://github.com/taiki-e/create-gh-release-action/blob/3d89f8d1ab8d63913861d1a4ec424395f1a60e67/main.sh#L84>
run: |
package="${{ steps.version.outputs.package }}"
version="${{ steps.version.outputs.version }}"
curl -LsSf "$PARSE_CHANGELOG_URL" | tar xzf -
notes=$(./parse-changelog packages/${package}/CHANGELOG.md "${version#v}")
tag="${{ steps.version.outputs.raw }}"
if gh release view "${tag}" &>/dev/null; then
gh release delete "${tag}" -y
fi
if ${{ steps.version.outputs.prerelease }}; then
prerelease="--prerelease"
fi
gh release create "${tag}" $prerelease --draft --title "${package} ${version}" --notes "${notes}"