Last active
December 24, 2018 22:21
-
-
Save fennifith/664f534ead7336adf420d5afa72628f9 to your computer and use it in GitHub Desktop.
A script to create releases on github because Travis doesn't like newline chars in its release bodies.
This file contains 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 | |
# MIT License | |
# | |
# Copyright (c) 2018 James Fenn | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
# This is my script to create github releases. There are many like it, but this one is mine. | |
# | |
# Here are some other scripts with similar functionality, if you are curious: | |
# - https://gist.github.com/stefanbuck/ce788fee19ab6eb0b4447a85fc99f447 | |
# - https://gist.github.com/Jaskaranbir/d5b065173b3a6f164e47a542472168c1 | |
# | |
# The main purpose of this script is to publish multi-line release bodies from Travis CI. | |
# The reason that Travis's implementation cannot do this is explained in an issue here: | |
# https://github.com/travis-ci/dpl/issues/155 | |
# | |
# Since I already have to specify the changelog in a file inside the repo, there is no point | |
# in manually copying that to the release notes every time I make a release. | |
# | |
# Parameters: (these are environment variables that must be specified before the | |
# script is run) | |
# - GITHUB_TOKEN: An authenticated API token with access to the repo. | |
# - RELEASE_VERSION: The version name/number/tag of the release. | |
# - RELEASE_CHANGELOG: The changelog, could be assigned like "$(cat CHANGELOG.md)" | |
# - TRAVIS_BRANCH: The branch of the repository to create a release on. | |
# Automatically created by Travis. Should normally be "master". | |
# - TRAVIS_REPO_SLUG: The full name of the repository, formatted like "author/repo". | |
# Automatically created by Travis. | |
# formats data to pass to github api | |
data=$(jq -n \ | |
--arg body "$RELEASE_CHANGELOG" \ | |
--arg name "$RELEASE_VERSION" \ | |
--arg commitish "$TRAVIS_BRANCH" \ | |
'{ | |
body: $body, | |
name: $name, | |
tag_name: $name, | |
target_commitish: $commitish, | |
draft: false, | |
prerelease: false | |
}') | |
# creates the release... | |
curl -H "Authorization: token $GITHUB_TOKEN" \ | |
--data "$data" \ | |
"https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment