So, as Drone doesn’t include a slug for commit branch, I tried to use environment substitution ${DRONE_COMMIT_BRANCH//[^a-zA-Z0-9_.-]/__}. This should ensure any branch name is mapped to an unique value, which is a valid docker image tag for example. However, it seems that the envsubst go package doesn’t implement regex parsing. This is a huge difference from shell implementations for this pattern.
I can go and replace that with a regex. However, that might break some existing uses. Though, I personally see this missing feature as a bug.
That said, is someone against this better implementation and is there something I have not thought about? If not, then I can look on implementing a PR for this.
p.s. DRONE_COMMIT_BRANCH_SLUG couldn’t be a valuable addition (Gitlab CI includes CI_COMMIT_REF_SLUG).
The envsubst library is a reasonable effort to emulate posix variable substitution, which uses pattern matching, which is not the same thing as regular expressions. Note this warning from posix pattern matching documentation:
Do not confuse patterns with regular expressions because they share some symbols and do similar matching work.
For pattern matching we use the path.Match function in the Go standard library. You can see the supported pattern matching syntax at this link: https://pkg.go.dev/path#Match
The path.Match function may not support the full posix pattern matching syntax but should support most common use cases. I suspect that in order to provide accurate emulation one would need to write a custom pattern matching library, which is not something I was interested in doing. I decided to use as much of the standard library as possible, meaning the goal was to get reasonably close to the posix spec, therefore, a perfectly compliant implementation was considered out of scope.