Skip to content

Commit

Permalink
add programs and content scripts (#11419)
Browse files Browse the repository at this point in the history
  • Loading branch information
sean1588 committed May 14, 2024
1 parent 5e859bd commit 0f32a0e
Show file tree
Hide file tree
Showing 8 changed files with 490 additions and 1 deletion.
36 changes: 35 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,38 @@ serve-all:

.PHONY: build-assets
build-assets:
yarn --cwd ./theme run build
yarn --cwd ./theme run build

.PHONY: test
test:
$(MAKE) test-programs

.PHONY: test-programs
test-programs:
./scripts/programs/test.sh preview

.PHONY: upgrade-programs
upgrade-programs:
./scripts/programs/upgrade.sh

.PHONY: new-learn-module
new-learn-module:
./scripts/content/new-learn-module.sh

.PHONY: new-learn-topic
new-learn-topic:
./scripts/content/new-learn-topic.sh

.PHONY: new-template
new-template:
./scripts/content/new-template.sh

.PHONY: new-example-program
new-example-program:
./scripts/content/new-example-program.sh

.PHONY: new-blog-post
new-blog-post:
hugo new --kind blog-post --contentDir content \
"blog/$(shell bash -c 'read -p "Slug (e.g., 'my-new-post'): " slug; echo $$slug')"

99 changes: 99 additions & 0 deletions scripts/content/new-example-program.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/bash

set -o errexit -o pipefail

source ./scripts/common.sh
source ./scripts/programs/common.sh

cloud=""
example_name=""
example_description=""
examples_dir="static/programs"

prompt_for_cloud() {
read -p "Cloud (e.g., aws): " cloud

if [[ ! -z "$cloud" ]]; then
return
fi

echo "Enter a cloud name that exists in pulumi/templates, like 'aws-native' or 'scaleway'."
echo
prompt_for_cloud
}

prompt_for_example_name() {
read -p "Example name (e.g., awsx-apigateway-lambda): " example_name

if [ ! -z "$example_name" ]; then
return
fi

echo "Please give the example a name."
prompt_for_example_name
}

prompt_for_example_description() {
read -p "Example description (e.g., 'An example that deploys an API Gateway REST API on AWS.'): " example_description

if [ ! -z "$example_description" ]; then
return
fi

echo "Please give the example a description."
prompt_for_example_description
}

generate_example() {
languages=(javascript typescript python go csharp java yaml)
echo

for language in "${languages[@]}"; do
example_dir="${examples_dir}/${example_name}-${language}"

rm -rf "${example_dir}"
mkdir -p "${example_dir}"

pushd "$example_dir" > /dev/null
echo "Creating ${example_dir} ..."
pulumi new "${cloud}-${language}" --description="${example_description}" --yes --force --generate-only > /dev/null
pulumi install > /dev/null
popd > /dev/null
done

unsuffix_gomods
}

echo
echo "So, you want to make a new example program? Awesome! 🙌"
echo
echo "Step 1: Choose a cloud. Your example will be built from an existing Pulumi template,
so choose a cloud/provider that we have an existing <cloud>-<language> template for, like
'aws', 'azure', 'gcp', or 'digitalocean'."
echo
prompt_for_cloud

echo
echo "Step 2: Give the example a descriptive, Pulumi project-friendly name. This name will
be used for the project prefix. Try to choose a name that succinctly describes the content
of the example, rather than the specific page you're building it for, as this'll make the
example more easily findable and reusable."
echo
prompt_for_example_name

echo
echo "Step 3: Give the example a project description. This will be used for the description
field in Pulumi.yaml."
echo
prompt_for_example_description

generate_example
echo
echo "✨ Done! Your new projects are now available at ${examples_dir}/${example_name}. To
include them in any Markdown file (blog post, doc, whatever), use the '{{< example-program >}}'
shortcode thusly:
{{< example-program path=\"${example_name}\" >}}
Enjoy!"
echo
49 changes: 49 additions & 0 deletions scripts/content/new-learn-module.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

set -o errexit -o pipefail

module=""
topic=""

content_dir="content"

prompt_for_module_name() {
read -p "Module name (e.g., pulumi-101-aws): " module

if [ ! -z "$module" ]; then
hugo new --kind learn/module --contentDir "${content_dir}" "learn/${module}"
return
fi

echo "Please give the module a name."
prompt_for_module_name
}

prompt_for_topic_name() {
read -p "Topic name (e.g., basics): " topic

if [ ! -z "$topic" ]; then
hugo new --kind learn/topic --contentDir "${content_dir}" "learn/${module}/${topic}"
return
fi

echo "Please give the topic a name."
prompt_for_topic_name
}

echo "So, you want to make a new Learn Pulumi module? Awesome! 🙌"
echo
echo "Step 1:"
echo "First, give the module a URL- and SEO-friendly name.
For example, to create a new module that'll live at
https://pulumi.com/learn/pulumi-101, type 'pulumi-101'."
echo
prompt_for_module_name

echo
echo "Step 2:"
echo "Now give your new module at least one new topic, also expressed
as a URL-friendly name. For example, to create a new topic under ${module}
that'll live at https://pulumi.com/learn/${module}/basics, type 'basics'."
echo
prompt_for_topic_name
47 changes: 47 additions & 0 deletions scripts/content/new-learn-topic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

set -o errexit -o pipefail

module=""
topic=""
content_dir="content"

prompt_for_module_name() {
read -p "Module name (e.g., pulumi-101-aws): " module

if [[ ! -z "$module" && -d "${content_dir}/learn/${module}" ]]; then
return
fi

echo "Couldn't find a module with that name. Make sure you're using the path as listed under content/learn."
echo
prompt_for_module_name
}

prompt_for_topic_name() {
read -p "Topic name (e.g., basics): " topic

if [ ! -z "$topic" ]; then
hugo new --kind learn/topic --contentDir "${content_dir}" "learn/${module}/${topic}"
return
fi

echo "Please give the topic a name."
echo
prompt_for_topic_name
}

echo "So, you want to make a new Learn Pulumi topic? Great! 🙌"
echo
echo "Step 1:"
echo "What is the path name of the module you want to write for?"
echo
prompt_for_module_name

echo
echo "Step 2:"
echo "Now give your new topic a URL-friendly name. For example, to
create a new topic under ${module} that'll live at
https://pulumi.com/learn/${module}/basics, type 'basics'."
echo
prompt_for_topic_name
58 changes: 58 additions & 0 deletions scripts/content/new-template.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

set -o errexit -o pipefail

type=""
template=""
content_dir="content"

prompt_for_template_type() {
read -p "Template type (e.g., static-website): " type

if [[ ! -z "$type" && -d "${content_dir}/templates/${type}" ]]; then
return
fi

create_template_type
}

create_template_type() {
echo
read -e -p "Template type '${type}' doesn't exist in '${content_dir}/templates'. Create it [y/n]? " choice

if [[ "$choice" == [Yy]* ]]; then
hugo new --kind templates/type --contentDir "${content_dir}" "templates/${type}"
return
fi

echo "Ok, exiting."
exit 0
}

prompt_for_template_name() {
read -p "Template name (e.g., azure): " template

if [ ! -z "$template" ]; then
hugo new --kind templates/template --contentDir "${content_dir}" "templates/${type}/${template}"
return
fi

echo "Please give the template a name."
echo
prompt_for_template_name
}

echo "So, you want to make a new Pulumi template? Great! 🙌"
echo
echo "Step 1:"
echo "What type of template would you like to create?"
echo
prompt_for_template_type

echo
echo "Step 2:"
echo "Now give your new template a URL-friendly name. For example, to
create a new template under ${type} that'll live at
https://pulumi.com/templates/${type}/azure, type 'azure'."
echo
prompt_for_template_name && echo && echo "Done! You can now run 'make serve' to get started."
32 changes: 32 additions & 0 deletions scripts/programs/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

suffix_gomods() {
for file in $(find ./static/programs/* -name 'go.mod' -not -path "**/node_modules/**")
do
cp $file $(echo "$file" | sed -r 's|.mod|.mod.txt|g')
done
}

unsuffix_gomods() {
for file in $(find ./static/programs/* -name 'go.mod.txt' -not -path "**/node_modules/**" )
do
cp $file $(echo "$file" | sed -r 's|.mod.txt|.mod|g')
done
}

clean_gomods() {
local requires=0
local i=0

for file in $(find ./static/programs/* -name 'go.mod*' -not -path "**/node_modules/**" )
do
new_file="$(cat $file)"
split_at="$(awk '/require/{i++; if (i==2) { print NR-1; exit }}' $file)"

if [[ "$split_at" != "" ]]; then
new_file="$(cat $file | head -n $split_at)"
fi

echo "$new_file" > "$file"
done
}
Loading

0 comments on commit 0f32a0e

Please sign in to comment.