"Fossies" - the Fresh Open Source Software Archive

Member "ponyc-0.33.2/.ci-scripts/release.bash" (3 Feb 2020, 3673 Bytes) of package /linux/misc/ponyc-0.33.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "release.bash": 0.33.1_vs_0.33.2.

    1 #!/bin/bash
    2 
    3 set -o errexit
    4 
    5 # Verify ENV is set up correctly
    6 # We validate all that need to be set in case, in an absolute emergency,
    7 # we need to run this by hand. Otherwise the GitHub actions environment should
    8 # provide all of these if properly configured
    9 if [[ -z "${RELEASE_TOKEN}" ]]; then
   10   echo -e "\e[31mA personal access token needs to be set in RELEASE_TOKEN."
   11   echo -e "\e[31mIt should not be secrets.GITHUB_TOKEN. It has to be a"
   12   echo -e "\e[31mpersonal access token otherwise next steps in the release"
   13   echo -e "\e[31mprocess WILL NOT trigger."
   14   echo -e "\e[31mPersonal access tokens are in the form:"
   15   echo -e "\e[31m     TOKEN"
   16   echo -e "\e[31mfor example:"
   17   echo -e "\e[31m     1234567890"
   18   echo -e "\e[31mExiting.\e[0m"
   19   exit 1
   20 fi
   21 
   22 if [[ -z "${GITHUB_REF}" ]]; then
   23   echo -e "\e[31mThe release tag needs to be set in GITHUB_REF."
   24   echo -e "\e[31mThe tag should be in the following GitHub specific form:"
   25   echo -e "\e[31m    /refs/tags/release-X.Y.Z"
   26   echo -e "\e[31mwhere X.Y.Z is the version we are releasing"
   27   echo -e "\e[31mExiting.\e[0m"
   28   exit 1
   29 fi
   30 
   31 if [[ -z "${GITHUB_REPOSITORY}" ]]; then
   32   echo -e "\e[31mName of this repository needs to be set in GITHUB_REPOSITORY."
   33   echo -e "\e[31mShould be in the form OWNER/REPO, for example:"
   34   echo -e "\e[31m     ponylang/ponyup"
   35   echo -e "\e[31mExiting.\e[0m"
   36   exit 1
   37 fi
   38 
   39 # no unset variables allowed from here on out
   40 # allow above so we can display nice error messages for expected unset variables
   41 set -o nounset
   42 
   43 # Set up GitHub credentials
   44 git config --global user.name 'Ponylang Main Bot'
   45 git config --global user.email 'ponylang.main@gmail.com'
   46 git config --global push.default simple
   47 
   48 PUSH_TO="https://${RELEASE_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
   49 
   50 # Extract version from tag reference
   51 # Tag ref version: "refs/tags/release-1.0.0"
   52 # Version: "1.0.0"
   53 VERSION="${GITHUB_REF/refs\/tags\/release-/}"
   54 
   55 # create release prep branch
   56 echo "Creating release prep"
   57 git checkout -b "prep-release-${VERSION}"
   58 
   59 # update VERSION
   60 echo "${VERSION}" > VERSION
   61 echo "VERSION set to ${VERSION}"
   62 
   63 # version the changelog
   64 changelog-tool release "${VERSION}" -e
   65 
   66 # commit CHANGELOG and VERSION updates
   67 git add CHANGELOG.md VERSION
   68 git commit -m "${VERSION} release"
   69 
   70 # merge into release
   71 git checkout release
   72 echo "Merging changes into release"
   73 git merge "prep-release-${VERSION}" -m "Release ${VERSION}"
   74 
   75 # tag release
   76 echo "Tagging version"
   77 git tag "${VERSION}"
   78 
   79 # push to release branch
   80 echo "Pushing to release branch"
   81 git push ${PUSH_TO} release
   82 git push ${PUSH_TO} "${VERSION}"
   83 
   84 # release body
   85 echo "Preparing to update GitHub release notes..."
   86 
   87 body=$(changelog-tool get "$VERSION")
   88 
   89 jsontemplate="
   90 {
   91   \"tag_name\":\$version,
   92   \"name\":\$version,
   93   \"body\":\$body
   94 }
   95 "
   96 
   97 json=$(jq -n \
   98 --arg version "$VERSION" \
   99 --arg body "$body" \
  100 "${jsontemplate}")
  101 
  102 echo "Uploading release notes..."
  103 
  104 result=$(curl -X POST "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases" \
  105   -H "Content-Type: application/x-www-form-urlencoded" \
  106   -u "${GITHUB_ACTOR}:${GITHUB_TOKEN}" \
  107   --data "${json}")
  108 
  109 rslt_scan=$(echo "${result}" | jq -r '.id')
  110 if [ "$rslt_scan" != null ]
  111 then
  112   echo "Release notes uploaded"
  113 else
  114   echo "Unable to upload release notes, here's the curl output..."
  115   echo "${result}"
  116   exit 1
  117 fi
  118 
  119 # update CHANGELOG for new entries
  120 git checkout master
  121 git merge "prep-release-${VERSION}"
  122 changelog-tool unreleased -e
  123 
  124 # commit changelog and push to master
  125 git add CHANGELOG.md
  126 git commit -m "Add unreleased section to CHANGELOG post ${VERSION} release prep
  127 
  128 [skip ci]"
  129 git push ${PUSH_TO} master
  130 
  131 # delete release-VERSION tag
  132 git push --delete ${PUSH_TO} "release-${VERSION}"