On the master branch @ 4a007126fbe3254d4025da5c623f378db44a1125, the built depends cache is keyed by the hash of a configuration script and the depends subdirectory:https://github.com/bitcoin/bitcoin/blob/0a1bbec688b8c075ba45b6028b6f4fe3ef636be9/.github/actions/configure-environment/action.yml#L20
Unfortunately, the current approach fails to invalidate the cache when toolchain packages shipped by the running OS are updated. Moreover, in such a scenario, the depends build subsystem rebuilds packages from scratch but they won't be cached by the CI framework.
As a solution, the final_build_id variable can be used:
gmake -C depends --no-print-directory print-final_build_id
This approach has another advantage: it does not require git and maybe be exploited in environments where the source code is fetched as a tarball rather than as a repository.
However, this approach is currently broken on systems (macOS, *BSD, etc). For further details, please see #35618.