Skip to content
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
51 changes: 51 additions & 0 deletions .github/workflows/test-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,68 @@ jobs:
- name: Test
uses: ./terraform-test
id: test
env:
TERRAFORM_VERSION: 1.10.0
with:
path: tests/workflows/test-test/local

- name: Check Passed
env:
FAILURE_REASON: ${{ steps.test.outputs.failure-reason }}
JUNIT_XML_PATH: ${{ steps.test.outputs.junit-xml-path }}
run: |
if [[ "$FAILURE_REASON" != "" ]]; then
echo "::error:: failure-reason not set correctly"
exit 1
fi
if [[ "$JUNIT_XML_PATH" != "" ]]; then
echo "::error:: junit-xml-path should not be set"
exit 1
fi
junit:
runs-on: ubuntu-24.04
name: Junit support
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Test
uses: ./terraform-test
id: test
env:
TERRAFORM_VERSION: 1.11.0
with:
path: tests/workflows/test-test/local

- name: Check Passed
env:
FAILURE_REASON: ${{ steps.test.outputs.failure-reason }}
JUNIT_XML_PATH: ${{ steps.test.outputs.junit-xml-path }}
run: |
if [[ "$FAILURE_REASON" != "" ]]; then
echo "::error:: failure-reason not set correctly"
exit 1
fi
if [[ "$JUNIT_XML_PATH" == "" ]]; then
echo "::error:: junit-xml-path should be set"
exit 1
fi
# Check the output looks right
if [[ ! -f "$JUNIT_XML_PATH" ]]; then
echo "::error:: junit-xml-path does not point to a file"
exit 1
fi
if [[ "$(grep -c '<testsuites' "$JUNIT_XML_PATH")" -ne 1 ]]; then
echo "::error:: junit-xml-path does not contain a testsuites tag"
exit 1
fi
filter:
runs-on: ubuntu-24.04
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ jobs:
run: |
echo "The terraform version was $DETECTED_TERRAFORM_VERSION"
if [[ "$DETECTED_TERRAFORM_VERSION" != *"1.10"* ]]; then
if [[ "$DETECTED_TERRAFORM_VERSION" != *"1.11"* ]]; then
echo "::error:: Latest version was not used"
exit 1
fi
Expand Down
10 changes: 7 additions & 3 deletions docs-gen/action.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import textwrap
from dataclasses import dataclass, field
from textwrap import indent
from typing import Callable
from typing import Callable, Type


def heading(text: str, level: int=1) -> str:
Expand Down Expand Up @@ -95,6 +95,7 @@ class Output:
type: str = None
aliases: list[str] = field(default_factory=list)
meta_output: bool = False
available_in: list[Type[Terraform] | Type[OpenTofu]] = field(default_factory=lambda: [Terraform, OpenTofu])

def markdown(self, tool: Tool) -> str:
if self.meta_output:
Expand Down Expand Up @@ -182,6 +183,7 @@ def assert_ordering(self):
"plan_path",
"json_plan_path",
"text_plan_path",
"junit-xml-path",
"to_add",
"failure-reason",
"lock-info",
Expand Down Expand Up @@ -231,6 +233,8 @@ def markdown(self, tool: Tool) -> str:
s += text_chunk(self.outputs_intro)

for output in self.outputs:
if tool not in output.available_in:
continue
s += text_chunk(output.markdown(tool))

if self.environment_variables:
Expand Down Expand Up @@ -273,10 +277,10 @@ def action_yaml(self, tool: Tool) -> str:

s += '\n'

if [output for output in self.outputs if not output.meta_output]:
if [output for output in self.outputs if not output.meta_output and tool in output.available_in]:
s += 'outputs:\n'

for output in self.outputs:
for output in (output for output in self.outputs if not output.meta_output and tool in output.available_in):
if output.meta_output:
continue

Expand Down
2 changes: 2 additions & 0 deletions docs-gen/actions/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from inputs.var_file import var_file
from inputs.variables import variables
from outputs.failure_reason import failure_reason
from outputs.junit_xml import junit_xml_path

test = Action(
'test',
Expand All @@ -31,6 +32,7 @@
var_file
],
outputs=[
junit_xml_path,
dataclasses.replace(failure_reason, description='''
When the job outcome is `failure`, this output may be set. The value may be one of:
Expand Down
14 changes: 14 additions & 0 deletions docs-gen/outputs/junit_xml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from action import Output, Terraform

junit_xml_path = Output(
name='junit-xml-path',
type='string',
description='''
A test report in JUnit XML format.
The path is relative to the Actions workspace.
This will only be available when using Terraform 1.11.0 or later.
''',
available_in = [Terraform]
)
10 changes: 10 additions & 0 deletions image/entrypoints/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ function set-test-args() {
TEST_ARGS="$TEST_ARGS -filter=$file"
done
fi

if [[ "$TOOL_COMMAND_NAME" == "terraform" && $TERRAFORM_VER_MAJOR -ge 1 && $TERRAFORM_VER_MINOR -ge 11 ]]; then
TEST_ARGS="$TEST_ARGS -junit-xml=$STEP_TMP_DIR/test-result.xml"
fi
}

function test() {
Expand All @@ -45,6 +49,12 @@ function test() {

cat "$STEP_TMP_DIR/terraform_test.stderr"

if [[ -f "$STEP_TMP_DIR/test-result.xml" ]]; then
mkdir -p "$GITHUB_WORKSPACE/$WORKSPACE_TMP_DIR"
cp "$STEP_TMP_DIR/test-result.xml" "$GITHUB_WORKSPACE/$WORKSPACE_TMP_DIR/test-result.xml"
set_output junit-xml-path "$WORKSPACE_TMP_DIR/test-result.xml"
fi

if [[ $TEST_EXIT -eq 0 ]]; then
# Workaround a bit of stupidity in the terraform test command
if grep -q "Success! 0 passed, 0 failed." "$STEP_TMP_DIR/terraform_test.stdout"; then
Expand Down
10 changes: 10 additions & 0 deletions terraform-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ If the tests fail, the job will stop with a failure status.

## Outputs

* `junit-xml-path`

A test report in JUnit XML format.

The path is relative to the Actions workspace.

This will only be available when using Terraform 1.11.0 or later.

- Type: string

* `failure-reason`

When the job outcome is `failure`, this output may be set. The value may be one of:
Expand Down
7 changes: 7 additions & 0 deletions terraform-test/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ inputs:
required: false

outputs:
junit-xml-path:
description: |
A test report in JUnit XML format.
The path is relative to the Actions workspace.
This will only be available when using Terraform 1.11.0 or later.
failure-reason:
description: |
When the job outcome is `failure`, this output may be set. The value may be one of:
Expand Down
Loading