<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>GitHub by Ruslan Diachenko</title><link>https://rdiachenko.com/til/github/</link><description>Recent content in GitHub by Ruslan Diachenko</description><generator>Hugo</generator><language>en</language><managingEditor>ruslan@rdiachenko.com (Ruslan Diachenko)</managingEditor><webMaster>ruslan@rdiachenko.com (Ruslan Diachenko)</webMaster><lastBuildDate>Tue, 17 Nov 2026 20:17:07 +0000</lastBuildDate><atom:link href="https://rdiachenko.com/til/github/index.xml" rel="self" type="application/rss+xml"/><item><title>Let a GitHub Action Download the Right Prebuilt Binary</title><link>https://rdiachenko.com/til/github/action-prebuilt-binary/</link><pubDate>Tue, 17 Nov 2026 20:17:07 +0000</pubDate><author>ruslan@rdiachenko.com (Ruslan Diachenko)</author><guid>https://rdiachenko.com/til/github/action-prebuilt-binary/</guid><description>I made my GitHub Action download a prebuilt binary, cutting setup from 22–36 seconds with a warm build cache to 0.4–1.0 seconds. It reads the ref from the path to its own code because &lt;code&gt;github.action_ref&lt;/code&gt; can be wrong.</description><content:encoded><![CDATA[<p>If your GitHub Action runs a compiled program, it can download a prebuilt binary instead of building it on every run. To pick the right release, it needs to know which version the workflow asked for, the <code>v0</code> in <code>uses: owner/action@v0</code>.</p>
<p>GitHub has a variable for this, <code>github.action_ref</code>, but it can be empty or hold another action&rsquo;s version. The path to the action&rsquo;s own code is more reliable. The runner downloads that code to a folder named after the version and gives the action&rsquo;s steps its path in <code>$GITHUB_ACTION_PATH</code>.</p>
<h2 id="whos-who">
Who&rsquo;s who
<a href="#whos-who" class="heading-anchor" aria-label="Anchor link for: Who&amp;rsquo;s who">
    
    
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M579.8 267.7c56.5-56.5 56.5-148 0-204.5c-50-50-128.8-56.5-186.3-15.4l-1.6 1.1c-14.4 10.3-17.7 30.3-7.4 44.6s30.3 17.7 44.6 7.4l1.6-1.1c32.1-22.9 76-19.3 103.8 8.6c31.5 31.5 31.5 82.5 0 114L422.3 334.8c-31.5 31.5-82.5 31.5-114 0c-27.9-27.9-31.5-71.8-8.6-103.8l1.1-1.6c10.3-14.4 6.9-34.4-7.4-44.6s-34.4-6.9-44.6 7.4l-1.1 1.6C206.5 251.2 213 330 263 380c56.5 56.5 148 56.5 204.5 0L579.8 267.7zM60.2 244.3c-56.5 56.5-56.5 148 0 204.5c50 50 128.8 56.5 186.3 15.4l1.6-1.1c14.4-10.3 17.7-30.3 7.4-44.6s-30.3-17.7-44.6-7.4l-1.6 1.1c-32.1 22.9-76 19.3-103.8-8.6C74 372 74 321 105.5 289.5L217.7 177.2c31.5-31.5 82.5-31.5 114 0c27.9 27.9 31.5 71.8 8.6 103.9l-1.1 1.6c-10.3 14.4-6.9 34.4 7.4 44.6s34.4 6.9 44.6-7.4l1.1-1.6C433.5 260.8 427 182 377 132c-56.5-56.5-148-56.5-204.5 0L60.2 244.3z"/></svg>
    
