Skip to content

Commit

Permalink
Add automated release process
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanTAllen committed Sep 1, 2019
1 parent 4ee312b commit 3f81786
Show file tree
Hide file tree
Showing 10 changed files with 320 additions and 177 deletions.
89 changes: 89 additions & 0 deletions .ci-scripts/documentation.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash

set -o errexit
set -o nounset

base=$(dirname "$0")
source "${base}/env.bash"

# Gather expected arguments.
if [ $# -lt 2 ]
then
echo "Tag and GH personal access token are required"
exit 1
fi

# Directory we are going to do additional work in
GEN_MD="$(mktemp -d)"

# From command line
TAG=$1
GITHUB_TOKEN=$2

# Shouldn't need to touch these
BUILD_DIR="build/glob-docs"
DOCS_DIR="${GEN_MD}/glob/${TAG}"

# Generated markdown repo
echo "Cloning main.actor-package-markdown repo into ${GEN_MD}"
git clone \
"https://${GITHUB_TOKEN}@github.com/${REPO_OWNER}/main.actor-package-markdown.git" \
"${GEN_MD}"

# Make the docs
# We make assumptions about the location for the docs
make docs

# $BUILD_DIR contains the raw generated markdown for our documentation
pushd "${BUILD_DIR}" || exit 1
mkdir -p "${DOCS_DIR}"
cp -r docs/* "${DOCS_DIR}"/
cp -r mkdocs.yml "${DOCS_DIR}"

# Upload any new documentation
echo "Preparing to upload generated markdown content from ${GEN_MD}"
echo "Git fiddling commences..."
pushd "${GEN_MD}" || exit 1
echo "Creating a branch for generated documentation..."
branch_name="glob-${TAG}"
git checkout -b "${branch_name}"
echo "Adding content..."
git add .
git commit -m "Add docs for package: glob version: ${TAG}"
echo "Uploading new generated markdown content..."
git push --set-upstream origin "${branch_name}"
echo "Generated markdown content has been uploaded!"
popd || exit 1

# Create a PR
echo "Preparing to create a pull request..."
jsontemplate="
{
\"title\":\$title,
\"head\":\$incoming_repo_and_branch,
\"base\":\"master\"
}
"

json=$(jq -n \
--arg title "glob ${TAG}" \
--arg incoming_repo_and_branch "${REPO_OWNER}:${branch_name}" \
"${jsontemplate}")


echo "Curling..."
result=$(curl -X POST \
https://api.github.com/repos/ponylang/main.actor-package-markdown/pulls \
-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 "PR successfully created!"
else
echo "Unable to create PR, here's the curl output..."
echo "${result}"
exit 1
fi
8 changes: 8 additions & 0 deletions .ci-scripts/env.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
REPO_OWNER="ponylang"
REPO_NAME="glob"
GITHUB_USER="ponylang-main"

# Who we are for git
git config --global user.email "ponylang.main@gmail.com"
git config --global user.name "Main"
git config --global push.default simple
3 changes: 2 additions & 1 deletion .ci-scripts/install-dependencies.bash
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

add-apt-repository ppa:ponylang/ponylang
apt-get update
apt-get install -y libpcre2-dev
apt-get install -y pony-stable

stable fetch
135 changes: 135 additions & 0 deletions .ci-scripts/release.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/bin/bash

set -o errexit
set -o nounset

base=$(dirname "$0")
source "${base}/env.bash"

# Gather expected arguments.
if [ $# -lt 3 ]
then
echo "Tag, GH personal access token, and Ponylang zulip access token are required"
exit 1
fi

TAG=$1
GITHUB_TOKEN=$2
ZULIP_TOKEN=$3
# 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 HEAD: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 HEAD: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/${REPO_OWNER}/${REPO_NAME}/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

# Update Last Week in Pony
echo "Adding release to Last Week in Pony..."

result=$(curl https://api.github.com/repos/ponylang/ponylang-website/issues?labels=last-week-in-pony)

lwip_url=$(echo "${result}" | jq -r '.[].url')
if [ "$lwip_url" != "" ]
then
body="
Version ${VERSION} of glob has been released.
See the [release notes](https://github.com/ponylang/glob/releases/tag/${VERSION}) for more details.
"

jsontemplate="
{
\"body\":\$body
}
"

json=$(jq -n \
--arg body "$body" \
"${jsontemplate}")

result=$(curl -X POST "$lwip_url/comments" \
-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 notice posted to LWIP"
else
echo "Unable to post to LWIP, here's the curl output..."
echo "${result}"
fi
else
echo "Unable to post to Last Week in Pony. Can't find the issue."
fi

message="
Version ${VERSION} of glob has been released.
See the [release notes](https://github.com/ponylang/glob/releases/tag/${VERSION}) for more details.
"

curl -X POST https://ponylang.zulipchat.com/api/v1/messages \
-u ${ZULIP_TOKEN} \
-d "type=stream" \
-d "to=announce" \
-d "topic=glob" \
-d "content=${message}"
66 changes: 51 additions & 15 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,22 @@ orbs:
zulip: ponylang/zulip@1

jobs:
release-vs-ponyc-release:
verify-changelog:
docker:
- image: ponylang/ponyc:release
- image: ponylang/changelog-tool:release
steps:
- checkout
- run: bash .ci-scripts/install-dependencies.bash
- run: stable fetch
- run: make test config=release
- run: changelog-tool verify
- zulip/status:
fail_only: true

debug-vs-ponyc-release:
release-vs-ponyc-release:
docker:
- image: ponylang/ponyc:release
steps:
- checkout
- run: bash .ci-scripts/install-dependencies.bash
- run: stable fetch
- run: make test config=debug
- run: make test config=release
- zulip/status:
fail_only: true

Expand All @@ -32,34 +29,53 @@ jobs:
steps:
- checkout
- run: bash .ci-scripts/install-dependencies.bash
- run: stable fetch
- run: make test config=release
- zulip/status:
fail_only: true

debug-vs-ponyc-release:
docker:
- image: ponylang/ponyc:release
steps:
- checkout
- run: bash .ci-scripts/install-dependencies.bash
- run: make test config=debug
- zulip/status:
fail_only: true

debug-vs-ponyc-master:
docker:
- image: ponylang/ponyc:latest
steps:
- checkout
- run: bash .ci-scripts/install-dependencies.bash
- run: stable fetch
- run: make test config=debug
- zulip/status:
fail_only: true

verify-changelog:
cut-release:
docker:
- image: ponylang/changelog-tool:release
- image: ponylang/shared-docker-ci-release-a-library:release
steps:
- checkout
- run: changelog-tool verify
- run: bash .ci-scripts/release.bash "$CIRCLE_TAG" "$GITHUB_TOKEN" "$ZULIP_RELEASE_ANNOUNCEMENT_TOKEN"
- zulip/status:
fail_only: true

generate-documentation-pr-for-main-dot-actor:
docker:
- image: ponylang/shared-docker-ci-release-a-library:release
steps:
- checkout
- run: bash .ci-scripts/install-dependencies.bash
- run: bash .ci-scripts/documentation.bash "$CIRCLE_TAG" "$GITHUB_TOKEN"
- zulip/status:
fail_only: true

workflows:
version: 2.1
commit:

on-every-commit:
jobs:
- verify-changelog:
context: org-global
Expand All @@ -68,7 +84,27 @@ workflows:
- debug-vs-ponyc-release:
context: org-global

nightly:
create-release:
jobs:
- cut-release:
context: org-global
filters:
tags:
only: /^release-\d+\.\d+\.\d+$/
branches:
ignore: /.*/

on-release-being-tagged:
jobs:
- generate-documentation-pr-for-main-dot-actor:
context: org-global
filters:
tags:
only: /^\d+\.\d+\.\d+$/
branches:
ignore: /.*/

daily-check-for-breakage:
triggers:
- schedule:
cron: "0 0 * * *"
Expand Down
Loading

0 comments on commit 3f81786

Please sign in to comment.