Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only copy collection when really necessary #48

Merged
Merged
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
48 changes: 33 additions & 15 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,20 @@ runs:
with OUTPUTS_FILE_PATH.open(FILE_APPEND_MODE) as outputs_file:
outputs_file.writelines(f'{name}={value}{os.linesep}')

directory = "${{
format(
'{0}/{1}',
(
inputs.collection-src-directory
&& inputs.collection-src-directory
|| '.tmp-ansible-collection-checkout'
),
inputs.collection-root
)
}}"

COLLECTION_META_FILE = 'galaxy.yml'
with open(COLLECTION_META_FILE) as galaxy_yml:
with open(os.path.join(directory, COLLECTION_META_FILE)) as galaxy_yml:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is running on a modern enough Python, maybe it's time to just use pathlib?
This all could be as simple as

from pathlib import Path
...
galaxy_yml_path = Path(directory / COLLECTION_META_FILE)
galaxy_yml_text = galaxy_yml_path.read_text()
collection_meta = yaml.loads(galaxy_yml_text)

collection_meta = yaml.load(galaxy_yml)

coll_name = collection_meta['name']
Expand All @@ -235,29 +247,35 @@ runs:
set_output('namespace', coll_ns)

set_output('fqcn', f'{coll_ns}.{coll_name}')
set_output('collection-namespace-path', f'ansible_collections/{coll_ns}')
set_output('checkout-path', f'ansible_collections/{coll_ns}/{coll_name}')

wanted_path = f'ansible_collections{os.sep}{coll_ns}{os.sep}{coll_name}'
if directory.endswith(wanted_path):
set_output('copy-to-checkout-path', 'false')
set_output(
'collection-namespace-path',
os.path.normpath(os.path.join(directory, '..')))
set_output('checkout-path', directory)
else:
set_output('copy-to-checkout-path', 'true')
set_output(
'collection-namespace-path',
os.path.join('ansible_collections', coll_ns))
set_output(
'checkout-path',
os.path.join('ansible_collections', coll_ns, coll_name))
shell: python
working-directory: >-
${{
format(
'{0}/{1}',
(
inputs.collection-src-directory
&& inputs.collection-src-directory
|| '.tmp-ansible-collection-checkout'
),
inputs.collection-root
)
}}

- name: Log the next step action
if: >-
${{ fromJSON(steps.collection-metadata.outputs.copy-to-checkout-path) }}
run: >-
echo ▷ ${{ inputs.collection-src-directory && 'Copy' || 'Move' }}
"'${{ steps.collection-metadata.outputs.fqcn }}'"
collection to ${{ steps.collection-metadata.outputs.checkout-path }}...
shell: bash
- name: Move the collection to the proper path
if: >-
${{ fromJSON(steps.collection-metadata.outputs.copy-to-checkout-path) }}
run: >-
set -x
;
Expand Down