</a>
</h2>
<p>I recently built 
<a href="https://github.com/rdiachenko/rotguard" target="_blank" rel="nofollow noopener">rotguard</a>
, a link checker that rewrites redirected and dead links. It runs on this blog every week. Each run involves 3 things:</p>
<ul>
<li><strong>workflow</strong> is a YAML file in the blog&rsquo;s repo, <code>.github/workflows/rotguard.yml</code>. One of its steps says <code>uses: rdiachenko/rotguard@v0</code>.</li>
<li><strong>runner</strong> is the machine GitHub starts to run that workflow.</li>
<li><strong>rotguard</strong> is the action. Its <code>action.yml</code> lives in a separate repo and lists the shell steps the runner runs inside the workflow&rsquo;s job, as if the workflow had listed them itself.</li>
</ul>
<h2 id="download-or-build">
Download or build
<a href="#download-or-build" class="heading-anchor" aria-label="Anchor link for: Download or build">
    
    
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M579.8 267.7c56.5-56.5 56.5-148 0-204.5c-50-50-128.8-56.5-186.3-15.4l-1.6 1.1c-14.4 10.3-17.7 30.3-7.4 44.6s30.3 17.7 44.6 7.4l1.6-1.1c32.1-22.9 76-19.3 103.8 8.6c31.5 31.5 31.5 82.5 0 114L422.3 334.8c-31.5 31.5-82.5 31.5-114 0c-27.9-27.9-31.5-71.8-8.6-103.8l1.1-1.6c10.3-14.4 6.9-34.4-7.4-44.6s-34.4-6.9-44.6 7.4l-1.1 1.6C206.5 251.2 213 330 263 380c56.5 56.5 148 56.5 204.5 0L579.8 267.7zM60.2 244.3c-56.5 56.5-56.5 148 0 204.5c50 50 128.8 56.5 186.3 15.4l1.6-1.1c14.4-10.3 17.7-30.3 7.4-44.6s-30.3-17.7-44.6-7.4l-1.6 1.1c-32.1 22.9-76 19.3-103.8-8.6C74 372 74 321 105.5 289.5L217.7 177.2c31.5-31.5 82.5-31.5 114 0c27.9 27.9 31.5 71.8 8.6 103.9l-1.1 1.6c-10.3 14.4-6.9 34.4 7.4 44.6s34.4 6.9 44.6-7.4l1.1-1.6C433.5 260.8 427 182 377 132c-56.5-56.5-148-56.5-204.5 0L60.2 244.3z"/></svg>
    
</a>
</h2>
<p>rotguard is written in Rust, so it needs a binary on the runner before it can check any links. Building it from source took 22 to 36 seconds with a warm build cache and about 2.5 minutes without one. Downloading and installing it from a GitHub release took about a second.</p>
<p>Whether rotguard downloads the binary or builds it depends on what comes after <code>@</code> in the workflow&rsquo;s <code>uses:</code> line. That value is a git ref, such as a tag (<code>v0</code>), a branch (<code>main</code>) or a commit SHA. For <code>@v0</code>, rotguard downloads the binary for the release that <code>v0</code> points to. For <code>@main</code>, it builds from source.</p>
<h2 id="why-githubaction_ref-isnt-enough">
Why <code>github.action_ref</code> isn&rsquo;t enough
<a href="#why-githubaction_ref-isnt-enough" class="heading-anchor" aria-label="Anchor link for: Why github.action_ref isn&amp;rsquo;t enough">
    
    
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M579.8 267.7c56.5-56.5 56.5-148 0-204.5c-50-50-128.8-56.5-186.3-15.4l-1.6 1.1c-14.4 10.3-17.7 30.3-7.4 44.6s30.3 17.7 44.6 7.4l1.6-1.1c32.1-22.9 76-19.3 103.8 8.6c31.5 31.5 31.5 82.5 0 114L422.3 334.8c-31.5 31.5-82.5 31.5-114 0c-27.9-27.9-31.5-71.8-8.6-103.8l1.1-1.6c10.3-14.4 6.9-34.4-7.4-44.6s-34.4-6.9-44.6 7.4l-1.1 1.6C206.5 251.2 213 330 263 380c56.5 56.5 148 56.5 204.5 0L579.8 267.7zM60.2 244.3c-56.5 56.5-56.5 148 0 204.5c50 50 128.8 56.5 186.3 15.4l1.6-1.1c14.4-10.3 17.7-30.3 7.4-44.6s-30.3-17.7-44.6-7.4l-1.6 1.1c-32.1 22.9-76 19.3-103.8-8.6C74 372 74 321 105.5 289.5L217.7 177.2c31.5-31.5 82.5-31.5 114 0c27.9 27.9 31.5 71.8 8.6 103.9l-1.1 1.6c-10.3 14.4-6.9 34.4 7.4 44.6s34.4 6.9 44.6-7.4l1.1-1.6C433.5 260.8 427 182 377 132c-56.5-56.5-148-56.5-204.5 0L60.2 244.3z"/></svg>
    
