public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [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
@ 2021-07-26 22:15 Eugene Rozenfeld
  0 siblings, 0 replies; only message in thread
From: Eugene Rozenfeld @ 2021-07-26 22:15 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:52b0380fab5462a2a82d6c28dbf3fd5d9be35a4f

commit 52b0380fab5462a2a82d6c28dbf3fd5d9be35a4f
Author: Victor Tong <vitong@microsoft.com>
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
+
+


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-26 22:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-26 22:15 [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 Eugene Rozenfeld

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).