From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7840) id EE511383D827; Mon, 26 Jul 2021 22:15:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE511383D827 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Eugene Rozenfeld To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/microsoft/heads/main)] This changes adds a new workflow to delete branches created by update-main.yaml that are 14+ days ol X-Act-Checkin: gcc X-Git-Author: Victor Tong X-Git-Refname: refs/vendors/microsoft/heads/main X-Git-Oldrev: 2798baeae58dfa6b9736d926058bdda3a321e207 X-Git-Newrev: 52b0380fab5462a2a82d6c28dbf3fd5d9be35a4f Message-Id: <20210726221557.EE511383D827@sourceware.org> Date: Mon, 26 Jul 2021 22:15:57 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Jul 2021 22:15:58 -0000 https://gcc.gnu.org/g:52b0380fab5462a2a82d6c28dbf3fd5d9be35a4f commit 52b0380fab5462a2a82d6c28dbf3fd5d9be35a4f Author: Victor Tong Date: Mon Jun 21 10:19:26 2021 -0700 This changes adds a new workflow to delete branches created by update-main.yaml that are 14+ days old. The workflow will only delete branches matching the merge-master-.* regular expression Diff: --- .github/scripts/delete-branches.sh | 25 +++++++++++++ .github/workflows/delete-merge-branches.yaml | 52 ++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/.github/scripts/delete-branches.sh b/.github/scripts/delete-branches.sh new file mode 100644 index 00000000000..93582f1e4af --- /dev/null +++ b/.github/scripts/delete-branches.sh @@ -0,0 +1,25 @@ +# Deletes branches that match the regex and are older than the maximum acceptable branch age +# $1 is the regex to match the branch to +# $2 is the maximum acceptable branch age + +branchesStr=$(git for-each-ref --format='%(refname:short) %(committerdate:relative)' --sort=-committerdate refs/remotes/origin) +readarray -t branches <<<"$branchesStr" +maxAcceptableDateInSecs=$(date -d "$2 days ago" +%s) +regexMatch=$1 + +for (( i=0; i<${#branches[@]} ; i+=1 )) ; do + echo "${branches[i]}" + read -r branchName lastCommitRelative <<< "${branches[i]}" + # Remove commas in the date which can occur with older branches. e.g. "2 years, 2 months ago" + lastCommitRelative=$(echo "$lastCommitRelative" | sed 's;,;;' ) + lastCommitRelativeDate=$(date -d "$lastCommitRelative" +%s) + + echo "$lastCommitRelative" + echo "$lastCommitRelativeDate" + echo "$maxAcceptableDateInSecs" + if [ $lastCommitRelativeDate -lt $maxAcceptableDateInSecs ] + then + branchNameTrimmed=$( echo "$branchName" | sed 's;origin/;;' ) + [[ $branchNameTrimmed =~ $regexMatch ]] && echo "Deleting branch $branchNameTrimmed" && git push origin --delete $branchNameTrimmed + fi +done \ No newline at end of file diff --git a/.github/workflows/delete-merge-branches.yaml b/.github/workflows/delete-merge-branches.yaml new file mode 100644 index 00000000000..3e0930d62d6 --- /dev/null +++ b/.github/workflows/delete-merge-branches.yaml @@ -0,0 +1,52 @@ +# Copyright (c) Microsoft Corporation. + +# MIT License + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +# This workflow deletes the stale merge branches created by update-main.yaml +# Stale is defined by the branch being 14+ days old. Keeping the branch around for a little +# while can help us investigate failures. + +on: + # Run once a day at 5 am UTC + schedule: + - cron: "0 5 * * *" + +jobs: + delete: + runs-on: ubuntu-18.04 + outputs: + config: ${{ steps.printNoSecretJson.outputs.noSecretConfigJson }} + matrixTestSet: ${{ steps.printGCCTestSet.outputs.testSet }} + steps: + - name: checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + submodules: recursive + lfs: true + + - name: Delete stale branches + run: | + chmod +x .github/scripts/delete-branches.sh + .github/scripts/delete-branches.sh "^merge-master-.*" 14 + shell: bash + +