</a>
</h2>
<p>GitHub puts the ref in <code>github.action_ref</code>. In a composite action like rotguard, it has 2 problems:</p>
<ul>
<li>It&rsquo;s empty when you use <code>${{ github.action_ref }}</code> directly in <code>run:</code>. To read it from a shell step, pass it through the step&rsquo;s <code>env:</code>.</li>
<li>If another action calls rotguard, <code>github.action_ref</code> can hold that action&rsquo;s ref (
<a href="https://github.com/actions/runner/issues/2473" target="_blank" rel="nofollow noopener">actions/runner#2473</a>
). If a wrapper action pinned to <code>@v1</code> calls <code>rotguard@main</code>, rotguard sees <code>v1</code> and tries to download a release binary instead of building <code>main</code>.</li>
</ul>
<h2 id="reading-the-ref-from-the-folder-path">
Reading the ref from the folder path
<a href="#reading-the-ref-from-the-folder-path" class="heading-anchor" aria-label="Anchor link for: Reading the ref from the folder path">
    
    
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M579.8 267.7c56.5-56.5 56.5-148 0-204.5c-50-50-128.8-56.5-186.3-15.4l-1.6 1.1c-14.4 10.3-17.7 30.3-7.4 44.6s30.3 17.7 44.6 7.4l1.6-1.1c32.1-22.9 76-19.3 103.8 8.6c31.5 31.5 31.5 82.5 0 114L422.3 334.8c-31.5 31.5-82.5 31.5-114 0c-27.9-27.9-31.5-71.8-8.6-103.8l1.1-1.6c10.3-14.4 6.9-34.4-7.4-44.6s-34.4-6.9-44.6 7.4l-1.1 1.6C206.5 251.2 213 330 263 380c56.5 56.5 148 56.5 204.5 0L579.8 267.7zM60.2 244.3c-56.5 56.5-56.5 148 0 204.5c50 50 128.8 56.5 186.3 15.4l1.6-1.1c14.4-10.3 17.7-30.3 7.4-44.6s-30.3-17.7-44.6-7.4l-1.6 1.1c-32.1 22.9-76 19.3-103.8-8.6C74 372 74 321 105.5 289.5L217.7 177.2c31.5-31.5 82.5-31.5 114 0c27.9 27.9 31.5 71.8 8.6 103.9l-1.1 1.6c-10.3 14.4-6.9 34.4 7.4 44.6s34.4 6.9 44.6-7.4l1.1-1.6C433.5 260.8 427 182 377 132c-56.5-56.5-148-56.5-204.5 0L60.2 244.3z"/></svg>
    
</a>
</h2>
<p>Before the job starts, the runner downloads rotguard&rsquo;s code to a folder whose path ends with the ref. For <code>@v0</code>, the path looks like this:</p>
<div class="code-block" data-frame="editor">
    <div class="code-content">
        <i><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M280 64l40 0c35.3 0 64 28.7 64 64l0 320c0 35.3-28.7 64-64 64L64 512c-35.3 0-64-28.7-64-64L0 128C0 92.7 28.7 64 64 64l40 0 9.6 0C121 27.5 153.3 0 192 0s71 27.5 78.4 64l9.6 0zM64 112c-8.8 0-16 7.2-16 16l0 320c0 8.8 7.2 16 16 16l256 0c8.8 0 16-7.2 16-16l0-320c0-8.8-7.2-16-16-16l-16 0 0 24c0 13.3-10.7 24-24 24l-88 0-88 0c-13.3 0-24-10.7-24-24l0-24-16 0zm128-8a24 24 0 1 0 0-48 24 24 0 1 0 0 48z"/></svg></i><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">/home/runner/work/_actions/rdiachenko/rotguard/v0</span></span></code></pre></div></div>
