split icon indicating copy to clipboard operation
split copied to clipboard

How to get the last index

Open constgen opened this issue 1 year ago • 6 comments

Can we have a new output value outputs.last that is equal to the latest value in the split array? Because steps.version.outputs.length - 1 throws a syntax error

constgen avatar Mar 21 '23 16:03 constgen

Hi @constgen. I think you should type cast steps.version.outputs.length to integer first. Or using actions/github-script@v6 might be more appropriate for your use case.

winterjung avatar Mar 22 '23 02:03 winterjung

But it seems to me so easy to implement

outputs = {
    'length': str(len(results)),
+   'last': results[len(results) - 1],
}

constgen avatar Mar 22 '23 10:03 constgen

Or we can try absolutely different idea. Inverted indexes

outputs._-0 # last
outputs._-1 # the second from the end
outputs._-2 # the third from the end
...others

constgen avatar Mar 22 '23 10:03 constgen

Agree that it is easy to implement. You don't even have to do it like results[len(results) - 1], just results[-1]. But I just wonder in what specific use-case this change would be useful.

winterjung avatar Mar 22 '23 11:03 winterjung

My case is that I try to extract the full version 113.0.0 from branch name refs/heads/versions/113.0.0

constgen avatar Mar 22 '23 11:03 constgen

Thanks to let me know. I'll add last output for it.

winterjung avatar Mar 23 '23 02:03 winterjung