Skip to content

Instantly share code, notes, and snippets.

@whilei
Forked from Jaskaranbir/github_release_script.sh
Created January 6, 2019 19:29
Show Gist options
  • Save whilei/39ae1a63ae69de4d7fc9ba7bd686c290 to your computer and use it in GitHub Desktop.
Save whilei/39ae1a63ae69de4d7fc9ba7bd686c290 to your computer and use it in GitHub Desktop.

Revisions

  1. @Jaskaranbir Jaskaranbir revised this gist Sep 7, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion github_release_script.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    #!/bin/bash

    # ===> Set these variables first
    body="$(cat CHANGELOG.md)"
    branch="$GIT_BRANCH"
    # Example: "Jaskaranbir/MyRepo"
    repo_slug="$TRAVIS_REPO_SLUG"
    @@ -21,6 +20,8 @@ github_changelog_generator \
    --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" \
  2. @Jaskaranbir Jaskaranbir created this gist Sep 6, 2018.
    40 changes: 40 additions & 0 deletions github_release_script.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    #!/bin/bash

    # ===> Set these variables first
    body="$(cat CHANGELOG.md)"
    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}

    # 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"