Skip to content

Commit a92d015

Browse files
committed
update action with new setting step
1 parent 832fb00 commit a92d015

1 file changed

Lines changed: 108 additions & 91 deletions

File tree

action.yml

Lines changed: 108 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -88,97 +88,114 @@ runs:
8888

8989
- name: Get atmos settings
9090
id: atmos-settings
91-
uses: cloudposse/github-action-atmos-get-setting@v2
92-
with:
93-
# Here we do not process-templates because that requires terraform. Which we install after fetching the version
94-
# processing templates here can cause an issue where cached terraform versions conflict with the version we want to install
95-
process-templates: 'false'
96-
process-functions: 'false'
97-
settings: |
98-
- component: ${{ inputs.component }}
99-
stack: ${{ inputs.stack }}
100-
settingsPath: settings.github.actions_enabled
101-
outputPath: github-actions-enabled
102-
- component: ${{ inputs.component }}
103-
stack: ${{ inputs.stack }}
104-
settingsPath: settings.pro.enabled
105-
outputPath: atmos-pro-enabled
106-
- component: ${{ inputs.component }}
107-
stack: ${{ inputs.stack }}
108-
settingsPath: component_info.component_path
109-
outputPath: component-path
110-
- component: ${{ inputs.component }}
111-
stack: ${{ inputs.stack }}
112-
settingsPath: atmos_cli_config.base_path
113-
outputPath: base-path
114-
- component: ${{ inputs.component }}
115-
stack: ${{ inputs.stack }}
116-
settingsPath: command
117-
outputPath: command
118-
- component: ${{ inputs.component }}
119-
stack: ${{ inputs.stack }}
120-
settingsPath: settings.integrations.github.gitops.opentofu-version
121-
outputPath: opentofu-version
122-
- component: ${{ inputs.component }}
123-
stack: ${{ inputs.stack }}
124-
settingsPath: settings.integrations.github.gitops.terraform-version
125-
outputPath: terraform-version
126-
- component: ${{ inputs.component }}
127-
stack: ${{ inputs.stack }}
128-
settingsPath: settings.integrations.github.gitops.infracost-enabled
129-
outputPath: enable-infracost
130-
- component: ${{ inputs.component }}
131-
stack: ${{ inputs.stack }}
132-
settingsPath: settings.integrations.github.gitops.role.plan
133-
outputPath: terraform-plan-role
134-
- component: ${{ inputs.component }}
135-
stack: ${{ inputs.stack }}
136-
settingsPath: settings.integrations.github.gitops.role.apply
137-
outputPath: terraform-apply-role
138-
- component: ${{ inputs.component }}
139-
stack: ${{ inputs.stack }}
140-
settingsPath: settings.integrations.github.gitops.artifact-storage.region
141-
outputPath: aws-region
142-
- component: ${{ inputs.component }}
143-
stack: ${{ inputs.stack }}
144-
settingsPath: settings.integrations.github.gitops.artifact-storage.role
145-
outputPath: terraform-state-role
146-
- component: ${{ inputs.component }}
147-
stack: ${{ inputs.stack }}
148-
settingsPath: settings.integrations.github.gitops.artifact-storage.table
149-
outputPath: terraform-state-table
150-
- component: ${{ inputs.component }}
151-
stack: ${{ inputs.stack }}
152-
settingsPath: settings.integrations.github.gitops.artifact-storage.bucket
153-
outputPath: terraform-state-bucket
154-
- component: ${{ inputs.component }}
155-
stack: ${{ inputs.stack }}
156-
settingsPath: settings.integrations.github.gitops.artifact-storage.plan-repository-type
157-
outputPath: plan-repository-type
158-
- component: ${{ inputs.component }}
159-
stack: ${{ inputs.stack }}
160-
settingsPath: settings.integrations.github.gitops.artifact-storage.blob-account-name
161-
outputPath: blob-account-name
162-
- component: ${{ inputs.component }}
163-
stack: ${{ inputs.stack }}
164-
settingsPath: settings.integrations.github.gitops.artifact-storage.blob-container-name
165-
outputPath: blob-container-name
166-
- component: ${{ inputs.component }}
167-
stack: ${{ inputs.stack }}
168-
settingsPath: settings.integrations.github.gitops.artifact-storage.metadata-repository-type
169-
outputPath: metadata-repository-type
170-
- component: ${{ inputs.component }}
171-
stack: ${{ inputs.stack }}
172-
settingsPath: settings.integrations.github.gitops.artifact-storage.cosmos-container-name
173-
outputPath: cosmos-container-name
174-
- component: ${{ inputs.component }}
175-
stack: ${{ inputs.stack }}
176-
settingsPath: settings.integrations.github.gitops.artifact-storage.cosmos-database-name
177-
outputPath: cosmos-database-name
178-
- component: ${{ inputs.component }}
179-
stack: ${{ inputs.stack }}
180-
settingsPath: settings.integrations.github.gitops.artifact-storage.cosmos-endpoint
181-
outputPath: cosmos-endpoint
91+
shell: bash
92+
run: |
93+
set -euo pipefail
94+
95+
echo "Starting Atmos settings retrieval for component: ${{ inputs.component }} in stack: ${{ inputs.stack }}"
96+
97+
# Check if jq is available
98+
if ! command -v jq &> /dev/null; then
99+
echo "Error: jq is not installed. Please ensure jq is available in the runner."
100+
exit 1
101+
fi
102+
103+
# Check if atmos is available
104+
if ! command -v atmos &> /dev/null; then
105+
echo "Error: atmos is not installed or not in PATH."
106+
exit 1
107+
fi
108+
109+
echo "Executing atmos describe component command..."
110+
111+
# Execute atmos describe component with timeout and error handling
112+
COMPONENT_CONFIG=""
113+
if ! COMPONENT_CONFIG=$(timeout 300 atmos describe component "${{ inputs.component }}" \
114+
-s "${{ inputs.stack }}" \
115+
--format=json \
116+
--process-templates=false \
117+
--process-functions=false \
118+
--skip=terraform.output 2>&1); then
119+
120+
echo "Error: atmos describe component command failed or timed out after 5 minutes"
121+
echo "Command output: $COMPONENT_CONFIG"
122+
exit 1
123+
fi
124+
125+
# Validate that we got output
126+
if [[ -z "$COMPONENT_CONFIG" ]]; then
127+
echo "Error: Component configuration not found for component: ${{ inputs.component }} in stack: ${{ inputs.stack }}"
128+
exit 1
129+
fi
130+
131+
# Check if output is valid JSON
132+
if ! echo "$COMPONENT_CONFIG" | jq empty 2>/dev/null; then
133+
echo "Error: Invalid JSON output from atmos describe component"
134+
echo "Raw output (first 500 chars): ${COMPONENT_CONFIG:0:500}"
135+
exit 1
136+
fi
137+
138+
echo "Successfully retrieved component configuration"
139+
140+
# Get JSON size for monitoring
141+
JSON_SIZE=$(echo "$COMPONENT_CONFIG" | wc -c)
142+
echo "Component configuration size: ${JSON_SIZE} bytes"
143+
144+
if [[ $JSON_SIZE -gt 10485760 ]]; then # 10MB
145+
echo "Warning: Large component configuration detected (${JSON_SIZE} bytes). Processing may take longer."
146+
fi
147+
148+
echo "Processing component configuration with jq..."
149+
150+
# Process the JSON with jq using streaming for large objects
151+
settings=""
152+
if ! settings=$(echo "$COMPONENT_CONFIG" | jq -c \
153+
'{
154+
"github-actions-enabled": (.settings.github.actions_enabled // "") | tostring,
155+
"atmos-pro-enabled": (.settings.pro.enabled // "") | tostring,
156+
"component-path": (.component_info.component_path // "") | tostring,
157+
"base-path": (.atmos_cli_config.base_path // "") | tostring,
158+
"command": (.command // "") | tostring,
159+
"opentofu-version": (.settings.integrations.github.gitops."opentofu-version" // "") | tostring,
160+
"terraform-version": (.settings.integrations.github.gitops."terraform-version" // "") | tostring,
161+
"enable-infracost": (.settings.integrations.github.gitops."infracost-enabled" // "") | tostring,
162+
"terraform-plan-role": (.settings.integrations.github.gitops.role.plan // "") | tostring,
163+
"aws-region": (.settings.integrations.github.gitops."artifact-storage".region // "") | tostring,
164+
"terraform-state-role": (.settings.integrations.github.gitops."artifact-storage".role // "") | tostring,
165+
"terraform-state-table": (.settings.integrations.github.gitops."artifact-storage".table // "") | tostring,
166+
"terraform-state-bucket": (.settings.integrations.github.gitops."artifact-storage".bucket // "") | tostring,
167+
"plan-repository-type": (.settings.integrations.github.gitops."artifact-storage"."plan-repository-type" // "") | tostring,
168+
"blob-account-name": (.settings.integrations.github.gitops."artifact-storage"."blob-account-name" // "") | tostring,
169+
"blob-container-name": (.settings.integrations.github.gitops."artifact-storage"."blob-container-name" // "") | tostring,
170+
"metadata-repository-type": (.settings.integrations.github.gitops."artifact-storage"."metadata-repository-type" // "") | tostring,
171+
"cosmos-container-name": (.settings.integrations.github.gitops."artifact-storage"."cosmos-container-name" // "") | tostring,
172+
"cosmos-database-name": (.settings.integrations.github.gitops."artifact-storage"."cosmos-database-name" // "") | tostring,
173+
"cosmos-endpoint": (.settings.integrations.github.gitops."artifact-storage"."cosmos-endpoint" // "") | tostring
174+
}' 2>&1); then
175+
176+
echo "Error: Failed to process component configuration with jq"
177+
echo "jq error output: $settings"
178+
exit 1
179+
fi
180+
181+
# Validate the processed settings
182+
if ! echo "$settings" | jq empty 2>/dev/null; then
183+
echo "Error: Invalid JSON output from jq processing"
184+
echo "Processed output: $settings"
185+
exit 1
186+
fi
187+
188+
# Output debug information if debug mode is enabled
189+
if [[ "${{ inputs.debug }}" == "true" ]]; then
190+
echo "Debug: Processed settings:"
191+
echo "$settings" | jq '.'
192+
fi
193+
194+
echo "Successfully processed component settings"
195+
echo "settings=$settings" >> $GITHUB_OUTPUT
196+
197+
# Clean up large variable to free memory
198+
unset COMPONENT_CONFIG
182199
183200
- name: Install Terraform
184201
if: ${{ fromJson(steps.atmos-settings.outputs.settings).terraform-version != '' && fromJson(steps.atmos-settings.outputs.settings).terraform-version != 'null' }}

0 commit comments

Comments
 (0)