Skip to content

Commit

Permalink
configure upstream script and upgrade plugin workflows
Browse files Browse the repository at this point in the history
Signed-off-by: ocobleseqx <[email protected]>
  • Loading branch information
ocobles committed Oct 26, 2023
1 parent 694d2d2 commit 7b74315
Show file tree
Hide file tree
Showing 12 changed files with 406 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/community-moderation.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# WARNING: This file was build based on https://github.com/pulumi/ci-mgmt
# but it is currently not in sync. Any updates may be done manually
# but it is currently not in sync. Any update must be done manually

name: warn-codegen
on:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# WARNING: This file was build based on https://github.com/pulumi/ci-mgmt
# but it is currently not in sync. Any updates may be done manually
# but it is currently not in sync. Any update must be done manually

name: lint
on:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-acceptance-tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# WARNING: This file was build based on https://github.com/pulumi/ci-mgmt
# but it is currently not in sync. Any updates may be done manually
# but it is currently not in sync. Any update must be done manually

name: run-acceptance-tests
on:
Expand Down
85 changes: 85 additions & 0 deletions .github/workflows/upgrade-bridge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# WARNING: This file was build based on https://github.com/pulumi/ci-mgmt
# but it is currently not in sync. Any update must be done manually

name: Upgrade bridge
on:
repository_dispatch:
types:
- upgrade-bridge
workflow_dispatch:
inputs:
target-bridge-version:
description: pulumi-terraform-bridge version or hash reference
required: false
type: string
default: "latest"
pr-reviewers:
description: Reviewers to assign to the auto-opened pull request
required: false
type: string
default: ""
pr-description:
description: Extra description to add to the auto-opened pull request
required: false
type: string
default: ""
automerge:
description: Mark created PR for auto-merging?
required: false
type: boolean
default: false
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
upgrade_provider:
name: upgrade-provider
runs-on: ubuntu-latest
steps:
- name: Call upgrade provider action
if: github.event_name == 'workflow_dispatch'
uses: pulumi/[email protected]
with:
kind: bridge
email: [email protected]
username: GitHub
automerge: ${{ inputs.automerge }}
target-bridge-version: ${{ inputs.target-bridge-version }}
pr-reviewers: ${{ inputs.pr-reviewers }}
pr-description: ${{ inputs.pr-description }}
- name: Call upgrade provider action
if: github.event_name == 'repository_dispatch'
uses: pulumi/[email protected]
with:
kind: bridge
email: [email protected]
username: GitHub
automerge: ${{ github.event.client_payload.automerge }}
target-bridge-version: ${{ github.event.client_payload.target-bridge-version }}
pr-reviewers: ${{ github.event.client_payload.pr-reviewers }}
pr-description: ${{ github.event.client_payload.pr-description }}
## TODO
# - env:
# SLACK_CHANNEL: provider-upgrade-publish-status
# SLACK_COLOR: "#7CFC00"
# SLACK_ICON_EMOJI: ":taco:"
# SLACK_MESSAGE: >-
# Upgrade succeeded :heart_decoration:

# PR opened at github.com/pulumi/${{ github.event.repository.name }}/pulls
# SLACK_TITLE: ${{ github.event.repository.name }} upgrade result
# SLACK_USERNAME: provider-bot
# SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
# name: Send Upgrade Success To Slack
# uses: rtCamp/action-slack-notify@v2
# - env:
# SLACK_CHANNEL: provider-upgrade-publish-status
# SLACK_COLOR: "#FF0000"
# SLACK_ICON_EMOJI: ":taco:"
# SLACK_MESSAGE: " Upgrade failed :x:"
# SLACK_TITLE: ${{ github.event.repository.name }} upgrade result
# SLACK_USERNAME: provider-bot
# SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
# if: failure()
# name: Send Upgrade Failure To Slack
# uses: rtCamp/action-slack-notify@v2
43 changes: 43 additions & 0 deletions .github/workflows/upgrade-provider.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# WARNING: This file was build based on https://github.com/pulumi/ci-mgmt
# but it is currently not in sync. Any update must be done manually

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
upgrade_provider:
if: ${{ contains(github.event.issue.title, 'Upgrade terraform-provider-') || github.event_name == 'workflow_dispatch' }}
name: upgrade-provider
runs-on: ubuntu-latest
steps:
- name: Call upgrade provider action
uses: pulumi/[email protected]
with:
kind: all
email: [email protected]
username: GitHub
## TODO
# - env:
# SLACK_CHANNEL: provider-upgrade-publish-status
# SLACK_COLOR: "#7CFC00"
# SLACK_ICON_EMOJI: ":taco:"
# SLACK_MESSAGE: >-
# Upgrade succeeded :heart_decoration:

