Skip to content

Commit

Permalink
Re-generate
Browse files Browse the repository at this point in the history
  • Loading branch information
danielrbradley committed Jul 8, 2024
1 parent 23570fa commit f8651b0
Show file tree
Hide file tree
Showing 9 changed files with 957 additions and 348 deletions.
16 changes: 5 additions & 11 deletions provider-ci/test-providers/aws/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,27 +167,21 @@ tfgen_build_only:

upstream:
ifneq ("$(wildcard upstream)","")
scripts/upstream.sh "$@" apply
./upstream.sh init
endif

# Ensure tool is installed
cd upstream-tools && yarn install --frozen-lockfile
# Apply all automated changes
cd upstream-tools && yarn --silent run apply

# Deprecated: Use `upstream.format_patches` instead
upstream.finalize:
scripts/upstream.sh "$@" end_rebase
echo "Deprecated: Use `./upstream.sh format_patches` instead"
scripts/upstream_old.sh "$@" end_rebase

# Deprecated: Use `upstream.checkout` instead
upstream.rebase:
scripts/upstream.sh "$@" start_rebase

upstream.checkout:
scripts/upstream.sh "$@" checkout

upstream.format_patches:
scripts/upstream.sh "$@" format_patches
echo "Deprecated: Use `./upstream.sh checkout` and `./upstream.sh rebase` instead"
scripts/upstream_old.sh "$@" start_rebase

bin/pulumi-java-gen: .pulumi-java-gen.version
pulumictl download-binary -n pulumi-language-java -v v$(shell cat .pulumi-java-gen.version) -r pulumi/pulumi-java
Expand Down
105 changes: 0 additions & 105 deletions provider-ci/test-providers/aws/scripts/upstream.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
#!/usr/bin/env bash
# WARNING: This file is autogenerated - changes will be overwritten if not made via https://github.com/pulumi/ci-mgmt

# HOW UPSTREAM PATCHES WORK
# =========================
# Rather than creating a fork of the upstream repository, we maintain a set of patches that we can apply directly to the upstream code.
# This allows us to keep a single source of the patches we maintain as well as track the changes to our patches.
# We use a git submodule called 'upstream' to track the commit of the upstream repository that we will apply our patches to.
# This is typically pointing at the the same commit as the latest tag of the upstream repository.
# We then store our patches in the 'patches' directory and apply them to the upstream repository before building our provider.
# Our patches are never pushed to the remote upstream repository.
#
# There are two modes of patching the upstream repository:
# 1. 'apply': Only modifies the working directory. The submodule commit is checked out, then each patch is applied to the working directory.
# 2. 'checkout': Creates a branch in the local upstream repository and creates a commit for each patch in the 'patches' directory.
#
# The 'apply' mode is used by default for when we're building the provider. The 'checkout' mode is used when we need to modify the patches.
#
# To enter the 'checkout' mode, run `make upstream.checkout`. This will create a branch in the upstream repository with the patches applied.
# To exit the 'checkout' mode, run `make upstream.format_patches`. This will create a new set of patches in the 'patches' directory from the commits on your branch.
#
# When rebasing the commits, you must also move the 'checkout-base' branch to the new base commit of the patches. E.g. `git branch -f checkout-base <new_base_ref>`.

set -e

# "$1" is the current make command being run.
Expand Down Expand Up @@ -198,95 +178,10 @@ end_rebase() {
apply "$1"
}

checkout() {
assert_upstream "$1"
assert_no_rebase_in_progress "$1"

git submodule update --force --init
# Clean up any previous in-progress rebases.
rm -rf .git/modules/upstream/rebase-merge
cd upstream && git fetch

# Set the 'checkout-base' branch to the current commit of the upstream repository
# This is used to track the base commit of the patches
# If rebasing, then this must be moved to the new base commit.
git branch -f checkout-base
# Create a new branch 'pulumi-patch' which will contain the commits for each patch
git checkout -B pulumi-patch
git branch --set-upstream-to=local pulumi-patch

for patch in ../patches/*.patch; do
echo "Applying $patch"
if ! git am --3way "$patch"; then
echo
echo "Failed to apply ${patch}. Please run 'make upstream.rebase FROM=$TAG' where '$TAG' allows the patch set to apply cleanly"
echo
exit 1
fi
done

touch ../rebase-in-progress

cat <<EOF
The patches have been checked out as commits in the './upstream' repository
on the 'pulumi-patch' branch. You can now edit the commits directly in the
upstream repository e.g. using 'git rebase -i'.
The 'checkout-base' branch is tracking the base commit of the patches. If you
want to change the base commit of the patches, move the 'checkout-base' branch
first, the perform a rebase:
git branch -f checkout-base <new-base-commit>
For example, to rebase the patches on top of v1.2.3, run:
git branch -f checkout-base v1.2.3
git rebase --onto v1.2.3
Once you have finished editing the patches, run:
make upstream.format_patches
EOF
}

format_patches() {
assert_rebase_in_progress "$1"
# Use git to resolve the possible location of files indicating a rebase might be in progress.
rebase_merge_dir=$(cd upstream && git rev-parse --git-path rebase-merge)
rebase_apply_dir=$(cd upstream && git rev-parse --git-path rebase-apply)

if [ -d "${rebase_merge_dir}" ] || [ -d "${rebase_apply_dir}" ]; then
echo "rebase still in progress in './upstream'. Please resolve the rebase in"
echo "'./upstream' and then run 'make \"$1\"' again."
exit 1
fi

# Remove all existing patches before creating the new ones in case they've been renamed or removed.
rm patches/*.patch
cd upstream
# Extract patches from the commits in the 'pulumi-patch' branch into the 'patches' directory.
# Use the 'checkout-base' branch to determine the base commit of the patches.
git format-patch checkout-base -o ../patches --zero-commit --no-signature --no-stat --no-numbered
# Checkout the 'checkout-base' branch to the current commit of the upstream repository
# so the upstream HEAD is pointing at the correct base, ready to be committed as a submodule.
git checkout checkout-base
cd ..
# Mark the rebase as complete.
rm rebase-in-progress
}

case $2 in
apply)
apply "$1"
;;
checkout)
checkout "$1"
;;
format_patches)
format_patches "$1"
;;
start_rebase)
start_rebase "$1"
;;
Expand Down
Loading

0 comments on commit f8651b0

Please sign in to comment.