-
Notifications
You must be signed in to change notification settings - Fork 0
59 lines (49 loc) · 2.37 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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}"