Skip to content

Bump Dev Version

Bump Dev Version #210

name: Bump Dev Version
on:
workflow_dispatch: # Allows for manual triggering if needed
inputs:
updateType:
description: "Update Type"
required: true
default: "dev"
type: choice
options:
- dev
- patch+dev
- minor+dev
- major+dev
draft:
description: "PR as Draft"
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
permissions:
contents: write
pull-requests: write
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
bump-version:
if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
name: Bump Version
runs-on: ubuntu-latest
steps:
- name: git clone devtools
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
with:
ref: master
- uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f
- name: setup git config
run: |
git config user.name "DevTools Workflow Bot"
git config user.email "[email protected]"
- name: Bump the Version
id: version-bump
run: |
set -ex
pushd tool/
dart pub get
popd
ORIGINAL_VERSION=$(dart tool/update_version.dart current-version)
if [ -z "$UPDATE_TYPE" ]; then
# If $UPDATE_TYPE is not set, then assume it is dev
UPDATE_TYPE="dev"
fi
# If there is a major, minor, or patch bump, do it.
if [ "$UPDATE_TYPE" == "patch+dev" ]; then
dart tool/update_version.dart auto --type patch
dart tool/update_version.dart auto --type dev
elif [ "$UPDATE_TYPE" == "minor+dev" ]; then
dart tool/update_version.dart auto --type minor
dart tool/update_version.dart auto --type dev
elif [ "$UPDATE_TYPE" == "major+dev" ]; then
dart tool/update_version.dart auto --type major
dart tool/update_version.dart auto --type dev
elif [ "$UPDATE_TYPE" == "dev" ]; then
dart tool/update_version.dart auto --type dev
else
echo "ERROR: UNEXPECTED UPDATE TYPE: $UPDATE_TYPE"
exit 1
fi
NEW_VERSION=$(dart tool/update_version.dart current-version)
echo "COMMIT_MESSAGE=Updating from $ORIGINAL_VERSION to $NEW_VERSION" >> $GITHUB_OUTPUT
env:
UPDATE_TYPE: ${{ inputs.updateType }}
- name: Create the PR
run: |
set -ex
BRANCH_NAME="auto-bump-$(date +%s)"
# Stage the file, commit and push
git checkout -b "$BRANCH_NAME"
git commit -a -m "$COMMIT_MESSAGE"
git push -u origin "$BRANCH_NAME"
if [ "$IS_DRAFT" == "true" ]; then
CREATION_FLAGS="--draft"
fi
PR_URL=$(gh pr create --title "$COMMIT_MESSAGE" --body "Automated Version Bump" $CREATION_FLAGS)
# Change github credentials back to the actions bot.
GH_TOKEN="$ORIGINAL_GH_TOKEN"
gh pr edit $PR_URL $FLAGS --add-label "autosubmit"
env:
COMMIT_MESSAGE: ${{ steps.version-bump.outputs.COMMIT_MESSAGE }}
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