Skip to content

Commit ce3e835

Browse files
committed
Merge remote-tracking branches 'felixfontein/only-copy-when-necessary' and 'felixfontein/yaml' into unstable/v1
3 parents 70aaefa + b143ec4 + 5cb6866 commit ce3e835

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

action.yml

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,21 @@ runs:
224224
with OUTPUTS_FILE_PATH.open(FILE_APPEND_MODE) as outputs_file:
225225
outputs_file.writelines(f'{name}={value}{os.linesep}')
226226
227+
directory = "${{
228+
format(
229+
'{0}/{1}',
230+
(
231+
inputs.collection-src-directory
232+
&& inputs.collection-src-directory
233+
|| '.tmp-ansible-collection-checkout'
234+
),
235+
inputs.collection-root
236+
)
237+
}}"
238+
227239
COLLECTION_META_FILE = 'galaxy.yml'
228-
with open(COLLECTION_META_FILE) as galaxy_yml:
229-
collection_meta = yaml.load(galaxy_yml)
240+
with open(os.path.join(directory, COLLECTION_META_FILE)) as galaxy_yml:
241+
collection_meta = yaml.safe_load(galaxy_yml)
230242
231243
coll_name = collection_meta['name']
232244
coll_ns = collection_meta['namespace']
@@ -235,29 +247,35 @@ runs:
235247
set_output('namespace', coll_ns)
236248
237249
set_output('fqcn', f'{coll_ns}.{coll_name}')
238-
set_output('collection-namespace-path', f'ansible_collections/{coll_ns}')
239-
set_output('checkout-path', f'ansible_collections/{coll_ns}/{coll_name}')
250+
251+
wanted_path = f'ansible_collections{os.sep}{coll_ns}{os.sep}{coll_name}'
252+
if directory.endswith(wanted_path):
253+
set_output('copy-to-checkout-path', 'false')
254+
set_output(
255+
'collection-namespace-path',
256+
os.path.normpath(os.path.join(directory, '..')))
257+
set_output('checkout-path', directory)
258+
else:
259+
set_output('copy-to-checkout-path', 'true')
260+
set_output(
261+
'collection-namespace-path',
262+
os.path.join('ansible_collections', coll_ns))
263+
set_output(
264+
'checkout-path',
265+
os.path.join('ansible_collections', coll_ns, coll_name))
240266
shell: python
241-
working-directory: >-
242-
${{
243-
format(
244-
'{0}/{1}',
245-
(
246-
inputs.collection-src-directory
247-
&& inputs.collection-src-directory
248-
|| '.tmp-ansible-collection-checkout'
249-
),
250-
inputs.collection-root
251-
)
252-
}}
253267

254268
- name: Log the next step action
269+
if: >-
270+
${{ fromJSON(steps.collection-metadata.outputs.copy-to-checkout-path) }}
255271
run: >-
256272
echo ▷ ${{ inputs.collection-src-directory && 'Copy' || 'Move' }}
257273
"'${{ steps.collection-metadata.outputs.fqcn }}'"
258274
collection to ${{ steps.collection-metadata.outputs.checkout-path }}...
259275
shell: bash
260276
- name: Move the collection to the proper path
277+
if: >-
278+
${{ fromJSON(steps.collection-metadata.outputs.copy-to-checkout-path) }}
261279
run: >-
262280
set -x
263281
;

0 commit comments

Comments
 (0)