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

How to get the last index #22

Open
constgen opened this issue Mar 21, 2023 · 6 comments
Open

How to get the last index #22

constgen opened this issue Mar 21, 2023 · 6 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@constgen
Copy link

constgen commented Mar 21, 2023

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

@winterjung
Copy link
Owner

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.

@constgen
Copy link
Author

But it seems to me so easy to implement

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

@constgen
Copy link
Author

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

@winterjung
Copy link
Owner

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.

@constgen
Copy link
Author

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

@winterjung winterjung added enhancement New feature or request good first issue Good for newcomers labels Mar 23, 2023
@winterjung
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants