1

I am trying to prepare artifact name prefix using GitHub Actions that will replace project name special characters with hyphens. I have this piece of code:

strategy:
 matrix:
 project:
 - Common/Helpers.Tests
 - PlaywrightXunitParallel
- name: Set artifact prefix
 id: artifact_prefix
 run: |
 PROJECT_NAME=${{ matrix.project }}
 ARTIFACT_PREFIX=${PROJECT_NAME/[^A-Za-z0-9\-]/-}
 echo "::set-output name=lowercase::${ARTIFACT_PREFIX,,}"

However, I realized that regex is performed only once and result for project Common/Helpers.Tests is common-helpers.tests instead of common-helpers-tests.

I have tried to mark it as global like this: ARTIFACT_PREFIX=${PROJECT_NAME/[^A-Za-z0-9\-]/-/g} but it is not working as expected.

How can I replace all occurrences of special characters from project name?

Link to repo: https://github.com/gucu112/CSharpAutomation/actions/runs/18258362933#artifacts

Wiktor Stribiżew
631k41 gold badges503 silver badges633 bronze badges
asked Oct 5 at 12:18
1
  • Use // to replace all occurrences, instead of g at the end: ARTIFACT_PREFIX=${PROJECT_NAME//[^A-Za-z0-9-]/-} Commented Dec 17 at 15:47

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.