</div>
<p>rotguard&rsquo;s steps get this path in <code>$GITHUB_ACTION_PATH</code> and use it to find files such as <code>Cargo.toml</code>. The ref is the part of that path after <code>_actions/&lt;owner&gt;/&lt;repo&gt;/</code>:</p>
<div class="code-block" data-frame="terminal">
    <div class="code-content">
        <i><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M280 64l40 0c35.3 0 64 28.7 64 64l0 320c0 35.3-28.7 64-64 64L64 512c-35.3 0-64-28.7-64-64L0 128C0 92.7 28.7 64 64 64l40 0 9.6 0C121 27.5 153.3 0 192 0s71 27.5 78.4 64l9.6 0zM64 112c-8.8 0-16 7.2-16 16l0 320c0 8.8 7.2 16 16 16l256 0c8.8 0 16-7.2 16-16l0-320c0-8.8-7.2-16-16-16l-16 0 0 24c0 13.3-10.7 24-24 24l-88 0-88 0c-13.3 0-24-10.7-24-24l0-24-16 0zm128-8a24 24 0 1 0 0-48 24 24 0 1 0 0 48z"/></svg></i><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nv">ref</span><span class="o">=</span><span class="s2">&#34;</span><span class="si">${</span><span class="nv">GITHUB_ACTION_PATH</span><span class="p">#*/_actions/*/*/</span><span class="si">}</span><span class="s2">&#34;</span></span></span></code></pre></div></div>
</div>
<p>If a branch name contains a slash, reading only what comes after the final <code>/</code> gives you an incomplete ref. A branch called <code>release/v0.2.0</code> gets this path:</p>
<div class="code-block" data-frame="editor">
    <div class="code-content">
        <i><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M280 64l40 0c35.3 0 64 28.7 64 64l0 320c0 35.3-28.7 64-64 64L64 512c-35.3 0-64-28.7-64-64L0 128C0 92.7 28.7 64 64 64l40 0 9.6 0C121 27.5 153.3 0 192 0s71 27.5 78.4 64l9.6 0zM64 112c-8.8 0-16 7.2-16 16l0 320c0 8.8 7.2 16 16 16l256 0c8.8 0 16-7.2 16-16l0-320c0-8.8-7.2-16-16-16l-16 0 0 24c0 13.3-10.7 24-24 24l-88 0-88 0c-13.3 0-24-10.7-24-24l0-24-16 0zm128-8a24 24 0 1 0 0-48 24 24 0 1 0 0 48z"/></svg></i><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">/home/runner/work/_actions/rdiachenko/rotguard/release/v0.2.0</span></span></code></pre></div></div>
</div>
<p>Reading only <code>v0.2.0</code> would make rotguard try to download a release binary instead of building the branch, because <code>v0.2.0</code> looks like a release tag. The <code>#</code> expansion removes the shortest prefix that matches the pattern. Here that prefix ends at <code>rotguard/</code>, leaving the full ref <code>release/v0.2.0</code>.</p>
<p>Figure 1 shows the whole run. Either way, the binary ends up where the last step expects it.</p>
<figure >
        <picture>
            <source
                    srcset="https://rdiachenko.com/til/github/action-prebuilt-binary/action-ref-flow-cover_hu_b46b4a0fe4d53d73.webp"
                    media="(max-width: 768px)"
                    width="2806"
                    height="2541">
            <source
                    srcset="https://rdiachenko.com/til/github/action-prebuilt-binary/action-ref-flow-cover_hu_d76983d0d3e54963.webp"
                    media="(min-width: 769px)"
                    width="4009"
                    height="3630">
            <img
                    src="https://rdiachenko.com/til/github/action-prebuilt-binary/action-ref-flow-cover_hu_d76983d0d3e54963.webp"
                    alt="Flowchart: the workflow uses rotguard@v0 and starts the job; the runner downloads rotguard&#39;s code to a folder named v0; if the ref looks like a release tag, rotguard downloads the binary from GitHub Releases in under 1 s, otherwise it builds it; either way rotguard then runs the binary."
                    width="4009"
                    height="3630"
                    loading="lazy">
        </picture><figcaption><small>Figure 1. One run of <code>rdiachenko/rotguard@v0</code>, from the workflow&rsquo;s <code>uses:</code> line to the step that runs the binary</small></figcaption></figure>
