Unverified Commit 64a9d925 authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

create a common history for generated code branches (#782)

* create a common history for generated code branches

* fetch first

* hmm

* try github.head_ref

* fix divergent history issue

* Compute the base branch properly

* chck

* chk
parent ab814219
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ jobs:
      id: branch_output
    - uses: actions/github-script@v5
      # NOTE: if comments on each commit become bothersome, add a check that github.event.pull_request.action == "opened"
      if: ${{ env.GITHUB_HEAD_REF }} != null
      if: ${{ github.head_ref != null }}
      with:
        script: |
          await github.rest.issues.createComment({
+10 −3
Original line number Diff line number Diff line
@@ -15,16 +15,23 @@ set -e
{
	git diff --quiet || (echo 'working tree not clean, aborting' && exit 1)
	gh_branch=${GITHUB_HEAD_REF##*/}
	echo "Loaded branch from GitHub: $gh_branch ($GITHUB_HEAD_REF)"
	base_branch=${GITHUB_BASE_REF##*/}
	if [ -n "$base_branch" ]; then
	  base_branch=__generated-$base_branch
  else
    base_branch=__generated__
	fi
	echo "Loaded branch from GitHub: $gh_branch ($GITHUB_HEAD_REF). Base branch: $base_branch"
	current_branch="${gh_branch:-$(git rev-parse --abbrev-ref HEAD)}"
	echo "Current branch resolved to: $current_branch"
	gen_branch="__generated-$current_branch"
	git branch -D "$gen_branch" || echo "no branch named $gen_branch yet"
	repo_root=$(git rev-parse --show-toplevel)
	cd "$repo_root" && ./gradlew :aws:sdk:assemble
	target="$(mktemp -d)"
	mv "$repo_root"/aws/sdk/build/aws-sdk "$target"
	git checkout --orphan "$gen_branch"
	# checkout and reset $gen_branch to be based on the __generated__ history
	git fetch origin "$base_branch"
	git checkout -B "$gen_branch" origin/"$base_branch"
	cd "$repo_root" && git rm -rf .
	rm -rf "$repo_root/aws-sdk"
	mv "$target"/aws-sdk "$repo_root"/.