# PR opened at github.com/pulumi/${{ github.event.repository.name }}/pulls
# SLACK_TITLE: ${{ github.event.repository.name }} upgrade result
# SLACK_USERNAME: provider-bot
# SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
# name: Send Upgrade Success To Slack
# uses: rtCamp/action-slack-notify@v2
# - env:
# SLACK_CHANNEL: provider-upgrade-publish-status
# SLACK_COLOR: "#FF0000"
# SLACK_ICON_EMOJI: ":taco:"
# SLACK_MESSAGE: " Upgrade failed :x:"
# SLACK_TITLE: ${{ github.event.repository.name }} upgrade result
# SLACK_USERNAME: provider-bot
# SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
# if: failure()
# name: Send Upgrade Failure To Slack
# uses: rtCamp/action-slack-notify@v2
8 changes: 8 additions & 0 deletions .upgrade-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# WARNING: This file was build based on https://github.com/pulumi/ci-mgmt
# but it is currently not in sync. Any update must be done manually

---
upstream-provider-name: terraform-provider-equinix
remove-plugins: true
pr-reviewers: equinix/governor-devrel-engineering
javaVersion: "v0.9.5"
111 changes: 56 additions & 55 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,68 +25,48 @@ WORKING_DIR := $(shell pwd)
OS := $(shell uname)
EMPTY_TO_AVOID_SED := ""

prepare::
@if test -z "${NAME}"; then echo "NAME not set"; exit 1; fi
@if test -z "${REPOSITORY}"; then echo "REPOSITORY not set"; exit 1; fi
@if test ! -d "provider/cmd/pulumi-tfgen-x${EMPTY_TO_AVOID_SED}yz"; then "Project already prepared"; exit 1; fi

mv "provider/cmd/pulumi-tfgen-x${EMPTY_TO_AVOID_SED}yz" provider/cmd/pulumi-tfgen-${NAME}
mv "provider/cmd/pulumi-resource-x${EMPTY_TO_AVOID_SED}yz" provider/cmd/pulumi-resource-${NAME}

if [[ "${OS}" != "Darwin" ]]; then \
sed -i 's,github.com/pulumi/pulumi-equinix,${REPOSITORY},g' provider/go.mod; \
find ./ ! -path './.git/*' -type f -exec sed -i 's/[x]yz/${NAME}/g' {} \; &> /dev/null; \
fi

# In MacOS the -i parameter needs an empty string to execute in place.
if [[ "${OS}" == "Darwin" ]]; then \
sed -i '' 's,github.com/pulumi/pulumi-equinix,${REPOSITORY},g' provider/go.mod; \
find ./ ! -path './.git/*' -type f -exec sed -i '' 's/[x]yz/${NAME}/g' {} \; &> /dev/null; \
fi

.PHONY: development provider build_sdks build_nodejs build_dotnet build_go build_python build_java clean cleanup

development:: install_plugins provider lint_provider build_sdks install_sdks cleanup # Build the provider & SDKs for a development environment
development: install_plugins provider lint_provider build_sdks install_sdks cleanup # Build the provider & SDKs for a development environment

# Required for the codegen action that runs in pulumi/pulumi and pulumi/pulumi-terraform-bridge
build:: install_plugins provider build_sdks install_sdks
only_build:: build
build: install_plugins provider build_sdks install_sdks
only_build: build