<h2 id="the-download-step">
The download step
<a href="#the-download-step" class="heading-anchor" aria-label="Anchor link for: The download step">
    
    
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M579.8 267.7c56.5-56.5 56.5-148 0-204.5c-50-50-128.8-56.5-186.3-15.4l-1.6 1.1c-14.4 10.3-17.7 30.3-7.4 44.6s30.3 17.7 44.6 7.4l1.6-1.1c32.1-22.9 76-19.3 103.8 8.6c31.5 31.5 31.5 82.5 0 114L422.3 334.8c-31.5 31.5-82.5 31.5-114 0c-27.9-27.9-31.5-71.8-8.6-103.8l1.1-1.6c10.3-14.4 6.9-34.4-7.4-44.6s-34.4-6.9-44.6 7.4l-1.1 1.6C206.5 251.2 213 330 263 380c56.5 56.5 148 56.5 204.5 0L579.8 267.7zM60.2 244.3c-56.5 56.5-56.5 148 0 204.5c50 50 128.8 56.5 186.3 15.4l1.6-1.1c14.4-10.3 17.7-30.3 7.4-44.6s-30.3-17.7-44.6-7.4l-1.6 1.1c-32.1 22.9-76 19.3-103.8-8.6C74 372 74 321 105.5 289.5L217.7 177.2c31.5-31.5 82.5-31.5 114 0c27.9 27.9 31.5 71.8 8.6 103.9l-1.1 1.6c-10.3 14.4-6.9 34.4 7.4 44.6s34.4 6.9 44.6-7.4l1.1-1.6C433.5 260.8 427 182 377 132c-56.5-56.5-148-56.5-204.5 0L60.2 244.3z"/></svg>
    
</a>
</h2>
<p>Here&rsquo;s the first step from rotguard&rsquo;s 
<a href="https://github.com/rdiachenko/rotguard/blob/main/action.yml" target="_blank" rel="nofollow noopener"><code>action.yml</code></a>
, with the error messages omitted and shorter <code>curl</code> flags. It tries to download a binary if the ref looks like a release tag (<code>v0</code> or <code>v0.3.0</code>) and the runner is on Linux with an x64 or ARM64 CPU. Otherwise, it sets <code>mode=build</code>:</p>
<div class="code-block" data-frame="editor">
        <div class="code-header">
                <span class="code-filename">rotguard/action.yml</span>
        </div>
    <div class="code-content">
        <i><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M280 64l40 0c35.3 0 64 28.7 64 64l0 320c0 35.3-28.7 64-64 64L64 512c-35.3 0-64-28.7-64-64L0 128C0 92.7 28.7 64 64 64l40 0 9.6 0C121 27.5 153.3 0 192 0s71 27.5 78.4 64l9.6 0zM64 112c-8.8 0-16 7.2-16 16l0 320c0 8.8 7.2 16 16 16l256 0c8.8 0 16-7.2 16-16l0-320c0-8.8-7.2-16-16-16l-16 0 0 24c0 13.3-10.7 24-24 24l-88 0-88 0c-13.3 0-24-10.7-24-24l0-24-16 0zm128-8a24 24 0 1 0 0-48 24 24 0 1 0 0 48z"/></svg></i><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl">- <span class="nt">id</span><span class="p">:</span><span class="w"> </span><span class="l">fetch</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">shell</span><span class="p">:</span><span class="w"> </span><span class="l">bash</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">run</span><span class="p">:</span><span class="w"> </span><span class="p">|</span><span class="sd">
