-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgithub_edit_release_script.sh
executable file
·45 lines (37 loc) · 1.27 KB
/
github_edit_release_script.sh
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
#!/bin/bash
# ===> Set these variables first
branch="master"
repo_slug="$TRAVIS_REPO_SLUG"
token="$GH_CHANGELOG_RELEASE_KEY"
version="$TRAVIS_TAG"
release_id=$(curl -H "Authorization: token $token" "https://api.github.com/repos/$repo_slug/releases/latest" | jq '.id')
echo "Starting to edit release $release_id..."
# An automatic changelog generator
gem install github_changelog_generator
LAST_REVISION=$(git rev-list --tags --skip=1 --max-count=1)
LAST_RELEASE_TAG=$(git describe --abbrev=0 --tags ${LAST_REVISION})
# Generate CHANGELOG.md
github_changelog_generator \
-u $(cut -d "/" -f1 <<< ${repo_slug}) \
-p $(cut -d "/" -f2 <<< ${repo_slug}) \
--token ${token} \
--no-issues \
--since-tag ${LAST_RELEASE_TAG}
body="$(cat CHANGELOG.md)"
# Overwrite CHANGELOG.md with JSON data for GitHub API
jq -n \
--arg body "$body" \
--arg name "$version" \
--arg tag_name "$version" \
--arg target_commitish "$branch" \
'{
body: $body,
name: $name,
tag_name: $tag_name,
target_commitish: $target_commitish,
draft: false,
prerelease: false
}' > CHANGELOG.md
echo "Edit release $version for repo: $repo_slug, branch: $branch"
curl -H "Authorization: token $token" --data @CHANGELOG.md "https://api.github.com/repos/$repo_slug/releases/$release_id"
echo "Done"