tfgen:: install_plugins
tfgen: install_plugins upstream
(cd provider && go build -o $(WORKING_DIR)/bin/${TFGEN} -ldflags "-X ${PROJECT}/${VERSION_PATH}=${VERSION}" ${PROJECT}/${PROVIDER_PATH}/cmd/${TFGEN})
$(WORKING_DIR)/bin/${TFGEN} schema --out provider/cmd/${PROVIDER}
(cd provider && VERSION=$(VERSION) go generate cmd/${PROVIDER}/main.go)

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

provider:: tfgen install_plugins # build the provider binary
provider: tfgen install_plugins # build the provider binary
(cd provider && go build -o $(WORKING_DIR)/bin/${PROVIDER} -ldflags "-X ${PROJECT}/${VERSION_PATH}=${VERSION}" ${PROJECT}/${PROVIDER_PATH}/cmd/${PROVIDER})

build_sdks:: install_plugins provider build_nodejs build_python build_go build_dotnet build_java # build all the sdks
build_sdks: build_nodejs build_python build_go build_dotnet build_java # build all the sdks

build_nodejs:: VERSION := $(shell pulumictl get version --language javascript)
build_nodejs:: install_plugins tfgen # build the node sdk
build_nodejs: VERSION := $(shell pulumictl get version --language javascript)
build_nodejs: upstream
$(WORKING_DIR)/bin/$(TFGEN) nodejs --overlays provider/overlays/nodejs --out sdk/nodejs/
build_nodejs:: patch_nodejs # fix generated files
build_nodejs::
build_nodejs: patch_nodejs # fix generated files
build_nodejs:
cd sdk/nodejs/ && \
printf "module fake_nodejs_module // Exclude this directory from Go tools\n\ngo 1.17\n" > go.mod && \
yarn install && \
yarn run tsc && \
cp ../../README.md ../../LICENSE package.json yarn.lock ./bin/ && \
sed -i.bak -e "s/\$${VERSION}/$(VERSION)/g" ./bin/package.json

patch_nodejs::
patch_nodejs:
echo "patch_nodejs: find and replace wrong imports in examples" && \
find ./sdk/nodejs/ -type f -name "*.ts" -not \( -path "*/bin/*" -o -path "*/node_modules/*" -o -path "*/@types/*" \) -print -exec sed -i.bak 's/import \* as ${PACK} from "@pulumi\/${PACK}"/import \* as ${PACK} from "@${ORG}-labs\/${NODE_PACK}"/g; s/import \* as ${NODE_PACK_ALIAS} from "@${ORG}\/${NODE_PACK}"/import \* as ${PACK} from "@${ORG}-labs\/${NODE_PACK}"/g' {} \;
echo "patch_nodejs: delete duplicate imports in examples" && \
find ./sdk/nodejs/ -type f -name "*.ts" -not \( -path "*/bin/*" -o -path "*/node_modules/*" -o -path "*/@types/*" \) -exec sed -i.bak '/@${ORG}-labs\/${NODE_PACK}/N;/^\(.*\)\n\1$$/!P; D' {} \;
echo "patch_nodejs: remove backup files" && \
find ./sdk/nodejs/ -type f -name "*.ts.bak" -not \( -path "*/bin/*" -o -path "*/node_modules/*" -o -path "*/@types/*" \) -print -exec /bin/rm {} \;

build_python:: PYPI_VERSION := $(shell pulumictl get version --language python)
build_python:: install_plugins tfgen # build the python sdk
build_python: PYPI_VERSION := $(shell pulumictl get version --language python)
build_python: upstream
rm -rf sdk/python/
$(WORKING_DIR)/bin/$(TFGEN) python --overlays provider/overlays/python --out sdk/python/
cd sdk/python/ && \
printf "module fake_python_module // Exclude this directory from Go tools\n\ngo 1.17\n" > go.mod && \
Expand All @@ -97,28 +77,28 @@ build_python:: install_plugins tfgen # build the python sdk
rm ./bin/setup.py.bak && \
cd ./bin && python3 setup.py build sdist

