From 6b9745c40b056d9879974f250208dcbbc5cdf812 Mon Sep 17 00:00:00 2001 From: "Sean T. Allen" Date: Sun, 4 Aug 2019 19:12:56 -0400 Subject: [PATCH] Add ability to release via a magic tag Not documentated yet. Leaving the previous release process code in place for now. --- .ci-scripts/release.bash | 81 +++++++++++++++++++ ...d-release-documentation-to-main-actor.bash | 6 +- .circleci/config.yml | 17 ++++ USAGE.md | 3 +- 4 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 .ci-scripts/release.bash diff --git a/.ci-scripts/release.bash b/.ci-scripts/release.bash new file mode 100644 index 0000000..737ae09 --- /dev/null +++ b/.ci-scripts/release.bash @@ -0,0 +1,81 @@ +#!/bin/bash + +set -o errexit +set -o nounset + +USERNAME="{USERNAME}" +REPO="{REPO}" +GITHUB_USER="{GITHUB_USER}" + +# Who we are for git +git config --global user.email "{COMMIT_EMAIL}" +git config --global user.name "{COMMIT_NAME}" +git config --global push.default simple + +TAG=$1 +GITHUB_TOKEN=$2 +# changes tag from "release-1.0.0" to "1.0.0" +VERSION="${TAG/release-/}" + +### this doesn't account for master changing commit, assumes we are HEAD +# or can otherwise push without issue. that shouldl error out without issue. +# leaving us to restart from a different HEAD commit +# update CHANGELOG +changelog-tool release "${VERSION}" -e + +# commit CHANGELOG updates +git add CHANGELOG.md +git commit -m "Release ${VERSION}" + +# tag release +git tag "${VERSION}" + +# push to release to remote +git push origin master "${VERSION}" + +# update CHANGELOG for new entries +changelog-tool unreleased -e + +# commit changelog and push to master +git add CHANGELOG.md +git commit -m "Add unreleased section to CHANGELOG post ${VERSION} release + +[skip ci]" +git push origin master + +# release body +echo "Preparing to update GitHub release notes..." + +body=$(changelog-tool get "${VERSION}") + +jsontemplate=" +{ + \"tag_name\":\$version, + \"name\":\$version, + \"body\":\$body +} +" + +json=$(jq -n \ +--arg version "$VERSION" \ +--arg body "$body" \ +"${jsontemplate}") + +echo "Uploading release notes..." + +result=$(curl -X POST "https://api.github.com/repos/${USERNAME}/${REPO}/releases" \ + -H "Content-Type: application/x-www-form-urlencoded" \ + -u "${GITHUB_USER}:${GITHUB_TOKEN}" \ + --data "${json}") + + rslt_scan=$(echo "${result}" | jq -r '.id') +if [ "$rslt_scan" != null ] +then + echo "Release notes uploaded" +else + echo "Unable to upload release notes, here's the curl output..." + echo "${result}" + exit 1 +fi + + diff --git a/.ci-scripts/upload-release-documentation-to-main-actor.bash b/.ci-scripts/upload-release-documentation-to-main-actor.bash index d19f59d..a2a7a07 100644 --- a/.ci-scripts/upload-release-documentation-to-main-actor.bash +++ b/.ci-scripts/upload-release-documentation-to-main-actor.bash @@ -3,8 +3,9 @@ set -eu # Needs to be supplied -USERNAME={USERNAME} -PACKAGE_NAME={PACKAGE} +USERNAME="{USERNAME}" +PACKAGE_NAME="{PACKAGE}" +GITHUB_USER="{GITHUB_USER}" # Gather expected arguments. if [ $# -le 2 ] @@ -26,7 +27,6 @@ git config --global user.name "{COMMIT_NAME}" git config --global push.default simple # Shouldn't need to touch these -GITHUB_USER="${USERNAME}" BUILD_DIR="build/${PACKAGE_NAME}-docs" DOCS_DIR="${GEN_MD}/${PACKAGE_NAME}/${TAG}" diff --git a/.circleci/config.yml b/.circleci/config.yml index 5ffa212..64723e1 100755 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -29,6 +29,13 @@ jobs: - checkout - run: make test config=debug + cut-release: + docker: + - image: ponylang/main.actor-ci:standard + steps: + - checkout + - run: bash .ci-scripts/release.bash "$CIRCLE-TAG" "${GITHUB_ACCESS_TOKEN_NAME}" + generate-documentation-pr-for-main-dot-actor: docker: - image: ponylang/main.actor-ci:standard @@ -45,12 +52,22 @@ jobs: workflows: version: 2.1 + on-every-commit: jobs: - verify-changelog - release-vs-ponyc-release - debug-vs-ponyc-release + create-release: + jobs: + - cut-release: + filters: + tags: + only: /^release-\d+\.\d+\.\d+$/ + branches: + ignore: /.*/ + on-release-being-tagged: jobs: - generate-documentation-pr-for-main-dot-actor: diff --git a/USAGE.md b/USAGE.md index f3fdd60..1d6f5f5 100755 --- a/USAGE.md +++ b/USAGE.md @@ -42,7 +42,7 @@ Additionally, the CONTRIBUTING.md assumes your project is hosted on GitHub and c This repository is templated. You'll want to replace anything in {} with the correct value. The following replacement values are required: -- {USERNAME}: your GitHub username, for example: `ponylang`. +- {USERNAME}: your GitHub username or organization name, for example: `ponylang`. - {REPO}: the name of your repository, for example: `ponyc`. - {PACKAGE}: the name of your libraries package, for example: `msgpack`. - {COC_EMAIL}: email address that Code of Conduct violations should be reported to, for example: `coc@ponylang.org`. @@ -53,6 +53,7 @@ This repository is templated. You'll want to replace anything in {} with the cor - {COMMIT_NAME}: Name to use for commits that code that is part of this package will create, for example: `ponylang-main`. - {COMMIT_EMAIL}: Email address to use for commits that code that is part of this package will create, for example: `main@ponylang.io`. - {GITHUB_ACCESS_TOKEN_NAME}: Name of CircleCI environment variable that your GitHub personal access token that allows for `public_repo` access is stored in. +- {GITHUB_USER}: Username for the owner of the GitHub access token ## What you need to create