Is this for a genrule or for a Starlark rule?
"$(location :my_filegroup)" makes me think genrule, but "file.dirname" makes me think Starlark rule.
Either way, as far as I'm aware, there's no built-in way to do this. Python has
os.path.commonpath but that's not implemented in Starlark, nor in
Skylib.
So in the general case, you'd need to implement this either in bash/shell or in Starlark. However, since you're using an external repository rule (http_archive), there's maybe a shortcut. The external archive will be located in a directory at "external/<repository name>" in the execution root (i.e. where the action is executed) for the action that depends on the filegroup. That will be common to all the files in the archive. If that's too high up in the directory structure though, you'll probably have to implement something to find the appropriate directory.