From 0f1c7b307efbe00490fd4faecf468e1686b096f7 Mon Sep 17 00:00:00 2001 From: lgtm <1gtm@users.noreply.github.com> Date: Fri, 19 Jun 2020 16:10:20 -0700 Subject: [PATCH] [cherry-pick] Add script to update release tracker on pr merge (#32) (#35) Co-authored-by: Tamal Saha --- .github/workflows/cherry-pick.yml | 8 +++- .github/workflows/release-tracker.yml | 36 ++++++++++++++ hack/scripts/cherry-pick.sh | 2 - hack/scripts/update-release-tracker.sh | 66 ++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/release-tracker.yml create mode 100755 hack/scripts/update-release-tracker.sh diff --git a/.github/workflows/cherry-pick.yml b/.github/workflows/cherry-pick.yml index 4f5bb962b..d254244f5 100644 --- a/.github/workflows/cherry-pick.yml +++ b/.github/workflows/cherry-pick.yml @@ -13,9 +13,13 @@ jobs: - uses: actions/checkout@v1 - name: Prepare git + env: + GITHUB_USER: 1gtm + GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }} run: | - git config --global user.name "1gtm" - git config --global user.email "1gtm@appscode.com" + git config --global user.name "${GITHUB_USER}" + git config --global user.email "${GITHUB_USER}@appscode.com" + git remote set-url origin https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git - name: Install GitHub CLI run: | diff --git a/.github/workflows/release-tracker.yml b/.github/workflows/release-tracker.yml new file mode 100644 index 000000000..95308eafe --- /dev/null +++ b/.github/workflows/release-tracker.yml @@ -0,0 +1,36 @@ +name: release-tracker + +on: + pull_request: + types: [closed] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + + - name: Prepare git + env: + GITHUB_USER: 1gtm + GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }} + run: | + git config --global user.name "${GITHUB_USER}" + git config --global user.email "${GITHUB_USER}@appscode.com" + git remote set-url origin https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git + + - name: Install GitHub CLI + run: | + curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.1 + sudo mv bin/hub /usr/local/bin + + - name: Update release tracker + if: | + github.event.action == 'closed' && + github.event.pull_request.merged == true + env: + GITHUB_USER: 1gtm + GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }} + run: | + ./hack/scripts/update-release-tracker.sh diff --git a/hack/scripts/cherry-pick.sh b/hack/scripts/cherry-pick.sh index a25224415..313891953 100755 --- a/hack/scripts/cherry-pick.sh +++ b/hack/scripts/cherry-pick.sh @@ -31,8 +31,6 @@ should_cherry_pick || { exit 0 } -git remote set-url origin https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git - while IFS=/ read -r -u9 repo branch; do git checkout $branch pr_branch="master-${GITHUB_SHA:0:8}"${branch#"release"} diff --git a/hack/scripts/update-release-tracker.sh b/hack/scripts/update-release-tracker.sh new file mode 100755 index 000000000..ff1254d79 --- /dev/null +++ b/hack/scripts/update-release-tracker.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +# Copyright The Stash Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eou pipefail + +# ref: https://gist.github.com/joshisa/297b0bc1ec0dcdda0d1625029711fa24 +parse_url() { + proto="$(echo $1 | grep :// | sed -e's,^\(.*://\).*,\1,g')" + # remove the protocol + url="$(echo ${1/$proto/})" + + IFS='/' # / is set as delimiter + read -ra PARTS <<<"$url" # str is read into an array as tokens separated by IFS + if [ ${PARTS[0]} != 'github.com' ] || [ ${#PARTS[@]} -ne 5 ]; then + echo "failed to parse relase-tracker: $url" + exit 1 + fi + export RELEASE_TRACKER_OWNER=${PARTS[1]} + export RELEASE_TRACKER_REPO=${PARTS[2]} + export RELEASE_TRACKER_PR=${PARTS[4]} +} + +RELEASE_TRACKER= + +while IFS=$': \t' read -r -u9 marker v; do + case $marker in + Release-tracker) + export RELEASE_TRACKER=$v + ;; + Release) + export RELEASE=$v + ;; + esac +done 9< <(git show -s --format=%b) + +[ ! -z $RELEASE_TRACKER ] || { + echo "Release-tracker url not found." + exit 0 +} + +parse_url $RELEASE_TRACKER +api_url="repos/${RELEASE_TRACKER_OWNER}/${RELEASE_TRACKER_REPO}/issues/${RELEASE_TRACKER_PR}/comments" + +case $GITHUB_BASE_REF in + master) + msg="/ready-to-tag github.com/${GITHUB_REPOSITORY} ${GITHUB_SHA}" + ;; + *) + msg="/cherry-picked github.com/${GITHUB_REPOSITORY} ${GITHUB_BASE_REF} ${GITHUB_SHA}" + ;; +esac + +hub api "$api_url" -f body="$msg"