This repository has been archived by the owner on Aug 8, 2024. It is now read-only.
update submodules #17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: update submodules | |
# This workflow will checkout the tracked branch of all submodules | |
# and will update the submodule pull the latest commit of that submodule branch | |
# If the branch was not up to date this will then open a PR against the base branch | |
# in the repo this submodule belongs to. | |
# ---- WARNING ---- | |
# Currently if the submodule is not tracking the default branch, | |
# this will workflow will fail. | |
# | |
# 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: | |
- master | |
schedule: | |
- cron: "0 0 1 * *" | |
# to trigger update manually from the Action tab in github | |
workflow_dispatch: | |
inputs: | |
log: | |
description: "Log" | |
required: false | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
update_submodules: | |
# only trigger update on upstream repo | |
if: github.repository_owner == 'bids-standard' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Clone repo | |
uses: actions/checkout@v3 | |
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: | | |
set -e -u | |
start_dir=$PWD | |
submodules=$(git submodule | awk '{print $2}') | |
nb_submod=$(echo "${submodules}" | wc -l) | |
echo -e "\nUPDATING ${nb_submod} SUBMODULES" | |
echo -e "${submodules}" | |
paths=$(git config --file .gitmodules --name-only --get-regexp path) | |
branches=$(git config --file .gitmodules --name-only --get-regexp branch) | |
for i in $(seq 1 "${nb_submod}"); do | |
path=$(echo "${paths}" | awk -v i="${i}" '{print $i}') | |
path=$(git config --get --file .gitmodules "${path}") | |
branch=$(echo "${branches}" | awk -v i="${i}" '{print $i}') | |
branch=$(git config --get --file .gitmodules "${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@v4 | |
with: | |
commit-message: Update submodules | |
delete-branch: true | |
title: 'MNT: Update git submodules' | |
body: 'done via this [GitHub Action](https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/.github/workflows/update_submodules.yml)' |