build_dotnet:: DOTNET_VERSION := $(shell pulumictl get version --language dotnet)
build_dotnet:: install_plugins tfgen # build the dotnet sdk
build_dotnet: DOTNET_VERSION := $(shell pulumictl get version --language dotnet)
build_dotnet: upstream
pulumictl get version --language dotnet
$(WORKING_DIR)/bin/$(TFGEN) dotnet --overlays provider/overlays/dotnet --out sdk/dotnet/
cd sdk/dotnet/ && \
printf "module fake_dotnet_module // Exclude this directory from Go tools\n\ngo 1.17\n" > go.mod && \
echo "${DOTNET_VERSION}" >version.txt && \
dotnet build /p:Version=${DOTNET_VERSION}

build_go:: install_plugins tfgen # build the go sdk
build_go:: upstream
$(WORKING_DIR)/bin/$(TFGEN) go --overlays provider/overlays/go --out sdk/go/

build_java:: PACKAGE_VERSION := $(shell pulumictl get version --language generic)
build_java:: install_plugins tfgen bin/pulumi-java-gen patch_java_schema # build the java sdk
build_java: PACKAGE_VERSION := $(shell pulumictl get version --language generic)
build_java: bin/pulumi-java-gen patch_java_schema upstream
$(WORKING_DIR)/bin/$(JAVA_GEN) generate --schema provider/cmd/$(PROVIDER)/schema-java.json --out sdk/java --build gradle-nexus
rm -f ./provider/cmd/$(PROVIDER)/schema-java.json
build_java:: patch_java
build_java: patch_java
cd sdk/java/ && \
printf "module fake_java_module // Exclude this directory from Go tools\n\ngo 1.17\n" > go.mod && \
gradle --console=plain build

patch_java_schema::
patch_java_schema:
echo "patch_java_schema: copy schema.json to schema-java.json " && \
cp provider/cmd/$(PROVIDER)/schema.json provider/cmd/$(PROVIDER)/schema-java.json
echo "patch_java_schema: update schema-java.json to generate the SDK with pulumi as root package" && \
Expand All @@ -130,7 +110,7 @@ patch_java_schema::
-e 's/equinix:networkedge/pulumi:networkedge/g' ./provider/cmd/$(PROVIDER)/schema-java.json && \
rm -f ./provider/cmd/$(PROVIDER)/schema-java.json.bak

patch_java::
patch_java:
echo "patch_java: find and replace invocations of pulumi:fabric/metal/networkedge" && \
find ./sdk/java/src/main/java/com/equinix/pulumi -type f -name "*.java" -print -exec sed -i.bak 's/pulumi:fabric/equinix:fabric/g; s/pulumi:metal/equinix:metal/g; s/pulumi:networkedge/equinix:networkedge/g' {} \;
echo "patch_java: remove backup files" && \
Expand All @@ -157,45 +137,66 @@ patch_java::
sed -i.bak -E '/inceptionYear/,/packaging/s/(name = ).*/\1"$(PACK)"/' ./build.gradle && \
rm -f build.gradle.bak

lint_provider:: provider # lint the provider code
lint_provider: provider # lint the provider code
cd provider && golangci-lint run -c ../.golangci.yml

cleanup:: # cleans up the temporary directory
cleanup: # cleans up the temporary directory
rm -r $(WORKING_DIR)/bin
rm -f provider/cmd/${PROVIDER}/schema.go

