From 79ec61396fa6c6d364e4f3f74eed829fe3461dc6 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Fri, 26 Aug 2022 11:54:18 -0700 Subject: [PATCH] dev: update scripts to push subrepos Signed-off-by: Stephen Gutekanst --- dev/pull-subrepos.sh | 6 ----- dev/push-subrepos.sh | 61 ++++++++++++++++++++++++++++++++++++++---- dev/update-subrepos.sh | 17 ------------ 3 files changed, 56 insertions(+), 28 deletions(-) delete mode 100755 dev/pull-subrepos.sh delete mode 100755 dev/update-subrepos.sh diff --git a/dev/pull-subrepos.sh b/dev/pull-subrepos.sh deleted file mode 100755 index 84ba4c98..00000000 --- a/dev/pull-subrepos.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -set -exuo pipefail -cd "$(dirname "${BASH_SOURCE[0]}")"/.. - -./dev/update-subrepos.sh -git subtree pull --prefix glfw mach-glfw main diff --git a/dev/push-subrepos.sh b/dev/push-subrepos.sh index fe36fd4c..707ea944 100755 --- a/dev/push-subrepos.sh +++ b/dev/push-subrepos.sh @@ -1,8 +1,59 @@ #!/usr/bin/env bash -set -exuo pipefail +set -euo pipefail cd "$(dirname "${BASH_SOURCE[0]}")"/.. -./dev/update-subrepos.sh -git subtree push --prefix libs/glfw mach-glfw main -git subtree push --prefix libs/gpu-dawn mach-gpu-dawn main -git subtree push --prefix libs/freetype mach-freetype main +push_subrepo() { + local project=$1 + + echo " ----------------------------------------------------------------------------" + echo " | 🚀🐒 Preparing: mach-$project" + echo " ----------------------------------------------------------------------------" + cp -R staging-clean staging/ + cd staging/ + + # Rewrite e.g. libs/freetype/ -> freetype/ so we have Git history for that subrepo in one path + # only (git subtree cannot follow renames.) For glfw, gpu-dawn, and freetype they were in the + # root before being under libs/ and so this is required to generate the proper history. + if [[ "$project" == "glfw" ]]; then + # glfw has an unfortunately non-linear history, and so we can't preserve commit hashes + # or else the subtree push cannot rebuild history properly. + git filter-repo --force \ + --path $project \ + --path "libs/$project" \ + --path-rename libs/$project:$project + else + git filter-repo --force \ + --preserve-commit-hashes \ + --path $project \ + --path "libs/$project" \ + --path-rename libs/$project:$project + fi + + # Push changes to the external subrepo. + if [ -n "${GITHUB_ACTIONS:-}" ]; then + git remote add -f "mach-$project" "https://slimsag:$ACCESS_TOKEN@github.com/hexops/mach-$project" || true + else + git remote add -f "mach-$project" "git@github.com:hexops/mach-$project" || true + fi + git fetch "mach-$project" + + echo " ----------------------------------------------------------------------------" + echo " | 🚀🐒 Pushing: mach-$project" + echo " ----------------------------------------------------------------------------" + git subtree push --prefix "$project" "mach-$project" main + + cd .. + rm -rf staging/ + echo " ----------------------------------------------------------------------------" + echo " | 🚀🐒 Finished: mach-$project" + echo " ----------------------------------------------------------------------------" +} + +rm -rf staging-clean/ staging/ +git clone https://github.com/hexops/mach staging-clean + +push_subrepo 'glfw' +push_subrepo 'gpu-dawn' +push_subrepo 'freetype' + +rm -rf staging-clean diff --git a/dev/update-subrepos.sh b/dev/update-subrepos.sh deleted file mode 100755 index 02a57c60..00000000 --- a/dev/update-subrepos.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash -set -exuo pipefail -cd "$(dirname "${BASH_SOURCE[0]}")"/.. - -if [ -n "${GITHUB_ACTIONS:-}" ]; then - git remote add -f mach-glfw "https://slimsag:$ACCESS_TOKEN@github.com/hexops/mach-glfw" || true - git remote add -f mach-gpu-dawn "https://slimsag:$ACCESS_TOKEN@github.com/hexops/mach-gpu-dawn" || true - git remote add -f mach-freetype "https://slimsag:$ACCESS_TOKEN@github.com/hexops/mach-freetype" || true -else - git remote add -f mach-glfw git@github.com:hexops/mach-glfw || true - git remote add -f mach-gpu-dawn git@github.com:hexops/mach-gpu-dawn || true - git remote add -f mach-freetype git@github.com:hexops/mach-freetype || true -fi - -git fetch mach-glfw -git fetch mach-gpu-dawn -git fetch mach-freetype