I coded a small Golang program, that takes N arguments (files with resourceQuota requests for K8s) from a GitHub PR, and writes a file with the total amount of CPU and Memory requested that is then exported as GHA output in the next step.
can’t do go run main.go /path/to/file1 /path/to/file2
because Apparently i hit a bug in actions/setup-go
with our self-hosted runner, so i had to containerise that.
I’m new to all of these, so my colleagues told me to import the docker program from a self-made GitHub action, all works like a charm when only 1 file is changed in the PR (only 1 arg to handle).
Problem is when 2 or more args are passed, because the action im using: tj-actions/changed-files outputs a single string with all the files names and i’m really clueless on how to work around it.
this is how i call the self-made action:
- name: Capture request values actions
uses: ./goCapacityCheck
with:
files: ${{ steps.changed-files.outputs.all_changed_files }}
goCapacityCheck action.yml
name: 'goCapacityCheck'
description: 'Capture requests CPU and Memory values from all files in the PR'
inputs:
files:
description: 'files changed in the PR.'
required: false
runs:
using: 'docker'
image: './Dockerfile'
args:
- ${{ inputs.files }}
is there a way to split that string when passing to the action? or to Docker or something?
I haven’t tried much when i hit this issue, but i’d expect that the sting that looks like "/path/to/file1 /path/to/file2"
to be split at some point in order to be able to do
docker run --name mygocap gocap /path/to/file1 /path/to/file2
2
Answers
I ended up having to handle it inside the go program because i would never now how many arguments would come in, so from
os.Args[]
i calledgetFileNames()
and then i did the rest of the routine withfilenames
instead ofos.Args[1:]
directly.You could try to split with some bash tricks, as example:
will print
So you could try something like this in a GitHub action workflow: