Skip to content

Bump peter-evans/create-pull-request from 6 to 7 (#43) #62

Bump peter-evans/create-pull-request from 6 to 7 (#43)

Bump peter-evans/create-pull-request from 6 to 7 (#43) #62

name: update submodules
# requires sudmodules URL to be "https..." (no ssh)
#
# requires submodule to be specified to follow a specific branch (stored in .gitmodules)
#
# clone them with:
#
# git submodule add -b branch_to_follow https://github.com/... submodule_path
#
# or specify it with:
#
# git config -f .gitmodules submodule.submodule_path.branch branch_to_follow
#
# Uses the cron schedule for github actions
#
# https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#scheduled-events
#
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
# * * * * *
on:
push:
branches:
- main
- master
- dev
schedule:
- cron: "0 0 1 * *"
# to trigger update manually from the Action tab in github
workflow_dispatch:
inputs:
log:
description: "Log"
required: false
env:
# to update all submodules
SUBMOD_TO_UPDATE: "*"
# otherwise use a space separated list of the relative paths of each submodule to update
# SUBMOD_TO_UPDATE: "lib/sub_3 lib/sub_1"
defaults:
run:
shell: bash
jobs:
update_submodules:
# only trigger update on upstream repo
if: github.repository_owner == 'cpp-lln-lab'
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: actions/checkout@v4
with:
submodules: true
# check out the correct branch for each submodule and pull them all
# https://stackoverflow.com/questions/5828324/update-git-submodule-to-latest-commit-on-origin
- name: Update submodules
run: |
start_dir=$PWD
if [ "${SUBMOD_TO_UPDATE}" = "*" ]; then
submodules=$(git submodule | awk '{print $2}')
else
submodules=$(echo -e ${SUBMOD_TO_UPDATE} | sed "s/ /\n/g")
fi
nb_submod=$(echo "${submodules}" | wc -l)
echo -e "\nUPDATING ${nb_submod} SUBMODULES"
echo -e "${submodules}"
for i in $(seq 1 ${nb_submod}); do
path=$(echo -e ${submodules} | awk -v i=${i} '{print $i}')
branch=$(git config --get --file .gitmodules submodule.${path}.branch)
echo -e "\nswitching submodule ${path} to ${branch}"
cd "${path}" || exit
git checkout ${branch}
cd "${start_dir}"
done
git submodule update --remote --merge
# if there have been changes,
# a PR is created using the checkout branch for this workflow
# https://github.com/peter-evans/create-pull-request
- name: Create Pull-Request
uses: peter-evans/create-pull-request@v7
with:
commit-message: Update submodules
delete-branch: true