-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
49 lines (48 loc) · 1.43 KB
/
action.yml
File metadata and controls
49 lines (48 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
---
name: 'Command Loop GitHub Action'
description: |
A simple GitHub Action for running a shell command in a loop
against a list of items
author: 'Cliffano Subagio'
branding:
icon: 'repeat'
color: 'white'
inputs:
items:
description: |
List of items defined in a comma and/or space-separated string,
or custom delimiters
type: string
required: true
command:
description: |
Shell command to be executed in a loop,
each run can access an item from the list via $ITEM
type: string
required: true
delimiters:
description: |
Items string delimiters, separated by pipe character,
default: ", |,| " (comma followed by space, comma, space)
type: string
required: false
default: ', | |,'
runs:
using: 'composite'
steps:
- name: Execute shell command
shell: python
run: |
import re
import sys
import subprocess
from string import Template
items_list = re.split('${{ inputs.delimiters }}', '${{ inputs.items }}')
for item in items_list:
command_template = Template('${{ inputs.command }}')
command_merged = command_template.substitute(ITEM=item)
print(f'Run: {command_merged}')
result = subprocess.run(command_merged, shell=True)
if result.returncode != 0:
print(f'Error: {result.returncode}')
sys.exit(result.returncode)