help::
help:
@grep '^[^.#]\+:\s\+.*#' Makefile | \
sed "s/\(.\+\):\s*\(.*\) #\s*\(.*\)/`printf "\033[93m"`\1`printf "\033[0m"` \3 [\2]/" | \
expand -t20

clean::
clean:
rm -rf sdk/{dotnet,nodejs,go,python,java}

install_plugins::
[ -x $(shell which pulumi) ] || curl -fsSL https://get.pulumi.com | sh
pulumi plugin install resource random 4.3.1
install_plugins: .pulumi/bin/pulumi
.pulumi/bin/pulumi plugin install resource tls 4.11.0
.pulumi/bin/pulumi plugin install resource random 4.14.0

install_dotnet_sdk::
install_dotnet_sdk:
mkdir -p $(WORKING_DIR)/nuget
find . -name '*.nupkg' -print -exec cp -p {} ${WORKING_DIR}/nuget \;

install_python_sdk::
install_python_sdk:

install_go_sdk::
install_go_sdk:

install_java_sdk:

install_nodejs_sdk::
install_nodejs_sdk:
yarn link --cwd $(WORKING_DIR)/sdk/nodejs/bin

install_sdks:: install_dotnet_sdk install_python_sdk install_nodejs_sdk install_java_sdk
install_sdks: install_dotnet_sdk install_python_sdk install_nodejs_sdk install_java_sdk

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

test_provider:
@echo ""
@echo "== test_provider ==================================================================="
@echo ""
cd provider && go test -v -short ./... -parallel $(TESTPARALLELISM)

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

upstream.finalize:
scripts/upstream.sh "$@" end_rebase

upstream.rebase:
scripts/upstream.sh "$@" start_rebase

.pulumi/bin/pulumi: .pulumi/version
curl -fsSL https://get.pulumi.com | HOME=$(WORKING_DIR) sh -s -- --version $(cat .pulumi/version)

# Compute the version of Pulumi to use by inspecting the Go dependencies of the provider.
.pulumi/version:
@mkdir -p .pulumi
@cd provider && go list -f "{{slice .Version 1}}" -m github.com/pulumi/pulumi/pkg/v3 | tee ../$@

.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 help install_dotnet_sdk install_nodejs_sdk install_plugins lint_provider provider test tfgen upstream upstream.finalize upstream.rebase test_provider
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ github.com/golang-jwt/jwt v3.2.1+incompatible h1:73Z+4BJcrTC+KczS6WvTPvRGOp1WmfE
github.com/google/pprof v0.0.0-20230406165453-00490a63f317/go.mod h1:79YE0hCXdHag9sBkw2o+N/YnZtTkXi0UT9Nnixa5eYk=
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
github.com/gruntwork-io/terratest v0.43.0/go.mod h1:vZO4J6UW023NDvl1vI+twZk9r//+QEaNT6MfkheH7z0=
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 h1:1/D3zfFHttUKaCaGKZ/dR2roBXv0vKbSCnssIldfQdI=
github.com/hinshun/vt10x v0.0.0-20220301184237-5011da428d02/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
github.com/ijc/Gotty v0.0.0-20170406111628-a8b993ba6abd/go.mod h1:3LVOLeyx9XVvwPgrt2be44XgSqndprz1G18rSk8KD84=
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a/go.mod h1:yL958EeXv8Ylng6IfnvG4oflryUi3vgA3xPs9hmII1s=
Expand Down
Empty file added patches/README.md
Empty file.
6 changes: 5 additions & 1 deletion provider/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ module github.com/equinix/pulumi-equinix/provider

go 1.21

replace github.com/hashicorp/terraform-plugin-sdk/v2 => github.com/pulumi/terraform-plugin-sdk/v2 v2.0.0-20230912190043-e6d96b3b8f7e
replace (
github.com/hashicorp/go-cty => github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 => github.com/pulumi/terraform-plugin-sdk/v2 v2.0.0-20230912190043-e6d96b3b8f7e
github.com/equinix/terraform-provider-equinix => ../upstream
)

require (
github.com/equinix/terraform-provider-equinix v1.18.0
Expand Down
2 changes: 2 additions & 0 deletions provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ func Provider() tfbridge.ProviderInfo {
// The GitHub Org for the provider - defaults to `terraform-providers`. Note that this
// should match the TF provider module's require directive, not any replace directives.
GitHubOrg: "equinix",
UpstreamRepoPath: "./upstream",
Version: version.Version,
Config: map[string]*tfbridge.SchemaInfo{},
PreConfigureCallback: preConfigureCallback,
// IgnoreMappings is a list of TF resources and data sources to ignore in mappings errors
Expand Down
Loading

0 comments on commit 7b74315

Please sign in to comment.