Skip to content

Commit

Permalink
Add capability to ignore some examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Nepomuceno committed Aug 27, 2024
1 parent 7a55912 commit 4594b62
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
30 changes: 21 additions & 9 deletions .github/actions/e2e-getexamples/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,27 @@ runs:
- name: get examples
id: getexamples
run: |
# ls -d */ = list directories
# cut -d/ -f1 = strip trailing slash from ls output
# jq -R -s -c 'split("\n")[:-1]') = creates JSON array:
# -R treats the input as string instead of JSON
# -s joins all lines into an array
# -c creates a compact output
# [:-1] removes the last empty string in the output array
DIRS="$(ls -d */ | cut -d/ -f1 | jq -R -s -c 'split("\n")[:-1]')"
# Set output
# Loop through all directories (*/ means all directories ending with a /)
DIRS=$(for dir in */; do
# Check if the directory does NOT contain a .e2eignore file
if [ ! -f "$dir/.e2eignore" ]; then
# If the directory does not have a .e2eignore file, include it in the output
echo "$dir"
fi
done |
# Remove the trailing slash from each directory name
# -d/ specifies the delimiter as "/"
# -f1 selects the first field before the delimiter, which is the directory name
cut -d/ -f1 |
# Convert the list of directory names to a JSON array
# -R treats the input as raw strings instead of JSON
# -s slurps all lines into a single string
# -c generates a compact JSON output
# 'split("\n")[:-1]' splits the input into an array based on newline characters
# and [:-1] removes the last empty string caused by a trailing newline
jq -R -s -c 'split("\n")[:-1]')
# Set output for GitHub Actions using the $GITHUB_OUTPUT variable
echo examples="$DIRS" >> "$GITHUB_OUTPUT"
working-directory: examples
shell: bash
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
- Create a `_header.md` file in each directory to describe the example.
- See the `default` example provided as a skeleton - this must remain, but you can add others.
- Run `make fmt && make docs` from the repo root to generate the required documentation.
- If you want an example to be ignored by the end to end pipeline add a `.e2eignore` file to the example directory.

> **Note:** Examples must be deployable and idempotent. Ensure that no input variables are required to run the example and that random values are used to ensure unique resource names. E.g. use the [naming module](https://registry.terraform.io/modules/Azure/naming/azurerm/latest) to generate a unique name for a resource.

0 comments on commit 4594b62

Please sign in to comment.