Skip to content

Commit

Permalink
Adds support for platform fact output
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Apr 22, 2024
1 parent 843ff1f commit cce1438
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,11 @@ URL of the platform to install.

Version of platform to use. Default: *5*.

<!--
## Outputs

### `foo`
### `platform_fact`

Foo bar.
-->
Platform fact output.

### Support

Expand Down
29 changes: 17 additions & 12 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ inputs:
description: Version of platform to use.
name: EA Tester

# outputs:
# foo: # id of output
# description: 'Foo'
outputs:
platform_fact:
description: Platform fact output.
value: ${{ steps.platform-fact-output.outputs.platform-fact || '{}' }}

runs:
steps:
- name: Creates playbook
Expand Down Expand Up @@ -216,21 +218,24 @@ runs:
--verbose
playbook: run.yml
requirements: requirements.yml
- name: Sets output
- id: platform-fact-output
name: Sets platform fact output
env:
MT_VERSION: "${{ inputs.Version }}"
run: |
import json, os
try:
with open("/etc/ansible/facts.d/metatrader.fact", "r") as file:
data = json.load(file)
mt_path = data.get(os.getenv("MT_VERSION")).get("path")
with open(os.getenv("GITHUB_ENV"), "a") as file_env:
file_env.write(f"MT_PATH={mt_path}\n")
fact_obj = json.load(file)
except FileNotFoundError:
print("Error: Fact file not found.")
# Serialize the data back into a JSON string.
fact_plain = json.dumps(fact_obj)
try:
with open(os.getenv("GITHUB_OUTPUT"), "a") as file_env:
file_env.write(f"platform-fact={fact_plain}\n")
print(f"platform-fact={fact_plain}\n")
except FileNotFoundError:
print("Error: File not found.")
print("Error: Output file not found.")
shell: python
- name: Prints path
run: echo "$MT_PATH"
shell: bash
using: composite

0 comments on commit cce1438

Please sign in to comment.