Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bump branches #6244

Merged
merged 24 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions .github/workflows/daily-dev-bump.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ on:
required: false
type: boolean
default: false
pull_request:
types: [closed]
schedule:
# * is a special character in YAML so you have to quote this string
- cron: "0 8 * * *" # Run every day at midnight Pacific Time
Expand All @@ -31,7 +29,7 @@ env:

jobs:
bump-version:
if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
if: ${{ github.repository == 'flutter/devtools' }}
name: Bump Version
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -121,22 +119,4 @@ jobs:
GH_TOKEN: ${{ secrets.DEVTOOLS_WORKFLOW_BOT_TOKEN }}
ORIGINAL_GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
IS_DRAFT: ${{ inputs.draft == true }}
clean-up-branches:
# If a pr is closed on a workflow bot PR, then clean up workflow bot branches.
if: ${{ github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.user.login == 'DartDevtoolWorkflowBot'}}
name: Clean up Dev Bump Branches
runs-on: ubuntu-latest
steps:
- name: Clean up branches
run: |
# Get 5 most recent branches of closed DartDevtoolWorkflowBot PRs.
CLOSED_BRANCH_NAMES=$(gh pr list -A DartDevtoolWorkflowBot -s closed -L 5 --search sort:created-desc | grep auto-bump- | sed 's|.*\(auto-bump-[[:digit:]]*\).*|\1|')

# Get list of refs(branches) that exist on the remote
EXISTING_REFS=$(git ls-remote --heads | grep refs/heads/auto-bump-)
for CLOSED_BRANCH in $CLOSED_BRANCH_NAMES; do
if echo "$EXISTING_REFS" | grep -q "$CLOSED_BRANCH" ; then
# If the branch still exists then we will delete it
gh api /repos/flutter/devtools/git/refs/heads/$CLOSED_BRANCH -X DELETE
fi
done

1 change: 1 addition & 0 deletions .github/workflows/flutter-candidate-update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ env:

jobs:
update-candidate:
if: ${{ github.repository == 'flutter/devtools' }}
name: Update Flutter Candidate Version
runs-on: ubuntu-latest
steps:
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/workflow-bot-cleanup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Workflow Bot Cleanup
on:
workflow_dispatch: # Allows for manual triggering if needed
schedule:
# * is a special character in YAML so you have to quote this string
- cron: "0 9 * * *" # Run every day
permissions:
contents: write
pull-requests: write


jobs:
clean-up-branches:
if: ${{ github.repository == 'flutter/devtools' }}
name: Clean up closed DartDevtoolWorkflowBot Branches
runs-on: ubuntu-latest
steps:
- name: Sparse checkout of the repository
uses: actions/checkout@v3
with:
sparse-checkout: |
README.md
- name: Clean up closed DartDevtoolWorkflowBot branches
run: |
set -e

# Get list of branches that exist on the remote, then filter for the workflow bot branches
EXISTING_BRANCHES=$(git ls-remote --heads | grep refs/heads | awk '{print $2}' |sed 's|refs/heads/\(.*\)$|\1|')
for EXISTING_BRANCH in $EXISTING_BRANCHES; do
set +e # Turn off exit on error, since "gh pr view" may fail if branch doesn't exist
PR_INFO=$(gh pr view --json closed,author "$EXISTING_BRANCH")
if [[ $? -ne 0 ]]; then
# If getting PR_INFO fails assume the PR does not exist
echo "SKIP: No PR exists for $EXISTING_BRANCH"
continue
fi
set -e # Turn exit on error back on

PR_IS_CLOSED=$(echo $PR_INFO | jq -r '.closed')
PR_AUTHOR=$(echo $PR_INFO | jq -r '.author.login')
if [[ "$PR_IS_CLOSED" == "true" ]] && [[ "$PR_AUTHOR" == "DartDevtoolWorkflowBot" ]]; then
# Delete branches where:
# - DartDevtoolWorkflowBot is the author
# - the PR is closed
echo "Deleting $EXISTING_BRANCH"
gh api /repos/flutter/devtools/git/refs/heads/$EXISTING_BRANCH -X DELETE
else
echo "SKIP: Avoiding $EXISTING_BRANCH { is_closed:$PR_IS_CLOSED, author:$PR_AUTHOR }"
fi
done

env:
GH_TOKEN: ${{ secrets.DEVTOOLS_WORKFLOW_BOT_TOKEN }}