-
Notifications
You must be signed in to change notification settings - Fork 35
50 lines (45 loc) · 1.84 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
name: GitHub
on:
pull_request:
branches: [main]
#on:
# push:
# tags: ["*"]
jobs:
release:
permissions: write-all
runs-on: "ubuntu-latest"
name: Create a Release
steps:
- uses: actions/checkout@v4
- name: Extract the change log from CHANGES.(rst|md)
id: changelog
run: |
# get the lines where the changelog for the last release starts and finishes
first_line=$(grep -n "\-\-\-\-" CHANGES.rst | cut -d":" -f1 |head -n1)
last_line=$(grep -n "\-\-\-\-" CHANGES.rst | cut -d":" -f1 |head -n2 | tail -n1)
# do some math to adjust the line numbers
first=$((${first_line}+1))
last=$((${last_line}-2))
end=$((${last_line}-1))
# extract the changelog
output=$(sed -n "${first},${last}p;${end}q" CHANGES.rst)
# output="${output//'%'/'%25'}"
# output="${output//$'\n'/'%0A'}"
# output="${output//$'\r'/'%0D'}"
# output="${output//$"'"/"\'"}"
# GITHUB_OUTPUT needs a delimiter for multi line strings
delimiter="$(openssl rand -hex 8)"
echo "log<<${delimiter}" >> "${GITHUB_OUTPUT}"
echo "${output}" >> "${GITHUB_OUTPUT}"
echo "${delimiter}" >> "${GITHUB_OUTPUT}"
# - name: debug
# run: echo '{"tag_name":"${{ github.ref_name }}","name":"${{ github.ref_name }}","body":"${{ steps.changelog.outputs.log }}"}'
- name: Create a new GitHub release
run: |
curl -L \
-X POST \
--header "Accept: application/vnd.github+json" \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
https://api.github.com/repos/${{ github.repository }}/releases \
-d '{"tag_name":"${{ github.ref_name }}","name":"${{ github.ref_name }}","body":${{ toJson(steps.changelog.outputs.log) }}}'