Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): skip mapping errors when upgrading the Terraform provider #209

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/upgrade-provider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ on:
env:
GH_TOKEN: ${{ secrets.EQUINIX_BOT_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Allow missing or extra mappings during TF provider
# upgrades. This allows automation to do its job so
# that human contributions can be narrowly focused on
# adding or removing resource mappings
PULUMI_SKIP_MISSING_MAPPING_ERROR: true
PULUMI_SKIP_EXTRA_MAPPING_ERROR: true
jobs:
upgrade_provider:
name: upgrade-provider
Expand Down
78 changes: 40 additions & 38 deletions scripts/generate_examples.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
set -ex

# List of terraform examples to exclude
EXCLUDE_TF_EXAMPLES=(
Expand Down Expand Up @@ -114,7 +114,7 @@ generate_pulumi_yaml() {

# Generate Pulumi template
echo -e "\033[0;34m CONVERTING $normalized_path" >&2
.pulumi/bin/pulumi convert --cwd "$resource_dir" --from terraform --language yaml --out $resource_dir --generate-only "${tf_files[0]}"
.pulumi/bin/pulumi convert --cwd "$resource_dir" --from terraform --language yaml --out $resource_dir --generate-only "${tf_files[0]}" || continue
sed -i.bak $'1i\\\n# WARNING: This is an autogenerated file - manual changes will be overwritten if not made via ./scripts/generate_examples.sh\n' "$resource_dir/Pulumi.yaml"
rm "$tf_destination_file" "$resource_dir"/*.bak

Expand Down Expand Up @@ -166,7 +166,7 @@ generate_pulumi_yaml() {

# Execute the Terraform to YAML conversion
echo -e "\033[0;34m CONVERTING $normalized_path" >&2
.pulumi/bin/pulumi convert --cwd "$resource_dir" --from terraform --language yaml --out $resource_dir --generate-only $tf_file
.pulumi/bin/pulumi convert --cwd "$resource_dir" --from terraform --language yaml --out $resource_dir --generate-only $tf_file || continue
sed -i.bak $'1i\\\n# WARNING: This is an autogenerated file - manual changes will be overwritten if not made via ./scripts/generate_examples.sh\n' "$resource_dir/Pulumi.yaml"
rm "$tf_destination_file" "$resource_dir"/*.bak

Expand Down Expand Up @@ -286,38 +286,39 @@ generate_examples_and_docs() {
.pulumi/bin/pulumi convert --cwd "$PULUMI_DIR" --language go --out go || true
.pulumi/bin/pulumi convert --cwd "$PULUMI_DIR" --language csharp --out csharp --generate-only || true

# Fix version constraints
## csharp
for file in "$PULUMI_DIR/csharp"/*.csproj; do
echo $file
sed -i.bak "s|$VERSION|(, 1.0.0)|g" "$file"
done
rm "$PULUMI_DIR"/csharp/*.csproj.bak

## java
sed -i.bak "s|$VERSION|(,1.0)|g" $PULUMI_DIR/java/pom.xml
rm "$PULUMI_DIR"/java/pom.xml.bak
## python
sed -i.bak "s|$VERSION|<1.0.0|g" $PULUMI_DIR/python/requirements.txt
rm "$PULUMI_DIR"/python/requirements.txt.bak
## typescript
sed -i.bak "s|$VERSION|<1.0.0|g" $PULUMI_DIR/typescript/package.json
rm "$PULUMI_DIR"/typescript/package.json.bak
## go
sed -i.bak "s|github.com/equinix/pulumi-equinix/sdk [^ ]*|github.com/equinix/pulumi-equinix/sdk $GOLANG_VERSION|g" "$PULUMI_DIR/go/go.mod"
rm "$PULUMI_DIR"/go/go.sum "$PULUMI_DIR"/go/go.mod.bak

# Read each source file
TS_SRC=$(cat "$PULUMI_DIR/typescript/index.ts")
PY_SRC=$(cat "$PULUMI_DIR/python/__main__.py")
GO_SRC=$(cat "$PULUMI_DIR/go/main.go")
CS_SRC=$(cat "$PULUMI_DIR/csharp/Program.cs")
JAVA_SRC=$(cat "$PULUMI_DIR/java/src/main/java/generated_program/App.java")
# Skip first 3 lines of Pulumi.yaml from the specified directory
YAML_SRC=$(tail -n +4 "$PULUMI_DIR/Pulumi.yaml")

# Generate the markdown in the desired format
OUTPUT=$(cat <<EOF
if [ -z "$(find $PULUMI_DIR/* -empty -type d 2>/dev/null)" ]; then
# Fix version constraints
## csharp
for file in "$PULUMI_DIR/csharp"/*.csproj; do
echo $file
sed -i.bak "s|$VERSION|(, 1.0.0)|g" "$file"
done
rm "$PULUMI_DIR"/csharp/*.csproj.bak

## java
sed -i.bak "s|$VERSION|(,1.0)|g" $PULUMI_DIR/java/pom.xml
rm "$PULUMI_DIR"/java/pom.xml.bak
## python
sed -i.bak "s|$VERSION|<1.0.0|g" $PULUMI_DIR/python/requirements.txt
rm "$PULUMI_DIR"/python/requirements.txt.bak
## typescript
sed -i.bak "s|$VERSION|<1.0.0|g" $PULUMI_DIR/typescript/package.json
rm "$PULUMI_DIR"/typescript/package.json.bak
## go
sed -i.bak "s|github.com/equinix/pulumi-equinix/sdk [^ ]*|github.com/equinix/pulumi-equinix/sdk $GOLANG_VERSION|g" "$PULUMI_DIR/go/go.mod"
rm "$PULUMI_DIR"/go/go.sum "$PULUMI_DIR"/go/go.mod.bak

# Read each source file
TS_SRC=$(cat "$PULUMI_DIR/typescript/index.ts")
PY_SRC=$(cat "$PULUMI_DIR/python/__main__.py")
GO_SRC=$(cat "$PULUMI_DIR/go/main.go")
CS_SRC=$(cat "$PULUMI_DIR/csharp/Program.cs")
JAVA_SRC=$(cat "$PULUMI_DIR/java/src/main/java/generated_program/App.java")
# Skip first 3 lines of Pulumi.yaml from the specified directory
YAML_SRC=$(tail -n +4 "$PULUMI_DIR/Pulumi.yaml")

# Generate the markdown in the desired format
OUTPUT=$(cat <<EOF
## Example Usage
{{% example %}}
\`\`\`typescript
Expand All @@ -342,10 +343,11 @@ $YAML_SRC
EOF
)

# Write out to the generated output file in docs directory
echo "$OUTPUT" > "$OUTPUT_FILE"
# Write out to the generated output file in docs directory
echo "$OUTPUT" > "$OUTPUT_FILE"

echo "Output file generated: $OUTPUT_FILE" >&2
echo "Output file generated: $OUTPUT_FILE" >&2
fi
done
}

Expand Down
Loading