-
Notifications
You must be signed in to change notification settings - Fork 1.7k
137 lines (121 loc) · 4.77 KB
/
source-release-draft.yml
File metadata and controls
137 lines (121 loc) · 4.77 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
name: Build Source Release Draft
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
build-source-release-draft:
if: ${{ github.repository == 'apache/casbin' && !contains(github.ref_name, '-') }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Compute release metadata
id: release
run: |
TAG_NAME="${GITHUB_REF_NAME}"
if ! [[ "${TAG_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Unsupported release tag: ${TAG_NAME}" >&2
exit 1
fi
VERSION="${TAG_NAME#v}"
BASENAME="casbin-${VERSION}-src"
PREVIOUS_TAG="$(
git tag --list 'v*' |
grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' |
sort -V |
awk -v current="${TAG_NAME}" '
$0 == current {
print previous
exit
}
{
previous = $0
}
'
)"
echo "tag=${TAG_NAME}" >> "${GITHUB_OUTPUT}"
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
echo "basename=${BASENAME}" >> "${GITHUB_OUTPUT}"
echo "previous_tag=${PREVIOUS_TAG}" >> "${GITHUB_OUTPUT}"
- name: Generate release notes
run: |
CURRENT_TAG="${{ steps.release.outputs.tag }}"
CURRENT_VERSION="${CURRENT_TAG#v}"
PREVIOUS_TAG="${{ steps.release.outputs.previous_tag }}"
RELEASE_DATE="$(date -u +%F)"
RANGE="${CURRENT_TAG}"
if [ -n "${PREVIOUS_TAG}" ]; then
RANGE="${PREVIOUS_TAG}..${CURRENT_TAG}"
fi
FEATURES="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(feat)(\(.+\))?: ' || true)"
FIXES="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(fix)(\(.+\))?: ' || true)"
DOCS="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(docs?|doc)(\(.+\))?: ' || true)"
{
if [ -n "${PREVIOUS_TAG}" ]; then
echo "# [${CURRENT_VERSION}](https://github.com/${GITHUB_REPOSITORY}/compare/${PREVIOUS_TAG}...${CURRENT_TAG}) (${RELEASE_DATE})"
else
echo "# ${CURRENT_VERSION} (${RELEASE_DATE})"
fi
echo
echo "This GitHub release is a draft helper for packaging and release notes."
echo
if [ -n "${FEATURES}" ]; then
echo "## Features"
echo
printf '%s\n' "${FEATURES}" | sed 's/^/- /'
echo
fi
if [ -n "${FIXES}" ]; then
echo "## Fixes"
echo
printf '%s\n' "${FIXES}" | sed 's/^/- /'
echo
fi
if [ -n "${DOCS}" ]; then
echo "## Docs"
echo
printf '%s\n' "${DOCS}" | sed 's/^/- /'
echo
fi
if [ -z "${FEATURES}${FIXES}${DOCS}" ]; then
echo "## Notes"
echo
echo "- No feat/fix/doc commits were found in this release range."
fi
} > RELEASE_NOTES.md
- name: Create source archives
run: |
mkdir -p dist
git archive --format=tar.gz --prefix="${{ steps.release.outputs.basename }}/" -o "dist/${{ steps.release.outputs.basename }}.tar.gz" "${{ steps.release.outputs.tag }}"
git archive --format=zip --prefix="${{ steps.release.outputs.basename }}/" -o "dist/${{ steps.release.outputs.basename }}.zip" "${{ steps.release.outputs.tag }}"
- name: Create draft GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.release.outputs.tag }}
name: Casbin ${{ steps.release.outputs.tag }}
body_path: RELEASE_NOTES.md
draft: true
files: |
dist/${{ steps.release.outputs.basename }}.tar.gz
dist/${{ steps.release.outputs.basename }}.zip