-
-
Save whilei/39ae1a63ae69de4d7fc9ba7bd686c290 to your computer and use it in GitHub Desktop.
Shell script to create GitHub releases with automatically generated changelogs (using github-changelog-generator).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ===> Set these variables first | |
branch="$GIT_BRANCH" | |
# Example: "Jaskaranbir/MyRepo" | |
repo_slug="$TRAVIS_REPO_SLUG" | |
token="$GITHUB_TOKEN" | |
version="$TRAVIS_TAG" | |
# 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 \ | |
--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 "Create release $version for repo: $repo_slug, branch: $branch" | |
curl -H "Authorization: token $token" --data @CHANGELOG.md "https://api.github.com/repos/$repo_slug/releases" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment