Skip to content

Commit

Permalink
Merge pull request #613 from pulumi/update-github-actions-workflows-25
Browse files Browse the repository at this point in the history
Update GitHub Actions workflows.
  • Loading branch information
Alex Qiu authored May 1, 2023
2 parents 543ba7a + fc2f4f7 commit e0b3e39
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 50 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/upgrade-provider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ jobs:
- name: Call upgrade provider action
uses: pulumi/[email protected]
with:
branch: master
gh-token: ${{ secrets.PULUMI_BOT_TOKEN }}
git-email: [email protected]
git-username: Pulumi bot
provider-repo: pulumi-docker
slack-channel: provider-upgrade-status
slack-webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
name: Upgrade provider
Expand Down
54 changes: 9 additions & 45 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ cleanup:
docs:
cd provider/pkg/docs-gen/examples/ && go run generate.go ./yaml ./

finish-patch:
@if [ ! -z "$$(cd upstream && git status --porcelain)" ]; then echo "Please commit your changes before finishing the patch"; exit 1; fi
@cd upstream && \
git format-patch HEAD~ -o ../patches --start-number $$(($$(ls ../patches | wc -l | xargs)+1))

help:
@grep '^[^.#]\+:\s\+.*#' Makefile | \
sed "s/\(.\+\):\s*\(.*\) #\s*\(.*\)/`printf "\033[93m"`\1`printf "\033[0m"` \3 [\2]/" | \
Expand All @@ -108,29 +103,6 @@ lint_provider: provider
provider: tfgen install_plugins
(cd provider && go build $(PULUMI_PROVIDER_BUILD_PARALLELISM) -o $(WORKING_DIR)/bin/$(PROVIDER) -ldflags "-X $(PROJECT)/$(VERSION_PATH)=$(VERSION)" $(PROJECT)/$(PROVIDER_PATH)/cmd/$(PROVIDER))

start-patch: upstream
ifeq ("$(wildcard upstream)","")
@echo "No upstream found, so upstream can't be patched"
@exit 1
else
# To add an additional patch:
#
# 1. Run this command (`make start-patch`).
#
# 2. Edit the `upstream` repo, making whatever changes you want to appear in the new
# patch. It's fine to edit multiple files.
#
# 3. Commit your changes. The slugified first line of your commit description will
# be used to generate the patch file name. Only the diff from the latest commit will
# end up in the final patch.
#
# 4. Run `make finish-patch`.
#
# It is safe to run `make start-patch` as many times as you want, but any changes
# might be reverted until `make finish-patch` is run.
@cd upstream && git commit --quiet -m "existing patches"
endif

test:
cd examples && go test -v -tags=all -parallel $(TESTPARALLELISM) -timeout 2h

Expand All @@ -140,25 +112,17 @@ tfgen: install_plugins upstream docs
(cd provider && VERSION=$(VERSION) go generate cmd/$(PROVIDER)/main.go)

upstream:
ifeq ("$(wildcard upstream)","")
# upstream doesn't exist, so skip
else ifeq ("$(wildcard patches/*.patch)","")
# upstream exists, but patches don't exist. This is probably an error.
@echo "No patches found within the patch operation"
@echo "patches were expected because upstream exists"
@exit 1
else
# Checkout the submodule at the pinned commit.
# `--force`: If the submodule is at a different commit, move it to the pinned commit.
# `--init`: If the submodule is not initialized, initialize it.
git submodule update --force --init
# Iterating over the patches folder in sorted order,
# apply the patch using a 3-way merge strategy. This mirrors the default behavior of `git merge`
cd upstream && \
for patch in $(sort $(wildcard patches/*.patch)); do git apply --3way ../$$patch || exit 1; done
ifneq ("$(wildcard upstream)","")
@$(SHELL) ./scripts/upstream.sh "$@" apply
endif

upstream.finalize:
@$(SHELL) ./scripts/upstream.sh "$@" end_rebase

upstream.rebase:
@$(SHELL) ./scripts/upstream.sh "$@" start_rebase

bin/pulumi-java-gen:
$(shell pulumictl download-binary -n pulumi-language-java -v $(JAVA_GEN_VERSION) -r pulumi/pulumi-java)

.PHONY: development build build_sdks install_go_sdk install_java_sdk install_python_sdk install_sdks only_build build_dotnet build_go build_java build_nodejs build_python clean cleanup docs finish-patch help install_dotnet_sdk install_nodejs_sdk install_plugins lint_provider provider start-patch test tfgen upstream
.PHONY: development build build_sdks install_go_sdk install_java_sdk install_python_sdk install_sdks only_build build_dotnet build_go build_java build_nodejs build_python clean cleanup docs help install_dotnet_sdk install_nodejs_sdk install_plugins lint_provider provider test tfgen upstream upstream.finalize upstream.rebase
193 changes: 193 additions & 0 deletions scripts/upstream.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
# WARNING: This file is autogenerated - changes will be overwritten if not made via https://github.com/pulumi/ci-mgmt

set -e

# $1 is the current make command being run.
# It is used to make the error message more actionable.
err_rebase_in_progress() {
cat <<EOF
A rebase is already in progress. To finish the current rebase,
complete the 'git rebase' in './upstream' and then run:
make upstream.finalize
If you want to abandon the rebase currently in progress and
execute this target anyway, run:
rm rebase-in-progress && make $1
EOF
exit 1
}

assert_upstream() {
if [ ! -d upstream ]; then
echo "No upstream directory detected. $1 does not make sense in this context."
exit 1
fi
}

rebase_in_progress() {
[ -f rebase-in-progress ]
return $?
}

# $1 is the current make command being run.
# It is used to make the error message more actionable.
assert_no_rebase_in_progress() {
if rebase_in_progress; then
err_rebase_in_progress $1
fi
}

message_rebase_clean() {
cat <<EOF
The full patch set has been cleanly applied to the './upstream' repository.
To "edit" the patch set, commit changes directly to './upstream'. When
you are done making changes, run:
make upstream.finalize
to finish the rebase and commit those changes into the patch set.
EOF
}

message_rebase_dirty() {
cat <<EOF
The patch set did not apply cleanly. You need to manually resolve
rebase conflicts directly in './upstream'. When you have completed
the rebase, run
make upstream.finalize
This will finalize the changes you made back into the patch set.
EOF
}

# $1 is the current make command being run.
# It is used to make the error message more actionable.
start_rebase() {
assert_upstream
assert_no_rebase_in_progress $1

git submodule update --force --init
rm -rf .git/modules/upstream/rebase-merge
cd upstream && git fetch

if [ -z "$TO" ]; then
echo '$TO not set, assuming TO is the upstream SHAH currently committed.'
else
git checkout "$TO"
fi

git checkout -B pulumi-patch ${FROM}
git branch --set-upstream-to=local pulumi-patch

for patch in ../patches/*.patch; do
echo "Applying $patch"
if ! git apply --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
patch=${patch#../patches/*-}
git commit -am "${patch%.patch}"
done

touch ../rebase-in-progress

if git rebase local; then
message_rebase_clean
else
message_rebase_dirty
fi
}

# $1 is the current make command being run.
# It is used to make the error message more actionable.
assert_rebase_in_progress() {
if ! rebase_in_progress; then
cat <<EOF
Didn't detect an upstream rebase in progress.
To start an upstream rebase, run
[FROM=vX.Y.Z] [TO=vA.B.C] make upstream.rebase
If you are absolutly sure you are already in a rebase, run
touch rebase-in-progress && make $1
EOF
exit 1
fi
}

# $1 is the current make command being run.
# It is used to make the error message more actionable.
apply() {
assert_upstream
assert_no_rebase_in_progress $1

git submodule update --force --init
# Iterating over the patches folder in sorted order,
# apply the patch using a 3-way merge strategy. This mirrors the default behavior of 'git merge'
cd upstream
for patch in ../patches/*.patch; do
if ! git apply --3way $patch; then
cat <<EOF
make $1' failed to apply a patch. This is because there is a conflict between
the checked out version of upstream and the patch set. To resolve this conflict
run:
FROM=$(echo '$LAST_KNOWN_GOOD_COMMIT') make upstream.rebase
This will walk you through resolving the conflict and producing a patch set that
cleanly applies to the current upstream.
EOF
exit 1
fi
done
}

# $1 is the current make command being run.
# It is used to make the error message more actionable.
end_rebase() {
assert_rebase_in_progress $1

if [ -d .git/modules/upstream/rebase-merge ]; then
echo "rebase still in progress in './upstream'. Please resolve the rebase in"
echo "'./upstream' and then run 'make $1' again."
exit 1
fi

rm patches/*.patch
cd upstream
git format-patch local -o ../patches
rm ../rebase-in-progress
}

case $2 in
apply)
apply $1
;;
start_rebase)
start_rebase $1
;;
end_rebase)
end_rebase $1
;;
*)
cat <<EOF
Unknown argument $2.
Expected convention ./scripts/upstream.sh $@ [apply|start_rebase|end_rebase]
EOF
;;
esac

0 comments on commit e0b3e39

Please sign in to comment.