Is it possible to iterate over all the tags/releases from a GitHub Self-Hosted Runner? #189805
-
Why are you starting this discussion?Question What GitHub Actions topic or product is this about?Actions Runner Discussion DetailsWe're hoping that we can iterate over all the tags/releases to read all the semantic version numbers, so that we can calculate the next semantic version number during a GitHub Action, that is running on our server, in a GitHub self-hosted runner. Is that possible? If so, how can this be done? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
|
yes, it is absolutely possible. Since you are using a self-hosted runner, you actually have a slight advantage: you have direct access to the local git binary and the file system, which can be faster than hitting the GitHub API for every single tag. Here are the two best ways to do this:
Crucial Step: You must ensure your actions/checkout step fetches the entire history, not just the latest commit. By default, GitHub only fetches a "depth" of 1.
Bash |
Beta Was this translation helpful? Give feedback.
-
|
Self-hosted runners on Windows are actually persistent, not ephemeral, so they keep files in the _work folder unless you manually clean them or use the --ephemeral flag. The SemVer Action isn't unreliable or slow, it's actually more robust than custom scripts because it handles the regex and sorting for your "v" pattern automatically. It's often "not recommended" only by purists who prefer zero external dependencies, but for your case, it’s the most efficient choice in my opinion. |
Beta Was this translation helpful? Give feedback.
-
for tag in $(git tag --sort=version:refname); do
echo "Processing: $tag"
done |
Beta Was this translation helpful? Give feedback.
-
|
Yes, it’s possible. A self-hosted runner doesn’t store tags or releases itself—it just runs jobs—but you can fetch and iterate over them during a workflow. For tags, you use Git (e.g., fetch all tags and loop through them). So basically: the runner can access and iterate over tags/releases, but only by pulling them from the repository or GitHub, not from itself. |
Beta Was this translation helpful? Give feedback.
yes, it is absolutely possible. Since you are using a self-hosted runner, you actually have a slight advantage: you have direct access to the local git binary and the file system, which can be faster than hitting the GitHub API for every single tag.
Here are the two best ways to do this:
This is the most reliable method because it doesn't depend on API rate limits. You can pull all tags directly from the repository's history.
Crucial Step: You must ensure your actions/checkout step fetches the entire history, not just the latest commit. By default, GitHub only fetches a "depth" of 1.