</span></span></span><span class="line"><span class="cl"><span class="sd">    ref=&#34;${GITHUB_ACTION_PATH#*/_actions/*/*/}&#34;
</span></span></span><span class="line"><span class="cl"><span class="sd">    ref_pattern=&#39;^v[0-9]+(\.[0-9]+\.[0-9]+)?$&#39;
</span></span></span><span class="line"><span class="cl"><span class="sd">    target=&#39;&#39;
</span></span></span><span class="line"><span class="cl"><span class="sd">    if [[ $RUNNER_OS == Linux &amp;&amp; $ref =~ $ref_pattern ]]; then
</span></span></span><span class="line"><span class="cl"><span class="sd">      case &#34;$RUNNER_ARCH&#34; in
</span></span></span><span class="line"><span class="cl"><span class="sd">        X64) target=x86_64-unknown-linux-musl ;;
</span></span></span><span class="line"><span class="cl"><span class="sd">        ARM64) target=aarch64-unknown-linux-musl ;;
</span></span></span><span class="line"><span class="cl"><span class="sd">      esac
</span></span></span><span class="line"><span class="cl"><span class="sd">    fi
</span></span></span><span class="line"><span class="cl"><span class="sd">    if [ -z &#34;$target&#34; ]; then
</span></span></span><span class="line"><span class="cl"><span class="sd">      echo &#34;mode=build&#34; &gt;&gt; &#34;$GITHUB_OUTPUT&#34;
</span></span></span><span class="line"><span class="cl"><span class="sd">      exit 0
</span></span></span><span class="line"><span class="cl"><span class="sd">    fi
</span></span></span><span class="line"><span class="cl"><span class="sd">    version=$(&#34;$GITHUB_ACTION_PATH/scripts/cargo-version.sh&#34; &#34;$GITHUB_ACTION_PATH/Cargo.toml&#34;)
</span></span></span><span class="line"><span class="cl"><span class="sd">    asset=&#34;rotguard-$version-$target&#34;
</span></span></span><span class="line"><span class="cl"><span class="sd">    base=&#34;https://github.com/rdiachenko/rotguard/releases/download/v$version&#34;
</span></span></span><span class="line"><span class="cl"><span class="sd">    cd &#34;$RUNNER_TEMP&#34;
</span></span></span><span class="line"><span class="cl"><span class="sd">    curl -fsSL --retry 3 --max-time 120 -o &#34;$asset&#34; &#34;$base/$asset&#34;
</span></span></span><span class="line"><span class="cl"><span class="sd">    curl -fsSL --retry 3 --max-time 120 -o SHA256SUMS &#34;$base/SHA256SUMS&#34;
</span></span></span><span class="line"><span class="cl"><span class="sd">    grep -F &#34; $asset&#34; SHA256SUMS | sha256sum -c -
</span></span></span><span class="line"><span class="cl"><span class="sd">    mkdir -p &#34;$GITHUB_ACTION_PATH/target/release&#34;
</span></span></span><span class="line"><span class="cl"><span class="sd">    install -m 755 &#34;$asset&#34; &#34;$GITHUB_ACTION_PATH/target/release/rotguard&#34;
</span></span></span><span class="line"><span class="cl"><span class="sd">    echo &#34;mode=release&#34; &gt;&gt; &#34;$GITHUB_OUTPUT&#34;</span></span></span></code></pre></div></div>
</div>
<ul>
<li>The build steps that follow use <code>if: steps.fetch.outputs.mode == 'build'</code>, so they run only when the fetch step sets <code>mode=build</code>.</li>
<li>The fetch step puts the binary where <code>cargo build --release</code> would put it, so the last step can use the same path either way.</li>
<li>The fetch step sets <code>shell: bash</code>, which the runner starts as <code>bash --noprofile --norc -eo pipefail</code>, so a failed download or checksum check fails the job. A missing release binary shouldn&rsquo;t pass quietly.</li>
<li>A branch named <code>v1</code> also matches the pattern, so on a supported runner rotguard tries to download a release binary for that branch.</li>
</ul>
<h2 id="where-the-version-comes-from">
Where the version comes from
<a href="#where-the-version-comes-from" class="heading-anchor" aria-label="Anchor link for: Where the version comes from">
    
    
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M579.8 267.7c56.5-56.5 56.5-148 0-204.5c-50-50-128.8-56.5-186.3-15.4l-1.6 1.1c-14.4 10.3-17.7 30.3-7.4 44.6s30.3 17.7 44.6 7.4l1.6-1.1c32.1-22.9 76-19.3 103.8 8.6c31.5 31.5 31.5 82.5 0 114L422.3 334.8c-31.5 31.5-82.5 31.5-114 0c-27.9-27.9-31.5-71.8-8.6-103.8l1.1-1.6c10.3-14.4 6.9-34.4-7.4-44.6s-34.4-6.9-44.6 7.4l-1.1 1.6C206.5 251.2 213 330 263 380c56.5 56.5 148 56.5 204.5 0L579.8 267.7zM60.2 244.3c-56.5 56.5-56.5 148 0 204.5c50 50 128.8 56.5 186.3 15.4l1.6-1.1c14.4-10.3 17.7-30.3 7.4-44.6s-30.3-17.7-44.6-7.4l-1.6 1.1c-32.1 22.9-76 19.3-103.8-8.6C74 372 74 321 105.5 289.5L217.7 177.2c31.5-31.5 82.5-31.5 114 0c27.9 27.9 31.5 71.8 8.6 103.9l-1.1 1.6c-10.3 14.4-6.9 34.4 7.4 44.6s34.4 6.9 44.6-7.4l1.1-1.6C433.5 260.8 427 182 377 132c-56.5-56.5-148-56.5-204.5 0L60.2 244.3z"/></svg>
    
</a>
</h2>
<p>The <code>v0</code> in the <code>uses:</code> line does more than pass the pattern check. It decides which commit of rotguard the runner downloads. <code>v0</code> is a tag that moves to each new 0.x release, and today it points at the &ldquo;Release 0.3.0&rdquo; commit. The runner&rsquo;s log shows it:</p>
<div class="code-block" data-frame="editor">
    <div class="code-content">
        <i><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M280 64l40 0c35.3 0 64 28.7 64 64l0 320c0 35.3-28.7 64-64 64L64 512c-35.3 0-64-28.7-64-64L0 128C0 92.7 28.7 64 64 64l40 0 9.6 0C121 27.5 153.3 0 192 0s71 27.5 78.4 64l9.6 0zM64 112c-8.8 0-16 7.2-16 16l0 320c0 8.8 7.2 16 16 16l256 0c8.8 0 16-7.2 16-16l0-320c0-8.8-7.2-16-16-16l-16 0 0 24c0 13.3-10.7 24-24 24l-88 0-88 0c-13.3 0-24-10.7-24-24l0-24-16 0zm128-8a24 24 0 1 0 0-48 24 24 0 1 0 0 48z"/></svg></i><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Download action repository &#39;rdiachenko/rotguard@v0&#39;
</span></span><span class="line"><span class="cl">  (SHA:8bd224b18bc8cf10c1cbfc8239f3f4d8113b17bc)</span></span></code></pre></div></div>
</div>
<p>The <code>Cargo.toml</code> in that commit says <code>version = &quot;0.3.0&quot;</code>, so the fetch step asks for <code>rotguard-0.3.0-x86_64-unknown-linux-musl</code>. With <code>@v0.2.1</code>, the runner downloads the commit tagged <code>v0.2.1</code>, and the step gets the 0.2.1 binary. The name <code>v0</code> stays the same across releases, so the step gets the exact version from the <code>Cargo.toml</code> that came with the code.</p>
<p>This only works if the release binaries are available before <code>v0</code> moves. rotguard&rsquo;s 
<a href="https://github.com/rdiachenko/rotguard/blob/main/.github/workflows/release.yml" target="_blank" rel="nofollow noopener">release workflow</a>
 runs when a <code>vX.Y.Z</code> tag is pushed. It checks the tag against <code>Cargo.toml</code>, builds both Linux binaries, publishes them with <code>SHA256SUMS</code>, and moves <code>v0</code> to the new commit last. If it moved <code>v0</code> to the 0.4.0 commit first, a job could pick up that commit, read <code>0.4.0</code> from <code>Cargo.toml</code>, and try to download a binary that doesn&rsquo;t exist yet.</p>
<h2 id="the-result">
The result
<a href="#the-result" class="heading-anchor" aria-label="Anchor link for: The result">
    
    
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M579.8 267.7c56.5-56.5 56.5-148 0-204.5c-50-50-128.8-56.5-186.3-15.4l-1.6 1.1c-14.4 10.3-17.7 30.3-7.4 44.6s30.3 17.7 44.6 7.4l1.6-1.1c32.1-22.9 76-19.3 103.8 8.6c31.5 31.5 31.5 82.5 0 114L422.3 334.8c-31.5 31.5-82.5 31.5-114 0c-27.9-27.9-31.5-71.8-8.6-103.8l1.1-1.6c10.3-14.4 6.9-34.4-7.4-44.6s-34.4-6.9-44.6 7.4l-1.1 1.6C206.5 251.2 213 330 263 380c56.5 56.5 148 56.5 204.5 0L579.8 267.7zM60.2 244.3c-56.5 56.5-56.5 148 0 204.5c50 50 128.8 56.5 186.3 15.4l1.6-1.1c14.4-10.3 17.7-30.3 7.4-44.6s-30.3-17.7-44.6-7.4l-1.6 1.1c-32.1 22.9-76 19.3-103.8-8.6C74 372 74 321 105.5 289.5L217.7 177.2c31.5-31.5 82.5-31.5 114 0c27.9 27.9 31.5 71.8 8.6 103.9l-1.1 1.6c-10.3 14.4-6.9 34.4 7.4 44.6s34.4 6.9 44.6-7.4l1.1-1.6C433.5 260.8 427 182 377 132c-56.5-56.5-148-56.5-204.5 0L60.2 244.3z"/></svg>
    
</a>
</h2>
<p>Here&rsquo;s how long it took to get the binary ready in the same weekly job before and after switching to <code>@v0</code>.</p>
<div class="code-block" data-frame="editor">
    <div class="code-content">
        <i><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M280 64l40 0c35.3 0 64 28.7 64 64l0 320c0 35.3-28.7 64-64 64L64 512c-35.3 0-64-28.7-64-64L0 128C0 92.7 28.7 64 64 64l40 0 9.6 0C121 27.5 153.3 0 192 0s71 27.5 78.4 64l9.6 0zM64 112c-8.8 0-16 7.2-16 16l0 320c0 8.8 7.2 16 16 16l256 0c8.8 0 16-7.2 16-16l0-320c0-8.8-7.2-16-16-16l-16 0 0 24c0 13.3-10.7 24-24 24l-88 0-88 0c-13.3 0-24-10.7-24-24l0-24-16 0zm128-8a24 24 0 1 0 0-48 24 24 0 1 0 0 48z"/></svg></i><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">@main, cold cache   2.5 min     install Rust, build
</span></span><span class="line"><span class="cl">@main, warm cache   22-36 s     install Rust, restore the cache, build
</span></span><span class="line"><span class="cl">@v0                 0.4-1.0 s   download, check the checksum, install</span></span></code></pre></div></div>
</div>
<p>This relies on the runner&rsquo;s folder layout. If the layout changes and rotguard stops finding a ref that looks like a release tag, it builds from the code the runner downloaded. That takes longer, but the job still runs the requested version.</p>
]]></content:encoded></item></channel></rss>