Skip to content

Commit

Permalink
Automate replacing test-infra release branch (#4577)
Browse files Browse the repository at this point in the history
Thanks to @atalman works in
#4515 and @osalpekar example
in https://github.com/pytorch/vision/pull/7929/files, this change
applies the same step to test-infra to automate its release branch.

From what I see in
https://github.com/pytorch/test-infra/commits/release/2.1, this seems to
be the only required steps to replace main with release branch.

### Testing

Run `GIT_BRANCH_TO_CUT_FROM=main RELEASE_VERSION=2.1 DRY_RUN=disabled
release/cut-release-branch.sh` to cut release branch for test-infra in
my own fork repo
https://github.com/huydhn/test-infra/commits/release/2.1

Fixes #4570
  • Loading branch information
huydhn authored Nov 6, 2023
1 parent f4361f3 commit 87cd963
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion release/cut-release-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,26 @@ GIT_BRANCH_TO_CUT_FROM=${GIT_BRANCH_TO_CUT_FROM:-viable/strict}

# should output something like 1.11
RELEASE_VERSION=${RELEASE_VERSION:-$(cut -d'.' -f1-2 "${GIT_TOP_DIR}/version.txt")}
TEST_INFRA_BRANCH=${TEST_INFRA_BRANCH:-"release/${RELEASE_VERSION}"}

DRY_RUN_FLAG="--dry-run"
if [[ ${DRY_RUN:-enabled} == "disabled" ]]; then
DRY_RUN_FLAG=""
fi

function update_test_infra_branch() {
# Change all GitHub Actions to reference the test-infra release branch
# as opposed to main as copied from pytorch/vision/packaging/cut_release.sh
for i in .github/workflows/*.yml; do
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' -e s#@main#@"${TEST_INFRA_BRANCH}"# $i;
sed -i '' -e s#test-infra-ref:[[:space:]]main#"test-infra-ref: ${TEST_INFRA_BRANCH}"# $i;
else
sed -i -e s#@main#@"${TEST_INFRA_BRANCH}"# $i;
sed -i -e s#test-infra-ref:[[:space:]]main#"test-infra-ref: ${TEST_INFRA_BRANCH}"# $i;
fi
done
}

(
set -x
Expand All @@ -43,7 +57,14 @@ for branch in "release/${RELEASE_VERSION}" "orig/release/${RELEASE_VERSION}"; do
set -x
git checkout "${GIT_REMOTE}/${GIT_BRANCH_TO_CUT_FROM}"
git checkout -b "${branch}"
git push "${GIT_REMOTE}" "${branch}"
# Apply common steps to automate release
update_test_infra_branch

if [[ "${DRY_RUN:-enabled}" == "disabled" ]]; then
git add .github/workflows/*.yml
git commit -m "[RELEASE-ONLY CHANGES] Branch Cut for Release ${RELEASE_VERSION}"
git push "${GIT_REMOTE}" "${branch}"
fi
)
fi
done

0 comments on commit 87cd963

Please sign in to comment.