File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 6666 - uses : actions/checkout@v3
6767 with :
6868 fetch-depth : 0 # This pulls changes before doing any changes
69- -
uses :
Panquesito7/[email protected] .4 69+ -
uses :
Panquesito7/[email protected] .5 7070 with :
7171 repos_filename : repos # In case your file is named `repos.lua`, you can leave it as `repos`.
7272 use_pr : true # Whether to create a pull request when updating/adding the repositories.
7777 update_repos : true # When enabled, this will attempt to update all the repositories.
7878 squash_commits : false # Whether to squash all commits or not on every repository update/addition. Cannot be used if `one_pr` is disabled.
7979 one_pr : false # Creates one single PR for everything if enabled. Works only for `update_repos` if disabled.
80+ delete_existing_branches : true # Deletes the branches that updated the subtrees. Note that this is done only on action run, not on immediate PR merge.
8081` ` `
8182
83+ If ` delete_existing_branches` is enabled, it will attempt to delete the branches before running the scripts to ensure there are no merge conflicts.\
84+ However, this is not the most efficient way of deleting the branches. These are other alternatives I recommend :
85+
86+ 1. Automatically [delete branches](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-the-automatic-deletion-of-branches) on PR merging (recommended).
87+ 2. Manually delete the branches (not recommended).
88+ 3. Use a GitHub Action like [Delete Merged Branch](https://github.com/SvanBoxel/delete-merged-branch).
89+
8290You can also configure to run the workflow manually by using `workflow_dispatch` instead of `schedule`.\
8391For more information about Cron, you can check [CronHub](https://crontab.cronhub.io/).
8492
Original file line number Diff line number Diff line change @@ -41,6 +41,10 @@ inputs:
4141 description : " Creates one single PR for updating all the repositories. This does not apply to the `fetch-repos` script. `squash_commits` must be disabled!"
4242 required : false
4343 default : " false"
44+ delete_existing_branches :
45+ description : " Deletes the branches that updated the subtrees. Note that this is done only on action run, not on immediate PR merge."
46+ required : false
47+ default : " true"
4448runs :
4549 using : " composite"
4650 steps :
@@ -99,6 +103,25 @@ runs:
99103 wget https://raw.githubusercontent.com/Panquesito7/submodules-alternative/main/update-repos.lua
100104 fi
101105 fi
106+ - name : Delete existing branches
107+ shell : bash
108+ run : |
109+ if [[ ${{ inputs.update_repos }} == true ]] && [[ ${{ inputs.delete_existing_branches }} == true ]]; then
110+ branches=$(lua -e 'local repos = require("${{ inputs.repos_filename }}").repos; dofile("helper-functions.lua"); get_repo_branches(repos)')
111+ for branch in ${branches[@]}; do
112+ if git ls-remote --heads origin $branch | grep -q $branch; then
113+ if git diff --name-only origin/${GITHUB_REF##*/} $branch | grep -q $branch; then
114+ git push origin -d $branch
115+ fi
116+ fi
117+ done
118+
119+ if git ls-remote --heads origin ${{ inputs.branch_name }} | grep -q ${{ inputs.branch_name }}; then
120+ if git diff --name-only origin/${GITHUB_REF##*/} ${{ inputs.branch_name }} | grep -q ${{ inputs.branch_name }}; then
121+ git push origin -d ${{ inputs.branch_name }}
122+ fi
123+ fi
124+ fi
102125 - name : Clone repositories
103126 shell : bash
104127 run : |
You can’t perform that action at this time.
0 commit comments