<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>R Engineering Playbook: Software engineering practices</title>
<link>https://insightsurge-dev.web.app/feed-engineering.html</link>
<atom:link href="https://insightsurge-dev.web.app/feed-engineering.xml" rel="self" type="application/rss+xml"/>
<description>Git, CI/CD, security, releases and GxP engineering practice that works in any language.</description>
<language>en</language>
<image>
<url>https://insightsurge-dev.web.app/images/social/default.png</url>
<title>R Engineering Playbook: Software engineering practices</title>
<link>https://insightsurge-dev.web.app/feed-engineering.html</link>
</image>
<generator>quarto-1.8.27</generator>
<lastBuildDate>Sat, 26 Sep 2026 18:30:00 GMT</lastBuildDate>
<item>
  <title>It worked locally: two hosting bugs every check missed</title>
  <link>https://insightsurge-dev.web.app/posts/hosted-site-pitfalls/</link>
  <description><![CDATA[ 





<!--
  Quarto 1.8.27's title-block.html with three changes: category badges and a
  series link ("Testing series · part 2") sit above the title, as in the brand's
  blog kit; and a post or series page with `trailer: true` shows its trailer beside the title
  (_filters/trailer.lua sets trailer-path; _includes/trailers.html plays it). On a Quarto upgrade, diff this against
  share/formats/html/templates/title-block.html and carry over any changes.
-->



<section id="the-problem" class="level2">
<h2 class="anchored" data-anchor-id="the-problem">The problem</h2>
<p>Before the pull request preview, the local verification suite reported success:</p>
<ol type="1">
<li><strong>Rendering:</strong> <code>quarto render</code> generated the entire site without a single warning.</li>
<li><strong>Automated link scanning:</strong> An offline link checker scanned 1,712 internal links across the rendered HTML files and reported 0 broken links.</li>
<li><strong>Automated tests:</strong> The full <code>testthat</code> test suite passed cleanly.</li>
<li><strong>Local manual review:</strong> We started a local <code>python3 -m http.server</code> and typed a post URL with the trailing slash into the browser address bar.</li>
</ol>
<p>The branch was pushed and the pull request opened. CI deployed the rendered site to a Firebase Hosting preview channel (see <a href="https://insightsurge-dev.web.app/posts/quarto-firebase-previews/index.html">Quarto Firebase previews</a>).</p>
<p>Clicking through the preview exposed two hosting bugs.</p>
<section id="bug-1-the-trailing-slash-and-the-404-trap" class="level3">
<h3 class="anchored" data-anchor-id="bug-1-the-trailing-slash-and-the-404-trap">Bug 1: The trailing slash and the 404 trap</h3>
<p>A post card on the blog index (<code>/blog</code>) linked to <code>posts/qc-demo/index.html</code>. After clicking it, the browser address bar showed <code>https://example.web.app/posts/qc-demo</code>.</p>
<p>Near the bottom of the article, clicking the relative <strong>View</strong> link for a companion R script navigated to:</p>
<pre class="text"><code>https://example.web.app/posts/scripts/qc-demo.R</code></pre>
<p>The browser displayed a <code>404 Not Found</code> error page.</p>
<p>Yet the file had been rendered and published. When requested directly at its full path, the server responded with <code>200 OK</code>:</p>
<pre class="text"><code>https://example.web.app/posts/qc-demo/scripts/qc-demo.R</code></pre>
<p>The bug stemmed from how web hosts implement clean URLs. In <code>firebase.json</code>, we had enabled <code>"cleanUrls": true</code>. When a user requests <code>posts/qc-demo/index.html</code>, Firebase Hosting issues an HTTP <code>301 Moved Permanently</code> redirect to <code>/posts/qc-demo</code> (without a trailing slash) and serves the page with <code>200 OK</code>.</p>
<p>Under RFC 3986 (Section 5.2.3, “Merge Paths”), when a browser resolves a relative URL reference that does not begin with a leading slash, it resolves the reference against the directory component of the base URI. When the base URL is <code>https://example.web.app/posts/qc-demo</code>:</p>
<ul>
<li>The final path segment (<code>qc-demo</code>) does not end with a slash, so the browser interprets it as a file name rather than a directory.</li>
<li>The browser strips <code>qc-demo</code> to determine the base directory, leaving <code>https://example.web.app/posts/</code>.</li>
<li>Appending the companion link produces <code>https://example.web.app/posts/scripts/qc-demo.R</code>, which does not exist.</li>
</ul>
<p>Had the base URL contained a trailing slash (<code>https://example.web.app/posts/qc-demo/</code>), the base directory would have remained <code>https://example.web.app/posts/qc-demo/</code>, resolving the relative link to the correct file.</p>
<p>Inspecting the preview server with <code>curl</code> revealed the exact redirect chain:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb3-1"><span class="co" style="color: #5E5E5E;"># Requesting the index file triggers cleanUrls redirect to the non-slashed URL</span></span>
<span id="cb3-2"><span class="ex" style="color: null;">curl</span> <span class="at" style="color: #657422;">-sI</span> https://example.web.app/posts/qc-demo/index.html <span class="kw" style="color: #003B4F;
font-weight: bold;">|</span> <span class="fu" style="color: #4758AB;">grep</span> <span class="at" style="color: #657422;">-E</span> <span class="st" style="color: #20794D;">"^(HTTP|location)"</span></span>
<span id="cb3-3"><span class="co" style="color: #5E5E5E;"># HTTP/2 301</span></span>
<span id="cb3-4"><span class="co" style="color: #5E5E5E;"># location: /posts/qc-demo</span></span>
<span id="cb3-5"></span>
<span id="cb3-6"><span class="co" style="color: #5E5E5E;"># The non-slashed URL serves content directly</span></span>
<span id="cb3-7"><span class="ex" style="color: null;">curl</span> <span class="at" style="color: #657422;">-sI</span> https://example.web.app/posts/qc-demo <span class="kw" style="color: #003B4F;
font-weight: bold;">|</span> <span class="fu" style="color: #4758AB;">grep</span> <span class="at" style="color: #657422;">-E</span> <span class="st" style="color: #20794D;">"^(HTTP)"</span></span>
<span id="cb3-8"><span class="co" style="color: #5E5E5E;"># HTTP/2 200</span></span>
<span id="cb3-9"></span>
<span id="cb3-10"><span class="co" style="color: #5E5E5E;"># The target file exists under the slug directory</span></span>
<span id="cb3-11"><span class="ex" style="color: null;">curl</span> <span class="at" style="color: #657422;">-sI</span> https://example.web.app/posts/qc-demo/scripts/qc-demo.R <span class="kw" style="color: #003B4F;
font-weight: bold;">|</span> <span class="fu" style="color: #4758AB;">grep</span> <span class="at" style="color: #657422;">-E</span> <span class="st" style="color: #20794D;">"^(HTTP)"</span></span>
<span id="cb3-12"><span class="co" style="color: #5E5E5E;"># HTTP/2 200</span></span>
<span id="cb3-13"></span>
<span id="cb3-14"><span class="co" style="color: #5E5E5E;"># But the relative link resolved from the non-slashed base URL hits 404</span></span>
<span id="cb3-15"><span class="ex" style="color: null;">curl</span> <span class="at" style="color: #657422;">-sI</span> https://example.web.app/posts/scripts/qc-demo.R <span class="kw" style="color: #003B4F;
font-weight: bold;">|</span> <span class="fu" style="color: #4758AB;">grep</span> <span class="at" style="color: #657422;">-E</span> <span class="st" style="color: #20794D;">"^(HTTP)"</span></span>
<span id="cb3-16"><span class="co" style="color: #5E5E5E;"># HTTP/2 404</span></span></code></pre></div></div>
<p>Why did local checks miss this?</p>
<ul>
<li><strong>The offline link checker operates on disk:</strong> An offline tool like <code>lychee</code> parses <code>_site/posts/qc-demo/index.html</code> from the file system. Because the file physically resides in <code>_site/posts/qc-demo/</code>, the tool finds the companion file in that directory. An offline scanner does not simulate HTTP redirects.</li>
<li><strong>The local URL kept its slash:</strong> Python’s local server served <code>/posts/qc-demo/</code> without the Firebase redirect, so the browser used the post directory as the base.</li>
<li><strong>Manual review typed the trailing slash:</strong> We typed <code>/posts/qc-demo/</code> into the address bar, masking the redirect from the listing link.</li>
<li><strong>Quarto navigation links did not fail:</strong> Quarto site navigation links (such as <code>../../series/foundations.html</code>) use <code>../</code> to navigate up to the root. Because <code>..</code> cannot ascend above the site root <code>/</code>, those links functioned even from the wrong base path. Only relative child links pointing into the post’s own subdirectory broke.</li>
</ul>
</section>
<section id="bug-2-compressed-responses-and-single-line-r-scripts" class="level3">
<h3 class="anchored" data-anchor-id="bug-2-compressed-responses-and-single-line-r-scripts">Bug 2: Compressed responses and single-line R scripts</h3>
<p>Opening the valid script URL directly showed the second bug:</p>
<pre class="text"><code>https://example.web.app/posts/qc-demo/scripts/qc-demo.R</code></pre>
<p>Instead of displaying formatted R code with newlines and comments, the browser displayed the entire script as a single continuous paragraph of plain text. All indentation and line breaks were collapsed into single spaces.</p>
<p>The browser was rendering the <code>.R</code> file as HTML (<code>text/html</code>), where consecutive whitespace characters are collapsed into a single space per HTML rendering rules.</p>
<p>A plain <code>curl -sI</code> request returned this header:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb5-1"><span class="ex" style="color: null;">curl</span> <span class="at" style="color: #657422;">-sI</span> https://example.web.app/posts/qc-demo/scripts/qc-demo.R <span class="kw" style="color: #003B4F;
font-weight: bold;">|</span> <span class="fu" style="color: #4758AB;">grep</span> <span class="at" style="color: #657422;">-i</span> <span class="st" style="color: #20794D;">"content-type"</span></span>
<span id="cb5-2"><span class="co" style="color: #5E5E5E;"># content-type: text/plain; charset=utf-8</span></span></code></pre></div></div>
<p>The <code>text/plain</code> response looked correct until compression headers were included.</p>
<p>The difference lay in how browsers request content. Modern web browsers automatically send compression request headers: <code>Accept-Encoding: gzip, br</code>. When <code>curl</code> sends those same headers, the server’s response changes:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb6-1"><span class="co" style="color: #5E5E5E;"># Request without compression headers</span></span>
<span id="cb6-2"><span class="ex" style="color: null;">curl</span> <span class="at" style="color: #657422;">-sI</span> https://example.web.app/posts/qc-demo/scripts/qc-demo.R <span class="kw" style="color: #003B4F;
font-weight: bold;">|</span> <span class="fu" style="color: #4758AB;">grep</span> <span class="at" style="color: #657422;">-i</span> <span class="st" style="color: #20794D;">"content-type"</span></span>
<span id="cb6-3"><span class="co" style="color: #5E5E5E;"># content-type: text/plain; charset=utf-8</span></span>
<span id="cb6-4"></span>
<span id="cb6-5"><span class="co" style="color: #5E5E5E;"># Request with browser compression headers</span></span>
<span id="cb6-6"><span class="ex" style="color: null;">curl</span> <span class="at" style="color: #657422;">-sI</span> <span class="at" style="color: #657422;">-H</span> <span class="st" style="color: #20794D;">"Accept-Encoding: gzip, br"</span> https://example.web.app/posts/qc-demo/scripts/qc-demo.R <span class="kw" style="color: #003B4F;
font-weight: bold;">|</span> <span class="fu" style="color: #4758AB;">grep</span> <span class="at" style="color: #657422;">-i</span> <span class="st" style="color: #20794D;">"content-type"</span></span>
<span id="cb6-7"><span class="co" style="color: #5E5E5E;"># content-type: text/html; charset=UTF-8</span></span></code></pre></div></div>
<p>On this deployment, requests with compression headers for <code>.R</code> files and the extensionless Git <code>commit-msg</code> hook returned <code>text/html; charset=UTF-8</code>. By contrast, shell scripts (<code>.sh</code>) returned <code>application/x-sh</code> (prompting a browser download), YAML (<code>.yml</code>) returned <code>text/yaml</code>, and Markdown (<code>.md</code>) returned <code>text/markdown</code>.</p>
<p>We did not find Firebase documentation explaining why compressed responses for unrecognised MIME types default to <code>text/html</code>. We report this strictly as observed production behavior.</p>
</section>
</section>
<section id="the-web-repo-way" class="level2">
<h2 class="anchored" data-anchor-id="the-web-repo-way">The web-repo way</h2>
<p>Front-end web engineering teams have long recognized that local file systems and generic development servers do not replicate the routing, caching, and compression behavior of production content delivery networks (CDNs). They guard against hosting defects using five standard practices:</p>
<ol type="1">
<li><strong>Ephemeral preview environments:</strong> Rather than relying exclusively on local development servers, web teams deploy pull requests to isolated preview channels on the real hosting platform (such as Firebase Hosting preview channels, Netlify Deploy Previews, or Cloudflare Pages branch deployments). The preview exercises the exact edge routing, HTTP caching, and header rewrite rules of production.</li>
<li><strong>Platform emulators for local testing:</strong> The host platform’s emulator can exercise its routing rules locally. For Firebase Hosting, <code>npx firebase-tools emulators:start --only hosting --project demo-preview</code> uses a demo project ID without a Google Cloud login and lets you check clean URLs, redirects, and custom headers.</li>
<li><strong>Browser-realistic smoke tests:</strong> Automated post-deployment checks send realistic browser headers (<code>Accept-Encoding: gzip, br</code> and <code>Accept: text/html,...</code>) to verify status codes, redirect chains (<code>Location</code>), and <code>Content-Type</code> headers.</li>
<li><strong>Explicit configuration over CDN defaults:</strong> Web teams do not rely on default MIME type tables for custom file formats or extensionless assets. They declare explicit MIME mappings and security headers (such as <code>X-Content-Type-Options: nosniff</code>) in their repository configuration files.</li>
<li><strong>Configuration regression tests:</strong> Critical routing and header rules in hosting configuration files are asserted in automated unit tests so they cannot be removed accidentally during repository refactoring.</li>
</ol>
</section>
<section id="the-r-way" class="level2">
<h2 class="anchored" data-anchor-id="the-r-way">The R way</h2>
<p>In the R ecosystem, documentation sites and analysis reports are typically compiled to static HTML directories using Quarto, pkgdown, or R Markdown. Applying web hosting discipline to these sites requires addressing the directory structure, configuring explicit host rules, and adding verification tests.</p>
<section id="directory-layout-and-relative-links-in-r-sites" class="level3">
<h3 class="anchored" data-anchor-id="directory-layout-and-relative-links-in-r-sites">1. Directory layout and relative links in R sites</h3>
<p>Static site generators in R organize content into folders with directory index files:</p>
<ul>
<li>Quarto blog articles: <code>_site/posts/&lt;slug&gt;/index.html</code></li>
<li>pkgdown documentation: <code>docs/reference/index.html</code> and <code>docs/articles/index.html</code></li>
</ul>
<p>In R engineering documentation, articles often reference downloadable companion files—such as runnable analysis scripts, raw CSV datasets, or validation test scripts—using relative paths (for example, <code>[scripts/hosting-check.R](scripts/hosting-check.R)</code>).</p>
<p>When a host serves a directory index at <code>/posts/&lt;slug&gt;</code> without a trailing slash, a relative child link resolves under <code>/posts/</code>. Check the host’s redirects and the final browser URL for pages with links into their own directories.</p>
</section>
<section id="fixing-the-trailing-slash-in-firebase.json" class="level3">
<h3 class="anchored" data-anchor-id="fixing-the-trailing-slash-in-firebase.json">2. Fixing the trailing slash in <code>firebase.json</code></h3>
<p>Firebase Hosting provides a global <code>"trailingSlash": true</code> setting that redirects static content URLs to add a trailing slash. We did not test that option. It would change URLs across the site, so it would need site-wide link and browser checks.</p>
<p>Instead of altering the global slash behavior, we configure a targeted 301 redirect rule in <code>firebase.json</code> using RE2 regular expressions:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode json code-with-copy"><code class="sourceCode json"><span id="cb7-1"><span class="fu" style="color: #4758AB;">{</span></span>
<span id="cb7-2">  <span class="dt" style="color: #AD0000;">"hosting"</span><span class="fu" style="color: #4758AB;">:</span> <span class="fu" style="color: #4758AB;">{</span></span>
<span id="cb7-3">    <span class="dt" style="color: #AD0000;">"public"</span><span class="fu" style="color: #4758AB;">:</span> <span class="st" style="color: #20794D;">"_site"</span><span class="fu" style="color: #4758AB;">,</span></span>
<span id="cb7-4">    <span class="dt" style="color: #AD0000;">"cleanUrls"</span><span class="fu" style="color: #4758AB;">:</span> <span class="kw" style="color: #003B4F;
font-weight: bold;">true</span><span class="fu" style="color: #4758AB;">,</span></span>
<span id="cb7-5">    <span class="dt" style="color: #AD0000;">"redirects"</span><span class="fu" style="color: #4758AB;">:</span> <span class="ot" style="color: #003B4F;">[</span></span>
<span id="cb7-6">      <span class="fu" style="color: #4758AB;">{</span></span>
<span id="cb7-7">        <span class="dt" style="color: #AD0000;">"regex"</span><span class="fu" style="color: #4758AB;">:</span> <span class="st" style="color: #20794D;">"^/posts/([^/.]+)$"</span><span class="fu" style="color: #4758AB;">,</span></span>
<span id="cb7-8">        <span class="dt" style="color: #AD0000;">"destination"</span><span class="fu" style="color: #4758AB;">:</span> <span class="st" style="color: #20794D;">"/posts/:1/"</span><span class="fu" style="color: #4758AB;">,</span></span>
<span id="cb7-9">        <span class="dt" style="color: #AD0000;">"type"</span><span class="fu" style="color: #4758AB;">:</span> <span class="dv" style="color: #AD0000;">301</span></span>
<span id="cb7-10">      <span class="fu" style="color: #4758AB;">}</span></span>
<span id="cb7-11">    <span class="ot" style="color: #003B4F;">]</span></span>
<span id="cb7-12">  <span class="fu" style="color: #4758AB;">}</span></span>
<span id="cb7-13"><span class="fu" style="color: #4758AB;">}</span></span></code></pre></div></div>
<p>This rule matches any URL path under <code>/posts/</code> that contains no subsequent slashes or file extension dots, captures the slug into group <code>:1</code>, and issues an HTTP 301 redirect that appends the trailing slash.</p>
<p>With this rule active, opening an article from the listing involves two redirects, then the page and its companion link:</p>
<ol type="1">
<li><code>posts/qc-demo/index.html</code> triggers a 301 redirect to <code>/posts/qc-demo</code> via <code>cleanUrls</code>.</li>
<li><code>/posts/qc-demo</code> triggers a 301 redirect to <code>/posts/qc-demo/</code> via the regex redirect rule.</li>
<li><code>/posts/qc-demo/</code> serves the rendered page with <code>200 OK</code>.</li>
<li>The relative companion link resolves inside the post directory and returns <code>200 OK</code>.</li>
</ol>
<p>Root pages (such as <code>/blog</code>) remain unaffected.</p>
</section>
<section id="fixing-mime-types-and-compression-headers" class="level3">
<h3 class="anchored" data-anchor-id="fixing-mime-types-and-compression-headers">3. Fixing MIME types and compression headers</h3>
<p>There is no standard media type for R source files. To ensure that R scripts, shell scripts, and extensionless files are delivered as plain text across all compression encodings, we define explicit <code>headers</code> in <code>firebase.json</code>:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode json code-with-copy"><code class="sourceCode json"><span id="cb8-1"><span class="fu" style="color: #4758AB;">{</span></span>
<span id="cb8-2">  <span class="dt" style="color: #AD0000;">"hosting"</span><span class="fu" style="color: #4758AB;">:</span> <span class="fu" style="color: #4758AB;">{</span></span>
<span id="cb8-3">    <span class="dt" style="color: #AD0000;">"headers"</span><span class="fu" style="color: #4758AB;">:</span> <span class="ot" style="color: #003B4F;">[</span></span>
<span id="cb8-4">      <span class="fu" style="color: #4758AB;">{</span></span>
<span id="cb8-5">        <span class="dt" style="color: #AD0000;">"source"</span><span class="fu" style="color: #4758AB;">:</span> <span class="st" style="color: #20794D;">"**/*.@(R|sh)"</span><span class="fu" style="color: #4758AB;">,</span></span>
<span id="cb8-6">        <span class="dt" style="color: #AD0000;">"headers"</span><span class="fu" style="color: #4758AB;">:</span> <span class="ot" style="color: #003B4F;">[</span></span>
<span id="cb8-7">          <span class="fu" style="color: #4758AB;">{</span> <span class="dt" style="color: #AD0000;">"key"</span><span class="fu" style="color: #4758AB;">:</span> <span class="st" style="color: #20794D;">"Content-Type"</span><span class="fu" style="color: #4758AB;">,</span> <span class="dt" style="color: #AD0000;">"value"</span><span class="fu" style="color: #4758AB;">:</span> <span class="st" style="color: #20794D;">"text/plain; charset=utf-8"</span> <span class="fu" style="color: #4758AB;">}</span><span class="ot" style="color: #003B4F;">,</span></span>
<span id="cb8-8">          <span class="fu" style="color: #4758AB;">{</span> <span class="dt" style="color: #AD0000;">"key"</span><span class="fu" style="color: #4758AB;">:</span> <span class="st" style="color: #20794D;">"X-Content-Type-Options"</span><span class="fu" style="color: #4758AB;">,</span> <span class="dt" style="color: #AD0000;">"value"</span><span class="fu" style="color: #4758AB;">:</span> <span class="st" style="color: #20794D;">"nosniff"</span> <span class="fu" style="color: #4758AB;">}</span></span>
<span id="cb8-9">        <span class="ot" style="color: #003B4F;">]</span></span>
<span id="cb8-10">      <span class="fu" style="color: #4758AB;">}</span><span class="ot" style="color: #003B4F;">,</span></span>
<span id="cb8-11">      <span class="fu" style="color: #4758AB;">{</span></span>
<span id="cb8-12">        <span class="dt" style="color: #AD0000;">"source"</span><span class="fu" style="color: #4758AB;">:</span> <span class="st" style="color: #20794D;">"/templates/git-hooks/commit-msg"</span><span class="fu" style="color: #4758AB;">,</span></span>
<span id="cb8-13">        <span class="dt" style="color: #AD0000;">"headers"</span><span class="fu" style="color: #4758AB;">:</span> <span class="ot" style="color: #003B4F;">[</span></span>
<span id="cb8-14">          <span class="fu" style="color: #4758AB;">{</span> <span class="dt" style="color: #AD0000;">"key"</span><span class="fu" style="color: #4758AB;">:</span> <span class="st" style="color: #20794D;">"Content-Type"</span><span class="fu" style="color: #4758AB;">,</span> <span class="dt" style="color: #AD0000;">"value"</span><span class="fu" style="color: #4758AB;">:</span> <span class="st" style="color: #20794D;">"text/plain; charset=utf-8"</span> <span class="fu" style="color: #4758AB;">}</span><span class="ot" style="color: #003B4F;">,</span></span>
<span id="cb8-15">          <span class="fu" style="color: #4758AB;">{</span> <span class="dt" style="color: #AD0000;">"key"</span><span class="fu" style="color: #4758AB;">:</span> <span class="st" style="color: #20794D;">"X-Content-Type-Options"</span><span class="fu" style="color: #4758AB;">,</span> <span class="dt" style="color: #AD0000;">"value"</span><span class="fu" style="color: #4758AB;">:</span> <span class="st" style="color: #20794D;">"nosniff"</span> <span class="fu" style="color: #4758AB;">}</span></span>
<span id="cb8-16">        <span class="ot" style="color: #003B4F;">]</span></span>
<span id="cb8-17">      <span class="fu" style="color: #4758AB;">}</span></span>
<span id="cb8-18">    <span class="ot" style="color: #003B4F;">]</span></span>
<span id="cb8-19">  <span class="fu" style="color: #4758AB;">}</span></span>
<span id="cb8-20"><span class="fu" style="color: #4758AB;">}</span></span></code></pre></div></div>
<p>The <code>X-Content-Type-Options: nosniff</code> header instructs browsers to follow the declared MIME type strictly, preventing browsers from attempting MIME type sniffing on response bodies.</p>
</section>
<section id="testing-like-a-browser" class="level3">
<h3 class="anchored" data-anchor-id="testing-like-a-browser">4. Testing like a browser</h3>
<p>To catch hosting bugs before release, teams should incorporate browser-like verification into their routine R workflow:</p>
<p>First, test locally using the platform emulator rather than a generic server:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb9-1"><span class="ex" style="color: null;">npx</span> firebase-tools emulators:start <span class="at" style="color: #657422;">--only</span> hosting <span class="at" style="color: #657422;">--project</span> demo-preview</span></code></pre></div></div>
<p>Second, follow the real user path: open the listing page, click into an article card, and click a companion script link.</p>
<p>Third, verify HTTP response headers using <code>curl</code> with compression flags enabled:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb10-1"><span class="ex" style="color: null;">curl</span> <span class="at" style="color: #657422;">-sI</span> <span class="at" style="color: #657422;">-H</span> <span class="st" style="color: #20794D;">"Accept-Encoding: gzip, br"</span> https://example.web.app/posts/qc-demo/scripts/qc-demo.R</span></code></pre></div></div>
<p>Fourth, write guardrail tests in <code>testthat</code> to ensure that hosting configuration rules cannot be deleted inadvertently:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r norun code-with-copy"><code class="sourceCode r"><span id="cb11-1"><span class="co" style="color: #5E5E5E;"># Read the hosting configuration committed with the site.</span></span>
<span id="cb11-2">config_text <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">paste</span>(<span class="fu" style="color: #4758AB;">readLines</span>(<span class="st" style="color: #20794D;">"firebase.json"</span>), <span class="at" style="color: #657422;">collapse =</span> <span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb11-3"></span>
<span id="cb11-4"><span class="fu" style="color: #4758AB;">test_that</span>(<span class="st" style="color: #20794D;">"hosting configuration retains redirect and header guardrails"</span>, {</span>
<span id="cb11-5">  <span class="fu" style="color: #4758AB;">expect_match</span>(config_text, <span class="st" style="color: #20794D;">'"regex": "^/posts/([^/.]+)$"'</span>, <span class="at" style="color: #657422;">fixed =</span> <span class="cn" style="color: #8f5902;">TRUE</span>)</span>
<span id="cb11-6">  <span class="fu" style="color: #4758AB;">expect_match</span>(config_text, <span class="st" style="color: #20794D;">'"destination": "/posts/:1/"'</span>, <span class="at" style="color: #657422;">fixed =</span> <span class="cn" style="color: #8f5902;">TRUE</span>)</span>
<span id="cb11-7">  <span class="fu" style="color: #4758AB;">expect_match</span>(config_text, <span class="st" style="color: #20794D;">'"source": "**/*.@(R|sh)"'</span>, <span class="at" style="color: #657422;">fixed =</span> <span class="cn" style="color: #8f5902;">TRUE</span>)</span>
<span id="cb11-8">  <span class="fu" style="color: #4758AB;">expect_match</span>(config_text, <span class="st" style="color: #20794D;">'"source": "/templates/git-hooks/commit-msg"'</span>, <span class="at" style="color: #657422;">fixed =</span> <span class="cn" style="color: #8f5902;">TRUE</span>)</span>
<span id="cb11-9">  <span class="fu" style="color: #4758AB;">expect_match</span>(config_text, <span class="st" style="color: #20794D;">'"value": "text/plain; charset=utf-8"'</span>, <span class="at" style="color: #657422;">fixed =</span> <span class="cn" style="color: #8f5902;">TRUE</span>)</span>
<span id="cb11-10">})</span></code></pre></div></div>
</section>
<section id="other-static-hosting-platforms" class="level3">
<h3 class="anchored" data-anchor-id="other-static-hosting-platforms">5. Other static hosting platforms</h3>
<p>Different static hosting platforms document their own URL and header rules:</p>
<ul>
<li><strong>Netlify:</strong> With Pretty URLs enabled (the default), Netlify forwards a path such as <code>/about</code> to <code>/about/</code> and rewrites <code>/about.html</code> to <code>/about/</code>. Custom headers can be set in <code>_headers</code> or <code>netlify.toml</code>.</li>
<li><strong>Cloudflare Pages:</strong> Its serving rules redirect <code>/about/index.html</code> to <code>/about/</code>. Custom static-asset headers can be set in a <code>_headers</code> file in the build output.</li>
</ul>
<p>Regardless of which hosting platform you use, verify your URLs with <code>curl -sI -H "Accept-Encoding: gzip, br" &lt;url&gt;</code> before sharing rendered documentation with readers.</p>
</section>
</section>
<section id="companion-code" class="level2">
<h2 class="anchored" data-anchor-id="companion-code">Companion code</h2>
<p><a href="https://insightsurge-dev.web.app/posts/hosted-site-pitfalls/scripts/hosting-check.R">View <code>hosting-check.R</code></a> · <a href="https://insightsurge-dev.web.app/posts/hosted-site-pitfalls/scripts/hosting-check.R" download="hosting-check.R">Download</a></p>
<p>A standalone verification script that scans rendered site directories for relative link traps in directory index pages and verifies HTTP response headers against browser compression encodings. Written in base R and verified with <code>testthat</code>.</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Full script: <code>hosting-check.R</code>
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><span class="co" style="color: #5E5E5E;"># Host verification checks: detects trailing-slash relative link traps</span></span>
<span id="cb12-2"><span class="co" style="color: #5E5E5E;"># in rendered sites and verifies HTTP response headers for non-HTML assets.</span></span>
<span id="cb12-3"><span class="co" style="color: #5E5E5E;">#</span></span>
<span id="cb12-4"><span class="co" style="color: #5E5E5E;"># Run with:</span></span>
<span id="cb12-5"><span class="co" style="color: #5E5E5E;">#   Rscript hosting-check.R</span></span>
<span id="cb12-6"><span class="co" style="color: #5E5E5E;">#   Rscript hosting-check.R --site _site</span></span>
<span id="cb12-7"><span class="co" style="color: #5E5E5E;">#   Rscript hosting-check.R --url https://example.web.app/posts/slug/scripts/demo.R</span></span>
<span id="cb12-8"></span>
<span id="cb12-9"><span class="co" style="color: #5E5E5E;">#' Scan a rendered directory for relative links vulnerable to trailing-slash stripping</span></span>
<span id="cb12-10"><span class="co" style="color: #5E5E5E;">#'</span></span>
<span id="cb12-11"><span class="co" style="color: #5E5E5E;">#' In static site hosting, directory pages served as `&lt;dir&gt;/index.html` often have</span></span>
<span id="cb12-12"><span class="co" style="color: #5E5E5E;">#' the `.html` extension stripped by clean URL rules. If the host serves the page</span></span>
<span id="cb12-13"><span class="co" style="color: #5E5E5E;">#' at `/dir` without a trailing slash, RFC 3986 path resolution strips `dir` as a</span></span>
<span id="cb12-14"><span class="co" style="color: #5E5E5E;">#' file component and resolves relative links against the parent directory.</span></span>
<span id="cb12-15"><span class="co" style="color: #5E5E5E;">#' This function finds all relative child links within directory index pages.</span></span>
<span id="cb12-16"><span class="co" style="color: #5E5E5E;">#'</span></span>
<span id="cb12-17"><span class="co" style="color: #5E5E5E;">#' @param site_dir Path to the rendered site directory (default "_site").</span></span>
<span id="cb12-18"><span class="co" style="color: #5E5E5E;">#' @return A data frame with columns: page, target, resolved_path, exists.</span></span>
<span id="cb12-19">find_relative_directory_links <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">function</span>(<span class="at" style="color: #657422;">site_dir =</span> <span class="st" style="color: #20794D;">"_site"</span>) {</span>
<span id="cb12-20">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="sc" style="color: #5E5E5E;">!</span><span class="fu" style="color: #4758AB;">dir.exists</span>(site_dir)) {</span>
<span id="cb12-21">    <span class="fu" style="color: #4758AB;">return</span>(<span class="fu" style="color: #4758AB;">data.frame</span>(</span>
<span id="cb12-22">      <span class="at" style="color: #657422;">page =</span> <span class="fu" style="color: #4758AB;">character</span>(),</span>
<span id="cb12-23">      <span class="at" style="color: #657422;">target =</span> <span class="fu" style="color: #4758AB;">character</span>(),</span>
<span id="cb12-24">      <span class="at" style="color: #657422;">resolved_path =</span> <span class="fu" style="color: #4758AB;">character</span>(),</span>
<span id="cb12-25">      <span class="at" style="color: #657422;">exists =</span> <span class="fu" style="color: #4758AB;">logical</span>(),</span>
<span id="cb12-26">      <span class="at" style="color: #657422;">stringsAsFactors =</span> <span class="cn" style="color: #8f5902;">FALSE</span></span>
<span id="cb12-27">    ))</span>
<span id="cb12-28">  }</span>
<span id="cb12-29"></span>
<span id="cb12-30">  all_indices <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">list.files</span>(</span>
<span id="cb12-31">    site_dir,</span>
<span id="cb12-32">    <span class="at" style="color: #657422;">pattern =</span> <span class="st" style="color: #20794D;">"^index</span><span class="sc" style="color: #5E5E5E;">\\</span><span class="st" style="color: #20794D;">.html$"</span>,</span>
<span id="cb12-33">    <span class="at" style="color: #657422;">recursive =</span> <span class="cn" style="color: #8f5902;">TRUE</span>,</span>
<span id="cb12-34">    <span class="at" style="color: #657422;">full.names =</span> <span class="cn" style="color: #8f5902;">FALSE</span></span>
<span id="cb12-35">  )</span>
<span id="cb12-36"></span>
<span id="cb12-37">  <span class="co" style="color: #5E5E5E;"># Only inspect index.html files located inside subdirectories</span></span>
<span id="cb12-38">  sub_indices <span class="ot" style="color: #003B4F;">&lt;-</span> all_indices[<span class="fu" style="color: #4758AB;">dirname</span>(all_indices) <span class="sc" style="color: #5E5E5E;">!=</span> <span class="st" style="color: #20794D;">"."</span>]</span>
<span id="cb12-39"></span>
<span id="cb12-40">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">length</span>(sub_indices) <span class="sc" style="color: #5E5E5E;">==</span> <span class="dv" style="color: #AD0000;">0</span>L) {</span>
<span id="cb12-41">    <span class="fu" style="color: #4758AB;">return</span>(<span class="fu" style="color: #4758AB;">data.frame</span>(</span>
<span id="cb12-42">      <span class="at" style="color: #657422;">page =</span> <span class="fu" style="color: #4758AB;">character</span>(),</span>
<span id="cb12-43">      <span class="at" style="color: #657422;">target =</span> <span class="fu" style="color: #4758AB;">character</span>(),</span>
<span id="cb12-44">      <span class="at" style="color: #657422;">resolved_path =</span> <span class="fu" style="color: #4758AB;">character</span>(),</span>
<span id="cb12-45">      <span class="at" style="color: #657422;">exists =</span> <span class="fu" style="color: #4758AB;">logical</span>(),</span>
<span id="cb12-46">      <span class="at" style="color: #657422;">stringsAsFactors =</span> <span class="cn" style="color: #8f5902;">FALSE</span></span>
<span id="cb12-47">    ))</span>
<span id="cb12-48">  }</span>
<span id="cb12-49"></span>
<span id="cb12-50">  results <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">list</span>()</span>
<span id="cb12-51"></span>
<span id="cb12-52">  <span class="cf" style="color: #003B4F;
font-weight: bold;">for</span> (sub_index <span class="cf" style="color: #003B4F;
font-weight: bold;">in</span> sub_indices) {</span>
<span id="cb12-53">    full_index_path <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">file.path</span>(site_dir, sub_index)</span>
<span id="cb12-54">    lines <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">readLines</span>(full_index_path, <span class="at" style="color: #657422;">warn =</span> <span class="cn" style="color: #8f5902;">FALSE</span>)</span>
<span id="cb12-55">    page_dir <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">dirname</span>(sub_index)</span>
<span id="cb12-56"></span>
<span id="cb12-57">    <span class="co" style="color: #5E5E5E;"># Extract href and src attribute values</span></span>
<span id="cb12-58">    href_matches <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">regmatches</span>(</span>
<span id="cb12-59">      lines,</span>
<span id="cb12-60">      <span class="fu" style="color: #4758AB;">gregexpr</span>(<span class="st" style="color: #20794D;">'(?:href|src)=["</span><span class="sc" style="color: #5E5E5E;">\'</span><span class="st" style="color: #20794D;">]([^"</span><span class="sc" style="color: #5E5E5E;">\'</span><span class="st" style="color: #20794D;">]+)["</span><span class="sc" style="color: #5E5E5E;">\'</span><span class="st" style="color: #20794D;">]'</span>, lines, <span class="at" style="color: #657422;">perl =</span> <span class="cn" style="color: #8f5902;">TRUE</span>)</span>
<span id="cb12-61">    )</span>
<span id="cb12-62"></span>
<span id="cb12-63">    targets <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">character</span>()</span>
<span id="cb12-64">    <span class="cf" style="color: #003B4F;
font-weight: bold;">for</span> (m <span class="cf" style="color: #003B4F;
font-weight: bold;">in</span> href_matches) {</span>
<span id="cb12-65">      <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">length</span>(m) <span class="sc" style="color: #5E5E5E;">&gt;</span> <span class="dv" style="color: #AD0000;">0</span>L) {</span>
<span id="cb12-66">        cleaned <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">sub</span>(<span class="st" style="color: #20794D;">'^(?:href|src)=["</span><span class="sc" style="color: #5E5E5E;">\'</span><span class="st" style="color: #20794D;">]'</span>, <span class="st" style="color: #20794D;">""</span>, m)</span>
<span id="cb12-67">        cleaned <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">sub</span>(<span class="st" style="color: #20794D;">'["</span><span class="sc" style="color: #5E5E5E;">\'</span><span class="st" style="color: #20794D;">]$'</span>, <span class="st" style="color: #20794D;">""</span>, cleaned)</span>
<span id="cb12-68">        targets <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">c</span>(targets, cleaned)</span>
<span id="cb12-69">      }</span>
<span id="cb12-70">    }</span>
<span id="cb12-71">    targets <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">unique</span>(targets)</span>
<span id="cb12-72"></span>
<span id="cb12-73">    <span class="co" style="color: #5E5E5E;"># Filter out anchors, query-only, root-relative, parent-relative, and URI schemes</span></span>
<span id="cb12-74">    is_scheme <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">grepl</span>(<span class="st" style="color: #20794D;">"^[a-zA-Z][a-zA-Z0-9+.-]*:"</span>, targets)</span>
<span id="cb12-75">    is_root_rel <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">startsWith</span>(targets, <span class="st" style="color: #20794D;">"/"</span>)</span>
<span id="cb12-76">    is_anchor <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">startsWith</span>(targets, <span class="st" style="color: #20794D;">"#"</span>)</span>
<span id="cb12-77">    is_query <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">startsWith</span>(targets, <span class="st" style="color: #20794D;">"?"</span>)</span>
<span id="cb12-78">    is_parent_rel <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">startsWith</span>(targets, <span class="st" style="color: #20794D;">"../"</span>)</span>
<span id="cb12-79">    is_blank <span class="ot" style="color: #003B4F;">&lt;-</span> targets <span class="sc" style="color: #5E5E5E;">==</span> <span class="st" style="color: #20794D;">""</span></span>
<span id="cb12-80"></span>
<span id="cb12-81">    child_relative <span class="ot" style="color: #003B4F;">&lt;-</span> targets[</span>
<span id="cb12-82">      <span class="sc" style="color: #5E5E5E;">!</span>is_scheme <span class="sc" style="color: #5E5E5E;">&amp;</span></span>
<span id="cb12-83">        <span class="sc" style="color: #5E5E5E;">!</span>is_root_rel <span class="sc" style="color: #5E5E5E;">&amp;</span></span>
<span id="cb12-84">        <span class="sc" style="color: #5E5E5E;">!</span>is_anchor <span class="sc" style="color: #5E5E5E;">&amp;</span></span>
<span id="cb12-85">        <span class="sc" style="color: #5E5E5E;">!</span>is_query <span class="sc" style="color: #5E5E5E;">&amp;</span></span>
<span id="cb12-86">        <span class="sc" style="color: #5E5E5E;">!</span>is_parent_rel <span class="sc" style="color: #5E5E5E;">&amp;</span></span>
<span id="cb12-87">        <span class="sc" style="color: #5E5E5E;">!</span>is_blank</span>
<span id="cb12-88">    ]</span>
<span id="cb12-89"></span>
<span id="cb12-90">    <span class="cf" style="color: #003B4F;
font-weight: bold;">for</span> (target <span class="cf" style="color: #003B4F;
font-weight: bold;">in</span> child_relative) {</span>
<span id="cb12-91">      <span class="co" style="color: #5E5E5E;"># Strip anchor or query string for disk path check</span></span>
<span id="cb12-92">      disk_target <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">sub</span>(<span class="st" style="color: #20794D;">"[?#].*$"</span>, <span class="st" style="color: #20794D;">""</span>, target)</span>
<span id="cb12-93">      resolved_rel <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">file.path</span>(page_dir, disk_target)</span>
<span id="cb12-94">      target_exists <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">file.exists</span>(<span class="fu" style="color: #4758AB;">file.path</span>(site_dir, resolved_rel))</span>
<span id="cb12-95"></span>
<span id="cb12-96">      results[[<span class="fu" style="color: #4758AB;">length</span>(results) <span class="sc" style="color: #5E5E5E;">+</span> <span class="dv" style="color: #AD0000;">1</span>L]] <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">list</span>(</span>
<span id="cb12-97">        <span class="at" style="color: #657422;">page =</span> sub_index,</span>
<span id="cb12-98">        <span class="at" style="color: #657422;">target =</span> target,</span>
<span id="cb12-99">        <span class="at" style="color: #657422;">resolved_path =</span> resolved_rel,</span>
<span id="cb12-100">        <span class="at" style="color: #657422;">exists =</span> target_exists</span>
<span id="cb12-101">      )</span>
<span id="cb12-102">    }</span>
<span id="cb12-103">  }</span>
<span id="cb12-104"></span>
<span id="cb12-105">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">length</span>(results) <span class="sc" style="color: #5E5E5E;">==</span> <span class="dv" style="color: #AD0000;">0</span>L) {</span>
<span id="cb12-106">    <span class="fu" style="color: #4758AB;">return</span>(<span class="fu" style="color: #4758AB;">data.frame</span>(</span>
<span id="cb12-107">      <span class="at" style="color: #657422;">page =</span> <span class="fu" style="color: #4758AB;">character</span>(),</span>
<span id="cb12-108">      <span class="at" style="color: #657422;">target =</span> <span class="fu" style="color: #4758AB;">character</span>(),</span>
<span id="cb12-109">      <span class="at" style="color: #657422;">resolved_path =</span> <span class="fu" style="color: #4758AB;">character</span>(),</span>
<span id="cb12-110">      <span class="at" style="color: #657422;">exists =</span> <span class="fu" style="color: #4758AB;">logical</span>(),</span>
<span id="cb12-111">      <span class="at" style="color: #657422;">stringsAsFactors =</span> <span class="cn" style="color: #8f5902;">FALSE</span></span>
<span id="cb12-112">    ))</span>
<span id="cb12-113">  }</span>
<span id="cb12-114"></span>
<span id="cb12-115">  <span class="fu" style="color: #4758AB;">do.call</span>(rbind, <span class="fu" style="color: #4758AB;">lapply</span>(results, as.data.frame, <span class="at" style="color: #657422;">stringsAsFactors =</span> <span class="cn" style="color: #8f5902;">FALSE</span>))</span>
<span id="cb12-116">}</span>
<span id="cb12-117"></span>
<span id="cb12-118"><span class="co" style="color: #5E5E5E;">#' Parse raw HTTP response headers</span></span>
<span id="cb12-119"><span class="co" style="color: #5E5E5E;">#'</span></span>
<span id="cb12-120"><span class="co" style="color: #5E5E5E;">#' Parses raw header lines returned by curl into structured status and header fields.</span></span>
<span id="cb12-121"><span class="co" style="color: #5E5E5E;">#' Correctly handles redirect chains (e.g. 301 followed by 200).</span></span>
<span id="cb12-122"><span class="co" style="color: #5E5E5E;">#'</span></span>
<span id="cb12-123"><span class="co" style="color: #5E5E5E;">#' @param raw_headers Character vector of header lines, or a single newline-delimited string.</span></span>
<span id="cb12-124"><span class="co" style="color: #5E5E5E;">#' @return A list with status_code, protocol, headers (named vector), redirects, and chain.</span></span>
<span id="cb12-125">parse_http_headers <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">function</span>(raw_headers) {</span>
<span id="cb12-126">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">length</span>(raw_headers) <span class="sc" style="color: #5E5E5E;">==</span> <span class="dv" style="color: #AD0000;">1</span>L <span class="sc" style="color: #5E5E5E;">&amp;&amp;</span> <span class="fu" style="color: #4758AB;">grepl</span>(<span class="st" style="color: #20794D;">"[</span><span class="sc" style="color: #5E5E5E;">\r\n</span><span class="st" style="color: #20794D;">]"</span>, raw_headers)) {</span>
<span id="cb12-127">    lines <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">strsplit</span>(raw_headers, <span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\r</span><span class="st" style="color: #20794D;">?</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)[[<span class="dv" style="color: #AD0000;">1</span>]]</span>
<span id="cb12-128">  } <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> {</span>
<span id="cb12-129">    lines <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">as.character</span>(raw_headers)</span>
<span id="cb12-130">  }</span>
<span id="cb12-131"></span>
<span id="cb12-132">  lines <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">trimws</span>(lines)</span>
<span id="cb12-133">  lines <span class="ot" style="color: #003B4F;">&lt;-</span> lines[lines <span class="sc" style="color: #5E5E5E;">!=</span> <span class="st" style="color: #20794D;">""</span>]</span>
<span id="cb12-134"></span>
<span id="cb12-135">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">length</span>(lines) <span class="sc" style="color: #5E5E5E;">==</span> <span class="dv" style="color: #AD0000;">0</span>L) {</span>
<span id="cb12-136">    <span class="fu" style="color: #4758AB;">return</span>(<span class="fu" style="color: #4758AB;">list</span>(</span>
<span id="cb12-137">      <span class="at" style="color: #657422;">status_code =</span> <span class="cn" style="color: #8f5902;">NA_integer_</span>,</span>
<span id="cb12-138">      <span class="at" style="color: #657422;">protocol =</span> <span class="cn" style="color: #8f5902;">NA_character_</span>,</span>
<span id="cb12-139">      <span class="at" style="color: #657422;">headers =</span> <span class="fu" style="color: #4758AB;">character</span>(),</span>
<span id="cb12-140">      <span class="at" style="color: #657422;">redirects =</span> <span class="fu" style="color: #4758AB;">list</span>(),</span>
<span id="cb12-141">      <span class="at" style="color: #657422;">chain =</span> <span class="fu" style="color: #4758AB;">integer</span>()</span>
<span id="cb12-142">    ))</span>
<span id="cb12-143">  }</span>
<span id="cb12-144"></span>
<span id="cb12-145">  <span class="co" style="color: #5E5E5E;"># Identify HTTP status lines (e.g. "HTTP/1.1 301 Moved Permanently" or "HTTP/2 200")</span></span>
<span id="cb12-146">  status_indices <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">grep</span>(<span class="st" style="color: #20794D;">"^HTTP/[0-9.]+ +[0-9]{3}"</span>, lines)</span>
<span id="cb12-147"></span>
<span id="cb12-148">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">length</span>(status_indices) <span class="sc" style="color: #5E5E5E;">==</span> <span class="dv" style="color: #AD0000;">0</span>L) {</span>
<span id="cb12-149">    <span class="fu" style="color: #4758AB;">return</span>(<span class="fu" style="color: #4758AB;">list</span>(</span>
<span id="cb12-150">      <span class="at" style="color: #657422;">status_code =</span> <span class="cn" style="color: #8f5902;">NA_integer_</span>,</span>
<span id="cb12-151">      <span class="at" style="color: #657422;">protocol =</span> <span class="cn" style="color: #8f5902;">NA_character_</span>,</span>
<span id="cb12-152">      <span class="at" style="color: #657422;">headers =</span> <span class="fu" style="color: #4758AB;">character</span>(),</span>
<span id="cb12-153">      <span class="at" style="color: #657422;">redirects =</span> <span class="fu" style="color: #4758AB;">list</span>(),</span>
<span id="cb12-154">      <span class="at" style="color: #657422;">chain =</span> <span class="fu" style="color: #4758AB;">integer</span>()</span>
<span id="cb12-155">    ))</span>
<span id="cb12-156">  }</span>
<span id="cb12-157"></span>
<span id="cb12-158">  responses <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">list</span>()</span>
<span id="cb12-159">  <span class="cf" style="color: #003B4F;
font-weight: bold;">for</span> (i <span class="cf" style="color: #003B4F;
font-weight: bold;">in</span> <span class="fu" style="color: #4758AB;">seq_along</span>(status_indices)) {</span>
<span id="cb12-160">    start_idx <span class="ot" style="color: #003B4F;">&lt;-</span> status_indices[i]</span>
<span id="cb12-161">    end_idx <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (i <span class="sc" style="color: #5E5E5E;">&lt;</span> <span class="fu" style="color: #4758AB;">length</span>(status_indices)) {</span>
<span id="cb12-162">      status_indices[i <span class="sc" style="color: #5E5E5E;">+</span> <span class="dv" style="color: #AD0000;">1</span>L] <span class="sc" style="color: #5E5E5E;">-</span> <span class="dv" style="color: #AD0000;">1</span>L</span>
<span id="cb12-163">    } <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> {</span>
<span id="cb12-164">      <span class="fu" style="color: #4758AB;">length</span>(lines)</span>
<span id="cb12-165">    }</span>
<span id="cb12-166">    block_lines <span class="ot" style="color: #003B4F;">&lt;-</span> lines[start_idx<span class="sc" style="color: #5E5E5E;">:</span>end_idx]</span>
<span id="cb12-167"></span>
<span id="cb12-168">    status_line <span class="ot" style="color: #003B4F;">&lt;-</span> block_lines[<span class="dv" style="color: #AD0000;">1</span>]</span>
<span id="cb12-169">    status_match <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">regexec</span>(</span>
<span id="cb12-170">      <span class="st" style="color: #20794D;">"^([A-Za-z0-9/.]+) +([0-9]{3})(?: +(.*))?$"</span>,</span>
<span id="cb12-171">      status_line</span>
<span id="cb12-172">    )</span>
<span id="cb12-173">    status_parts <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">regmatches</span>(status_line, status_match)[[<span class="dv" style="color: #AD0000;">1</span>]]</span>
<span id="cb12-174"></span>
<span id="cb12-175">    proto <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">length</span>(status_parts) <span class="sc" style="color: #5E5E5E;">&gt;=</span> <span class="dv" style="color: #AD0000;">2</span>L) status_parts[<span class="dv" style="color: #AD0000;">2</span>] <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> <span class="cn" style="color: #8f5902;">NA_character_</span></span>
<span id="cb12-176">    code <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">length</span>(status_parts) <span class="sc" style="color: #5E5E5E;">&gt;=</span> <span class="dv" style="color: #AD0000;">3</span>L) {</span>
<span id="cb12-177">      <span class="fu" style="color: #4758AB;">as.integer</span>(status_parts[<span class="dv" style="color: #AD0000;">3</span>])</span>
<span id="cb12-178">    } <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> {</span>
<span id="cb12-179">      <span class="cn" style="color: #8f5902;">NA_integer_</span></span>
<span id="cb12-180">    }</span>
<span id="cb12-181"></span>
<span id="cb12-182">    header_lines <span class="ot" style="color: #003B4F;">&lt;-</span> block_lines[<span class="sc" style="color: #5E5E5E;">-</span><span class="dv" style="color: #AD0000;">1</span>]</span>
<span id="cb12-183">    parsed_headers <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">character</span>()</span>
<span id="cb12-184"></span>
<span id="cb12-185">    <span class="cf" style="color: #003B4F;
font-weight: bold;">for</span> (h_line <span class="cf" style="color: #003B4F;
font-weight: bold;">in</span> header_lines) {</span>
<span id="cb12-186">      sep_idx <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">regexpr</span>(<span class="st" style="color: #20794D;">":"</span>, h_line, <span class="at" style="color: #657422;">fixed =</span> <span class="cn" style="color: #8f5902;">TRUE</span>)</span>
<span id="cb12-187">      <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (sep_idx <span class="sc" style="color: #5E5E5E;">&gt;</span> <span class="dv" style="color: #AD0000;">0</span>L) {</span>
<span id="cb12-188">        key <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">tolower</span>(<span class="fu" style="color: #4758AB;">trimws</span>(<span class="fu" style="color: #4758AB;">substr</span>(h_line, <span class="dv" style="color: #AD0000;">1</span>L, sep_idx <span class="sc" style="color: #5E5E5E;">-</span> <span class="dv" style="color: #AD0000;">1</span>L)))</span>
<span id="cb12-189">        val <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">trimws</span>(<span class="fu" style="color: #4758AB;">substr</span>(h_line, sep_idx <span class="sc" style="color: #5E5E5E;">+</span> <span class="dv" style="color: #AD0000;">1</span>L, <span class="fu" style="color: #4758AB;">nchar</span>(h_line)))</span>
<span id="cb12-190">        parsed_headers[key] <span class="ot" style="color: #003B4F;">&lt;-</span> val</span>
<span id="cb12-191">      }</span>
<span id="cb12-192">    }</span>
<span id="cb12-193"></span>
<span id="cb12-194">    responses[[<span class="fu" style="color: #4758AB;">length</span>(responses) <span class="sc" style="color: #5E5E5E;">+</span> <span class="dv" style="color: #AD0000;">1</span>L]] <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">list</span>(</span>
<span id="cb12-195">      <span class="at" style="color: #657422;">protocol =</span> proto,</span>
<span id="cb12-196">      <span class="at" style="color: #657422;">status_code =</span> code,</span>
<span id="cb12-197">      <span class="at" style="color: #657422;">headers =</span> parsed_headers</span>
<span id="cb12-198">    )</span>
<span id="cb12-199">  }</span>
<span id="cb12-200"></span>
<span id="cb12-201">  final_resp <span class="ot" style="color: #003B4F;">&lt;-</span> responses[[<span class="fu" style="color: #4758AB;">length</span>(responses)]]</span>
<span id="cb12-202">  chain <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">vapply</span>(responses, <span class="cf" style="color: #003B4F;
font-weight: bold;">function</span>(r) r<span class="sc" style="color: #5E5E5E;">$</span>status_code, <span class="fu" style="color: #4758AB;">integer</span>(<span class="dv" style="color: #AD0000;">1</span>))</span>
<span id="cb12-203"></span>
<span id="cb12-204">  redirects <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">list</span>()</span>
<span id="cb12-205">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">length</span>(responses) <span class="sc" style="color: #5E5E5E;">&gt;</span> <span class="dv" style="color: #AD0000;">1</span>L) {</span>
<span id="cb12-206">    <span class="cf" style="color: #003B4F;
font-weight: bold;">for</span> (j <span class="cf" style="color: #003B4F;
font-weight: bold;">in</span> <span class="fu" style="color: #4758AB;">seq_len</span>(<span class="fu" style="color: #4758AB;">length</span>(responses) <span class="sc" style="color: #5E5E5E;">-</span> <span class="dv" style="color: #AD0000;">1</span>L)) {</span>
<span id="cb12-207">      redirects[[j]] <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">list</span>(</span>
<span id="cb12-208">        <span class="at" style="color: #657422;">status_code =</span> responses[[j]]<span class="sc" style="color: #5E5E5E;">$</span>status_code,</span>
<span id="cb12-209">        <span class="at" style="color: #657422;">location =</span> <span class="fu" style="color: #4758AB;">unname</span>(responses[[j]]<span class="sc" style="color: #5E5E5E;">$</span>headers[<span class="st" style="color: #20794D;">"location"</span>])</span>
<span id="cb12-210">      )</span>
<span id="cb12-211">    }</span>
<span id="cb12-212">  }</span>
<span id="cb12-213"></span>
<span id="cb12-214">  <span class="fu" style="color: #4758AB;">list</span>(</span>
<span id="cb12-215">    <span class="at" style="color: #657422;">status_code =</span> final_resp<span class="sc" style="color: #5E5E5E;">$</span>status_code,</span>
<span id="cb12-216">    <span class="at" style="color: #657422;">protocol =</span> final_resp<span class="sc" style="color: #5E5E5E;">$</span>protocol,</span>
<span id="cb12-217">    <span class="at" style="color: #657422;">headers =</span> final_resp<span class="sc" style="color: #5E5E5E;">$</span>headers,</span>
<span id="cb12-218">    <span class="at" style="color: #657422;">redirects =</span> redirects,</span>
<span id="cb12-219">    <span class="at" style="color: #657422;">chain =</span> chain</span>
<span id="cb12-220">  )</span>
<span id="cb12-221">}</span>
<span id="cb12-222"></span>
<span id="cb12-223"><span class="co" style="color: #5E5E5E;">#' Check HTTP headers for MIME type misclassifications</span></span>
<span id="cb12-224"><span class="co" style="color: #5E5E5E;">#'</span></span>
<span id="cb12-225"><span class="co" style="color: #5E5E5E;">#' Flags responses where non-HTML assets (.R, .sh, .yml, extensionless scripts)</span></span>
<span id="cb12-226"><span class="co" style="color: #5E5E5E;">#' are served as text/html when compressed or requested with browser headers.</span></span>
<span id="cb12-227"><span class="co" style="color: #5E5E5E;">#'</span></span>
<span id="cb12-228"><span class="co" style="color: #5E5E5E;">#' @param raw_headers Character vector of header lines or string.</span></span>
<span id="cb12-229"><span class="co" style="color: #5E5E5E;">#' @param url_path Optional URL or path to infer expected file type.</span></span>
<span id="cb12-230"><span class="co" style="color: #5E5E5E;">#' @return A list with valid (logical), status_code, content_type, content_encoding, nosniff, and issue.</span></span>
<span id="cb12-231">check_content_type <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">function</span>(raw_headers, <span class="at" style="color: #657422;">url_path =</span> <span class="st" style="color: #20794D;">""</span>) {</span>
<span id="cb12-232">  parsed <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">parse_http_headers</span>(raw_headers)</span>
<span id="cb12-233"></span>
<span id="cb12-234">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">is.na</span>(parsed<span class="sc" style="color: #5E5E5E;">$</span>status_code)) {</span>
<span id="cb12-235">    <span class="fu" style="color: #4758AB;">return</span>(<span class="fu" style="color: #4758AB;">list</span>(</span>
<span id="cb12-236">      <span class="at" style="color: #657422;">valid =</span> <span class="cn" style="color: #8f5902;">FALSE</span>,</span>
<span id="cb12-237">      <span class="at" style="color: #657422;">status_code =</span> <span class="cn" style="color: #8f5902;">NA_integer_</span>,</span>
<span id="cb12-238">      <span class="at" style="color: #657422;">content_type =</span> <span class="cn" style="color: #8f5902;">NA_character_</span>,</span>
<span id="cb12-239">      <span class="at" style="color: #657422;">content_encoding =</span> <span class="cn" style="color: #8f5902;">NA_character_</span>,</span>
<span id="cb12-240">      <span class="at" style="color: #657422;">nosniff =</span> <span class="cn" style="color: #8f5902;">FALSE</span>,</span>
<span id="cb12-241">      <span class="at" style="color: #657422;">issue =</span> <span class="st" style="color: #20794D;">"Could not parse HTTP response headers"</span></span>
<span id="cb12-242">    ))</span>
<span id="cb12-243">  }</span>
<span id="cb12-244"></span>
<span id="cb12-245">  ct <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">unname</span>(parsed<span class="sc" style="color: #5E5E5E;">$</span>headers[<span class="st" style="color: #20794D;">"content-type"</span>])</span>
<span id="cb12-246">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">is.na</span>(ct)) {</span>
<span id="cb12-247">    ct <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="st" style="color: #20794D;">"missing"</span></span>
<span id="cb12-248">  }</span>
<span id="cb12-249"></span>
<span id="cb12-250">  ce <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">unname</span>(parsed<span class="sc" style="color: #5E5E5E;">$</span>headers[<span class="st" style="color: #20794D;">"content-encoding"</span>])</span>
<span id="cb12-251">  nosniff_hdr <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">unname</span>(parsed<span class="sc" style="color: #5E5E5E;">$</span>headers[<span class="st" style="color: #20794D;">"x-content-type-options"</span>])</span>
<span id="cb12-252">  nosniff <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="sc" style="color: #5E5E5E;">!</span><span class="fu" style="color: #4758AB;">is.na</span>(nosniff_hdr) <span class="sc" style="color: #5E5E5E;">&amp;&amp;</span> <span class="fu" style="color: #4758AB;">tolower</span>(nosniff_hdr) <span class="sc" style="color: #5E5E5E;">==</span> <span class="st" style="color: #20794D;">"nosniff"</span></span>
<span id="cb12-253"></span>
<span id="cb12-254">  <span class="co" style="color: #5E5E5E;"># Detect non-HTML target from url_path</span></span>
<span id="cb12-255">  clean_path <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">sub</span>(<span class="st" style="color: #20794D;">"[?#].*$"</span>, <span class="st" style="color: #20794D;">""</span>, url_path)</span>
<span id="cb12-256">  is_non_html <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">grepl</span>(</span>
<span id="cb12-257">    <span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\\</span><span class="st" style="color: #20794D;">.(r|sh|bash|yml|yaml|json|csv|tsv|txt|md|qmd|rmd)$"</span>,</span>
<span id="cb12-258">    clean_path,</span>
<span id="cb12-259">    <span class="at" style="color: #657422;">ignore.case =</span> <span class="cn" style="color: #8f5902;">TRUE</span></span>
<span id="cb12-260">  ) <span class="sc" style="color: #5E5E5E;">||</span></span>
<span id="cb12-261">    <span class="fu" style="color: #4758AB;">grepl</span>(<span class="st" style="color: #20794D;">"/commit-msg$"</span>, clean_path)</span>
<span id="cb12-262"></span>
<span id="cb12-263">  is_served_as_html <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">grepl</span>(<span class="st" style="color: #20794D;">"text/html"</span>, ct, <span class="at" style="color: #657422;">ignore.case =</span> <span class="cn" style="color: #8f5902;">TRUE</span>)</span>
<span id="cb12-264"></span>
<span id="cb12-265">  issue <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="st" style="color: #20794D;">""</span></span>
<span id="cb12-266">  valid <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="cn" style="color: #8f5902;">TRUE</span></span>
<span id="cb12-267"></span>
<span id="cb12-268">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (is_non_html <span class="sc" style="color: #5E5E5E;">&amp;&amp;</span> is_served_as_html) {</span>
<span id="cb12-269">    valid <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="cn" style="color: #8f5902;">FALSE</span></span>
<span id="cb12-270">    issue <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">sprintf</span>(</span>
<span id="cb12-271">      <span class="st" style="color: #20794D;">"Non-HTML asset (%s) was served as '%s'"</span>,</span>
<span id="cb12-272">      <span class="fu" style="color: #4758AB;">basename</span>(clean_path),</span>
<span id="cb12-273">      ct</span>
<span id="cb12-274">    )</span>
<span id="cb12-275">  }</span>
<span id="cb12-276"></span>
<span id="cb12-277">  <span class="fu" style="color: #4758AB;">list</span>(</span>
<span id="cb12-278">    <span class="at" style="color: #657422;">valid =</span> valid,</span>
<span id="cb12-279">    <span class="at" style="color: #657422;">status_code =</span> parsed<span class="sc" style="color: #5E5E5E;">$</span>status_code,</span>
<span id="cb12-280">    <span class="at" style="color: #657422;">content_type =</span> ct,</span>
<span id="cb12-281">    <span class="at" style="color: #657422;">content_encoding =</span> ce,</span>
<span id="cb12-282">    <span class="at" style="color: #657422;">nosniff =</span> nosniff,</span>
<span id="cb12-283">    <span class="at" style="color: #657422;">issue =</span> issue</span>
<span id="cb12-284">  )</span>
<span id="cb12-285">}</span>
<span id="cb12-286"></span>
<span id="cb12-287"><span class="co" style="color: #5E5E5E;"># Standalone execution</span></span>
<span id="cb12-288"><span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">sys.nframe</span>() <span class="sc" style="color: #5E5E5E;">==</span> <span class="dv" style="color: #AD0000;">0</span>L) {</span>
<span id="cb12-289">  args <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">commandArgs</span>(<span class="at" style="color: #657422;">trailingOnly =</span> <span class="cn" style="color: #8f5902;">TRUE</span>)</span>
<span id="cb12-290"></span>
<span id="cb12-291">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="st" style="color: #20794D;">"--help"</span> <span class="sc" style="color: #5E5E5E;">%in%</span> args <span class="sc" style="color: #5E5E5E;">||</span> <span class="st" style="color: #20794D;">"-h"</span> <span class="sc" style="color: #5E5E5E;">%in%</span> args) {</span>
<span id="cb12-292">    <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"Usage:</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-293">    <span class="fu" style="color: #4758AB;">cat</span>(</span>
<span id="cb12-294">      <span class="st" style="color: #20794D;">"  Rscript hosting-check.R                  # Run offline verification demo</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span></span>
<span id="cb12-295">    )</span>
<span id="cb12-296">    <span class="fu" style="color: #4758AB;">cat</span>(</span>
<span id="cb12-297">      <span class="st" style="color: #20794D;">"  Rscript hosting-check.R --site &lt;dir&gt;     # Scan directory index pages for relative links</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span></span>
<span id="cb12-298">    )</span>
<span id="cb12-299">    <span class="fu" style="color: #4758AB;">cat</span>(</span>
<span id="cb12-300">      <span class="st" style="color: #20794D;">"  Rscript hosting-check.R --url &lt;url&gt;      # Inspect HTTP headers for target URL</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span></span>
<span id="cb12-301">    )</span>
<span id="cb12-302">  } <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="st" style="color: #20794D;">"--site"</span> <span class="sc" style="color: #5E5E5E;">%in%</span> args) {</span>
<span id="cb12-303">    site_idx <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">which</span>(args <span class="sc" style="color: #5E5E5E;">==</span> <span class="st" style="color: #20794D;">"--site"</span>) <span class="sc" style="color: #5E5E5E;">+</span> <span class="dv" style="color: #AD0000;">1</span>L</span>
<span id="cb12-304">    site_dir <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (site_idx <span class="sc" style="color: #5E5E5E;">&lt;=</span> <span class="fu" style="color: #4758AB;">length</span>(args)) args[site_idx] <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> <span class="st" style="color: #20794D;">"_site"</span></span>
<span id="cb12-305">    <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"Scanning rendered directory:"</span>, site_dir, <span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-306">    findings <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">find_relative_directory_links</span>(site_dir)</span>
<span id="cb12-307">    <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">nrow</span>(findings) <span class="sc" style="color: #5E5E5E;">==</span> <span class="dv" style="color: #AD0000;">0</span>L) {</span>
<span id="cb12-308">      <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"No relative child links found in directory index pages.</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-309">    } <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> {</span>
<span id="cb12-310">      <span class="fu" style="color: #4758AB;">cat</span>(<span class="fu" style="color: #4758AB;">sprintf</span>(</span>
<span id="cb12-311">        <span class="st" style="color: #20794D;">"Found %d relative link(s) vulnerable to trailing slash removal:</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>,</span>
<span id="cb12-312">        <span class="fu" style="color: #4758AB;">nrow</span>(findings)</span>
<span id="cb12-313">      ))</span>
<span id="cb12-314">      <span class="fu" style="color: #4758AB;">print</span>(findings)</span>
<span id="cb12-315">    }</span>
<span id="cb12-316">  } <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="st" style="color: #20794D;">"--url"</span> <span class="sc" style="color: #5E5E5E;">%in%</span> args) {</span>
<span id="cb12-317">    url_idx <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">which</span>(args <span class="sc" style="color: #5E5E5E;">==</span> <span class="st" style="color: #20794D;">"--url"</span>) <span class="sc" style="color: #5E5E5E;">+</span> <span class="dv" style="color: #AD0000;">1</span>L</span>
<span id="cb12-318">    <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (url_idx <span class="sc" style="color: #5E5E5E;">&lt;=</span> <span class="fu" style="color: #4758AB;">length</span>(args)) {</span>
<span id="cb12-319">      target_url <span class="ot" style="color: #003B4F;">&lt;-</span> args[url_idx]</span>
<span id="cb12-320">      <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"Inspecting headers for:"</span>, target_url, <span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-321">      curl_args <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">c</span>(</span>
<span id="cb12-322">        <span class="st" style="color: #20794D;">"-sI"</span>,</span>
<span id="cb12-323">        <span class="st" style="color: #20794D;">"-H"</span>,</span>
<span id="cb12-324">        <span class="st" style="color: #20794D;">"Accept-Encoding: gzip, br"</span>,</span>
<span id="cb12-325">        <span class="st" style="color: #20794D;">"-H"</span>,</span>
<span id="cb12-326">        <span class="st" style="color: #20794D;">"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"</span>,</span>
<span id="cb12-327">        <span class="st" style="color: #20794D;">"--"</span>,</span>
<span id="cb12-328">        target_url</span>
<span id="cb12-329">      )</span>
<span id="cb12-330">      raw_output <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">tryCatch</span>(</span>
<span id="cb12-331">        <span class="fu" style="color: #4758AB;">system2</span>(<span class="st" style="color: #20794D;">"curl"</span>, curl_args, <span class="at" style="color: #657422;">stdout =</span> <span class="cn" style="color: #8f5902;">TRUE</span>, <span class="at" style="color: #657422;">stderr =</span> <span class="cn" style="color: #8f5902;">FALSE</span>),</span>
<span id="cb12-332">        <span class="at" style="color: #657422;">error =</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">function</span>(e) <span class="fu" style="color: #4758AB;">character</span>()</span>
<span id="cb12-333">      )</span>
<span id="cb12-334">      res <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">check_content_type</span>(raw_output, <span class="at" style="color: #657422;">url_path =</span> target_url)</span>
<span id="cb12-335">      <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"Status Code:     "</span>, res<span class="sc" style="color: #5E5E5E;">$</span>status_code, <span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-336">      <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"Content-Type:    "</span>, res<span class="sc" style="color: #5E5E5E;">$</span>content_type, <span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-337">      <span class="fu" style="color: #4758AB;">cat</span>(</span>
<span id="cb12-338">        <span class="st" style="color: #20794D;">"Content-Encoding:"</span>,</span>
<span id="cb12-339">        <span class="fu" style="color: #4758AB;">ifelse</span>(<span class="fu" style="color: #4758AB;">is.na</span>(res<span class="sc" style="color: #5E5E5E;">$</span>content_encoding), <span class="st" style="color: #20794D;">"none"</span>, res<span class="sc" style="color: #5E5E5E;">$</span>content_encoding),</span>
<span id="cb12-340">        <span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span></span>
<span id="cb12-341">      )</span>
<span id="cb12-342">      <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"Nosniff:         "</span>, <span class="fu" style="color: #4758AB;">ifelse</span>(res<span class="sc" style="color: #5E5E5E;">$</span>nosniff, <span class="st" style="color: #20794D;">"yes"</span>, <span class="st" style="color: #20794D;">"no"</span>), <span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-343">      <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"Valid MIME:      "</span>, <span class="fu" style="color: #4758AB;">ifelse</span>(res<span class="sc" style="color: #5E5E5E;">$</span>valid, <span class="st" style="color: #20794D;">"PASS"</span>, <span class="st" style="color: #20794D;">"FAIL"</span>), <span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-344">      <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">nzchar</span>(res<span class="sc" style="color: #5E5E5E;">$</span>issue)) {</span>
<span id="cb12-345">        <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"Issue:           "</span>, res<span class="sc" style="color: #5E5E5E;">$</span>issue, <span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-346">      }</span>
<span id="cb12-347">    } <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> {</span>
<span id="cb12-348">      <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"Error: --url requires a target URL argument.</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-349">    }</span>
<span id="cb12-350">  } <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> {</span>
<span id="cb12-351">    <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"=======================================================</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-352">    <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"Running offline hosting-check demonstration</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-353">    <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"=======================================================</span><span class="sc" style="color: #5E5E5E;">\n\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-354"></span>
<span id="cb12-355">    <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"Step 1: Header parsing with browser compression headers</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-356">    sample_compressed_bug <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">paste</span>(</span>
<span id="cb12-357">      <span class="st" style="color: #20794D;">"HTTP/2 200"</span>,</span>
<span id="cb12-358">      <span class="st" style="color: #20794D;">"content-type: text/html; charset=UTF-8"</span>,</span>
<span id="cb12-359">      <span class="st" style="color: #20794D;">"content-encoding: gzip"</span>,</span>
<span id="cb12-360">      <span class="at" style="color: #657422;">sep =</span> <span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span></span>
<span id="cb12-361">    )</span>
<span id="cb12-362">    res_bug <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">check_content_type</span>(</span>
<span id="cb12-363">      sample_compressed_bug,</span>
<span id="cb12-364">      <span class="at" style="color: #657422;">url_path =</span> <span class="st" style="color: #20794D;">"scripts/ars-demo.R"</span></span>
<span id="cb12-365">    )</span>
<span id="cb12-366">    <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"Bug reproduction (unconfigured CDN response):</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-367">    <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"  Asset:   scripts/ars-demo.R</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-368">    <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"  Valid:  "</span>, res_bug<span class="sc" style="color: #5E5E5E;">$</span>valid, <span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-369">    <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"  Type:   "</span>, res_bug<span class="sc" style="color: #5E5E5E;">$</span>content_type, <span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-370">    <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"  Issue:  "</span>, res_bug<span class="sc" style="color: #5E5E5E;">$</span>issue, <span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\n\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-371"></span>
<span id="cb12-372">    sample_fixed <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">paste</span>(</span>
<span id="cb12-373">      <span class="st" style="color: #20794D;">"HTTP/2 200"</span>,</span>
<span id="cb12-374">      <span class="st" style="color: #20794D;">"content-type: text/plain; charset=utf-8"</span>,</span>
<span id="cb12-375">      <span class="st" style="color: #20794D;">"content-encoding: gzip"</span>,</span>
<span id="cb12-376">      <span class="st" style="color: #20794D;">"x-content-type-options: nosniff"</span>,</span>
<span id="cb12-377">      <span class="at" style="color: #657422;">sep =</span> <span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span></span>
<span id="cb12-378">    )</span>
<span id="cb12-379">    res_fixed <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">check_content_type</span>(</span>
<span id="cb12-380">      sample_fixed,</span>
<span id="cb12-381">      <span class="at" style="color: #657422;">url_path =</span> <span class="st" style="color: #20794D;">"scripts/ars-demo.R"</span></span>
<span id="cb12-382">    )</span>
<span id="cb12-383">    <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"Fixed configuration (explicit headers):</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-384">    <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"  Asset:   scripts/ars-demo.R</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-385">    <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"  Valid:  "</span>, res_fixed<span class="sc" style="color: #5E5E5E;">$</span>valid, <span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-386">    <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"  Type:   "</span>, res_fixed<span class="sc" style="color: #5E5E5E;">$</span>content_type, <span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-387">    <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"  Nosniff:"</span>, res_fixed<span class="sc" style="color: #5E5E5E;">$</span>nosniff, <span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb12-388">  }</span>
<span id="cb12-389">}</span></code></pre></div></div>
</div>
</div>
</div>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<p><strong>Web standards and specifications</strong></p>
<ul>
<li><strong>RFC 3986 (Uniform Resource Identifier: Generic Syntax):</strong> Section 5.2.3 (“Merge Paths”), T. Berners-Lee, R. Fielding, L. Masinter, January 2005. <a href="https://www.rfc-editor.org/rfc/rfc3986">rfc-editor.org/rfc/rfc3986</a></li>
<li><strong>WHATWG URL Standard:</strong> Section 4.4, URL parsing and relative reference resolution. <a href="https://url.spec.whatwg.org/">url.spec.whatwg.org</a></li>
<li><strong>MDN Web Docs:</strong> <code>X-Content-Type-Options</code>. <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options">developer.mozilla.org</a></li>
</ul>
<p><strong>Hosting documentation</strong></p>
<ul>
<li><strong>Firebase Hosting:</strong> Full configuration guide (<code>cleanUrls</code>, <code>trailingSlash</code>, <code>redirects</code>, and <code>headers</code>). <a href="https://firebase.google.com/docs/hosting/full-config">firebase.google.com/docs/hosting/full-config</a></li>
<li><strong>Netlify:</strong> <a href="https://docs.netlify.com/manage/routing/redirects/redirect-options/#trailing-slash">Pretty URLs and trailing slash behavior</a> and <a href="https://docs.netlify.com/manage/routing/headers/">custom headers</a>.</li>
<li><strong>Cloudflare Pages:</strong> <a href="https://developers.cloudflare.com/pages/configuration/serving-pages/">Serving Pages</a> and <a href="https://developers.cloudflare.com/pages/configuration/headers/">custom headers</a>.</li>
</ul>
<p><strong>R package documentation</strong></p>
<ul>
<li><strong>testthat</strong>: <a href="https://testthat.r-lib.org/">testthat.r-lib.org</a></li>
<li><strong>withr</strong>: <a href="https://withr.r-lib.org/">withr.r-lib.org</a></li>
</ul>



<div class="site-related">
<div class="site-series-nav">
<p><a href="https://insightsurge-dev.web.app/series/foundations.html" class="site-series-nav__series">Foundations series · part 16 of 16</a></p>
<div class="site-card-grid site-series-nav__links">
<div class="site-card-cell">
<a href="https://insightsurge-dev.web.app/posts/companion-code/index.html" class="is-card site-related-card site-series-nav__prev"><span class="is-card__eyebrow">Previous · part 15</span><span class="site-related-card__title">Companion code: show it, link it, test it</span></a>
</div>
</div>
</div>
<section id="keep-reading" class="level2 unnumbered unlisted no-anchor">
<h2 class="unnumbered unlisted no-anchor" data-anchor-id="keep-reading">Keep reading</h2>
<div class="site-link-list">
<ul>
<li><a href="https://insightsurge-dev.web.app/posts/quarto-firebase-previews/index.html" class="site-link-row" title="Deploy temporary Firebase Hosting preview channels on every pull request to review rendered Quarto sites before merging."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Deploy a Quarto site with a preview for every pull request</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/link-checking-rendered-sites/index.html" class="site-link-row" title="Validate internal links across rendered documentation in CI using offline link scanners to block broken references before release."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Catch broken links before your readers do</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/series-registry-quarto/index.html" class="site-link-row" title="Model series and related posts as structured data with a YAML registry and a Pandoc Lua filter, guarded by testthat so missing references fail in CI."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Content as data: a series registry for a Quarto blog</span></a></li>
</ul>
</div>
</section>
</div>

</section>

 ]]></description>
  <category>Quarto</category>
  <category>CI/CD</category>
  <category>Best practices</category>
  <guid>https://insightsurge-dev.web.app/posts/hosted-site-pitfalls/</guid>
  <pubDate>Sat, 26 Sep 2026 18:30:00 GMT</pubDate>
</item>
<item>
  <title>ADRs &amp; evidence: record decisions, verify docs</title>
  <link>https://insightsurge-dev.web.app/posts/adrs-and-evidence/</link>
  <description><![CDATA[ 





<!--
  Quarto 1.8.27's title-block.html with three changes: category badges and a
  series link ("Testing series · part 2") sit above the title, as in the brand's
  blog kit; and a post or series page with `trailer: true` shows its trailer beside the title
  (_filters/trailer.lua sets trailer-path; _includes/trailers.html plays it). On a Quarto upgrade, diff this against
  share/formats/html/templates/title-block.html and carry over any changes.
-->



<section id="architecture-decision-records" class="level2">
<h2 class="anchored" data-anchor-id="architecture-decision-records">Architecture Decision Records</h2>
<p>Six months from now someone will ask <em>“why didn’t we use Astro?”</em> or <em>“why is there no JSON key for deploys?”</em>. An <strong>ADR</strong> is a short file that answers that question permanently.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode markdown code-with-copy"><code class="sourceCode markdown"><span id="cb1-1"><span class="fu" style="color: #4758AB;"># ADR-0003: Secrets management</span></span>
<span id="cb1-2"><span class="ss" style="color: #20794D;">- </span>**Status:** Accepted</span>
<span id="cb1-3"><span class="ss" style="color: #20794D;">- </span>**Date:** 2026-09-26</span>
<span id="cb1-4"></span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;">## Context      (what forced a decision; constraints)</span></span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;">## Decision     (what we chose, specifically)</span></span>
<span id="cb1-7"><span class="fu" style="color: #4758AB;">## Alternatives (what we rejected, and why)</span></span>
<span id="cb1-8"><span class="fu" style="color: #4758AB;">## Consequences (what gets easier or harder, and what to watch)</span></span></code></pre></div></div>
<p>Rules that keep ADRs useful:</p>
<ul>
<li><strong>One decision per file</strong>, numbered: <code>docs/adr/0001-stack-and-hosting.md</code>.</li>
<li><strong>Immutable once accepted.</strong> To change your mind, write a new ADR that <em>supersedes</em> the old one, and mark the old one <em>Superseded by ADR-00NN</em>. The history of your thinking is the point.</li>
<li><strong>Short.</strong> One page. Link out for detail.</li>
<li><strong>Reviewed in a PR</strong> like code, so the decision has an approver and a date.</li>
</ul>
<p>Our website started with five: stack and hosting, visual direction (pending), secrets, handoffs, and identity isolation.</p>
</section>
<section id="the-r-gxp-angle" class="level2">
<h2 class="anchored" data-anchor-id="the-r-gxp-angle">The R / GxP angle</h2>
<p>Validation packages already contain design rationale, but it’s usually written once, at the end. ADRs capture it <strong>when the decision is made</strong>, next to the code, with the review trail. They map to:</p>
<div class="table-responsive">
<table class="caption-top table">
<thead>
<tr class="header">
<th>Validation artefact</th>
<th>ADR equivalent</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Design specification rationale</td>
<td>Decision + Alternatives</td>
</tr>
<tr class="even">
<td>Risk assessment inputs</td>
<td>Context + Consequences</td>
</tr>
<tr class="odd">
<td>Change control record</td>
<td>The PR that added or superseded the ADR</td>
</tr>
</tbody>
</table>
</div>
<p><strong>Where to put them in an R package:</strong> not in <code>docs/</code>. That’s where <strong>pkgdown</strong> writes the site by default, so the two collide. Use <code>adr/</code> (or <code>design/adr/</code>) at the root with a README index, and <code>usethis::use_build_ignore("adr")</code> so they stay out of the tarball.</p>
</section>
<section id="evidence-verify-documentation-before-you-trust-it" class="level2">
<h2 class="anchored" data-anchor-id="evidence-verify-documentation-before-you-trust-it">Evidence: verify documentation before you trust it</h2>
<p>Decisions are only as good as the facts under them. Setting up this project, we hit several cases where the obvious source was wrong or incomplete:</p>
<div class="table-responsive">
<table class="caption-top table">
<colgroup>
<col style="width: 50%">
<col style="width: 50%">
</colgroup>
<thead>
<tr class="header">
<th>Claim</th>
<th>What we found</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>“Firebase App Hosting supports Next.js up to 15.2” (support table)</td>
<td>The table was stale. Firebase’s blog and the Next.js docs showed 16.2+ supported via the adapter API</td>
</tr>
<tr class="even">
<td>“Blank issues disabled means nobody can open one”</td>
<td>GitHub’s own page says both things; the detailed note says maintainers still see a blank option</td>
</tr>
<tr class="odd">
<td>“<code>~/.Renviron</code> and a project <code>.Renviron</code> combine”</td>
<td>Tested with two files: the project one <strong>replaces</strong> the home one</td>
</tr>
<tr class="even">
<td>“<code>gh</code> uses <code>GITHUB_PAT</code>”</td>
<td>Tested: <code>GITHUB_PAT_GITHUB_COM</code> wins over <code>GITHUB_PAT</code>, which wins over the credential helper</td>
</tr>
<tr class="odd">
<td>“<code>usethis::git_vaccinate()</code> protects <code>.Renviron</code>”</td>
<td>Read the list it writes: it doesn’t</td>
</tr>
<tr class="even">
<td>“Setting <code>.Last &lt;- function() NULL</code> stops history saving”</td>
<td>A draft claim that was wrong. Caught in review and removed</td>
</tr>
</tbody>
</table>
</div>
<p>Habits:</p>
<ol type="1">
<li><strong>Prefer running it to reading about it.</strong> Ten seconds with <code>Rscript -e</code> beats any blog post.</li>
<li><strong>Primary sources over summaries.</strong> Official docs, source code, <code>NEWS.md</code>, and the package’s own help.</li>
<li><strong>When sources disagree, record both</strong> and what you did about it, in the ADR’s Context.</li>
<li><strong>Date your evidence.</strong> “Checked 2026-09-26” tells a future reader when to re-check.</li>
<li><strong>Treat AI-written claims like any other secondary source</strong>, including your own assistant’s. Verify, or mark them <em>unverified</em>.</li>
</ol>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<ul>
<li><strong>Architecture Decision Records</strong>: <a href="https://adr.github.io/">adr.github.io</a></li>
<li><strong>pkgdown</strong> (the reason ADRs shouldn’t live in <code>docs/</code> in an R package): <a href="https://pkgdown.r-lib.org/">pkgdown.r-lib.org</a></li>
<li><strong>usethis</strong> (<code>use_build_ignore()</code>): <a href="https://usethis.r-lib.org/">usethis.r-lib.org</a></li>
<li><strong>“Blank issues disabled” still lets write-access users open a blank issue</strong>: <a href="https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/configuring-issue-templates-for-your-repository">GitHub Docs: Configuring issue templates for your repository</a></li>
<li><strong><code>gh</code>/<code>usethis</code> GitHub token lookup order (<code>GITHUB_PAT_GITHUB_COM</code> before <code>GITHUB_PAT</code> before the credential helper)</strong>: <a href="https://gh.r-lib.org/">gh.r-lib.org</a></li>
</ul>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Updates
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<ul>
<li><strong>2026-09-26:</strong> Removed the end-of-post checklist.</li>
<li><strong>2026-09-27:</strong> Added a Sources section.</li>
</ul>
</div>
</div>
</div>



<div class="site-related">
<div class="site-series-nav">
<p><a href="https://insightsurge-dev.web.app/series/foundations.html" class="site-series-nav__series">Foundations series · part 12 of 16</a></p>
<div class="site-card-grid site-series-nav__links">
<div class="site-card-cell">
<a href="https://insightsurge-dev.web.app/posts/test-your-guardrails/index.html" class="is-card site-related-card site-series-nav__prev"><span class="is-card__eyebrow">Previous · part 11</span><span class="site-related-card__title">Test your guardrails: probe PRs</span></a>
</div>
<div class="site-card-cell">
<a href="https://insightsurge-dev.web.app/posts/repo-hygiene-files/index.html" class="is-card site-related-card site-series-nav__next"><span class="is-card__eyebrow">Next · part 13</span><span class="site-related-card__title">Repo hygiene files</span></a>
</div>
</div>
</div>
<section id="keep-reading" class="level2 unnumbered unlisted no-anchor">
<h2 class="unnumbered unlisted no-anchor" data-anchor-id="keep-reading">Keep reading</h2>
<div class="site-link-list">
<ul>
<li><a href="https://insightsurge-dev.web.app/posts/coverage-and-test-evidence/index.html" class="site-link-row" title="Use covr to spot untested paths, export Cobertura and JUnit XML in CI, and build automated requirement traceability matrices."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Coverage and tests as evidence</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/two-model-workflow/index.html" class="site-link-row" title="Structure dual-model AI workflows with clear task ownership, written briefs, and human verification to maintain engineering rigor."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">One owner, two models: delegating to a second AI and verifying it</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/introducing-mascot/index.html" class="site-link-row" title="The mascot package is now on CRAN: add mood-driven characters to Shiny apps and Quarto pages, with visible status text, speech bubbles, click menus and reduced-motion support."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">mascot is on CRAN: live, mood-driven mascots for Shiny and Quarto</span></a></li>
</ul>
</div>
</section>
</div>

</section>

 ]]></description>
  <category>GxP</category>
  <category>Best practices</category>
  <category>R packages</category>
  <guid>https://insightsurge-dev.web.app/posts/adrs-and-evidence/</guid>
  <pubDate>Fri, 25 Sep 2026 18:30:00 GMT</pubDate>
</item>
<item>
  <title>CI with GitHub Actions</title>
  <link>https://insightsurge-dev.web.app/posts/ci-github-actions/</link>
  <description><![CDATA[ 





<!--
  Quarto 1.8.27's title-block.html with three changes: category badges and a
  series link ("Testing series · part 2") sit above the title, as in the brand's
  blog kit; and a post or series page with `trailer: true` shows its trailer beside the title
  (_filters/trailer.lua sets trailer-path; _includes/trailers.html plays it). On a Quarto upgrade, diff this against
  share/formats/html/templates/title-block.html and carry over any changes.
-->



<section id="the-idea" class="level2">
<h2 class="anchored" data-anchor-id="the-idea">The idea</h2>
<p>Continuous integration means every PR is built and checked <strong>on a clean machine</strong>, the same way every time, before it can merge. For an R package that’s <code>R CMD check</code>. For a Shiny app it’s tests plus a deploy check. For a Quarto site it’s a render plus a link check. “Works on my machine” stops being an argument.</p>
</section>
<section id="anatomy-of-a-workflow" class="level2">
<h2 class="anchored" data-anchor-id="anatomy-of-a-workflow">Anatomy of a workflow</h2>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb1-1"><span class="fu" style="color: #4758AB;">name</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> ci</span></span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;">on</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-3"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">pull_request</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-4"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">push</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-5"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">branches</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="kw" style="color: #003B4F;
font-weight: bold;">[</span><span class="at" style="color: #657422;">main</span><span class="kw" style="color: #003B4F;
font-weight: bold;">]</span></span>
<span id="cb1-6"></span>
<span id="cb1-7"><span class="fu" style="color: #4758AB;">permissions</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-8"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">contents</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> read</span><span class="co" style="color: #5E5E5E;">              # least privilege: read the code, nothing else</span></span>
<span id="cb1-9"></span>
<span id="cb1-10"><span class="fu" style="color: #4758AB;">concurrency</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-11"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">group</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> ci-${{ github.ref }}</span><span class="co" style="color: #5E5E5E;"> # a new push to the same PR cancels the old run</span></span>
<span id="cb1-12"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">cancel-in-progress</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="ch" style="color: #20794D;">true</span></span>
<span id="cb1-13"></span>
<span id="cb1-14"><span class="fu" style="color: #4758AB;">jobs</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-15"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">check</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-16"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">runs-on</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> ubuntu-26.04</span><span class="co" style="color: #5E5E5E;">     # pinned runner: avoids surprise moves when ubuntu-latest rolls</span></span>
<span id="cb1-17"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">steps</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-18"><span class="at" style="color: #657422;">      </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">uses</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> actions/checkout@v7</span></span>
<span id="cb1-19"><span class="at" style="color: #657422;">      </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">uses</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> actions/setup-node@v7</span></span>
<span id="cb1-20"><span class="at" style="color: #657422;">        </span><span class="fu" style="color: #4758AB;">with</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-21"><span class="at" style="color: #657422;">          </span><span class="fu" style="color: #4758AB;">node-version-file</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> .nvmrc</span><span class="co" style="color: #5E5E5E;">   # runtime version comes from the repo</span></span>
<span id="cb1-22"><span class="at" style="color: #657422;">          </span><span class="fu" style="color: #4758AB;">cache</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> npm</span></span>
<span id="cb1-23"><span class="at" style="color: #657422;">      </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">run</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> npm ci</span><span class="co" style="color: #5E5E5E;">                   # exact versions from the lockfile</span></span>
<span id="cb1-24"><span class="at" style="color: #657422;">      </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">run</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> npx biome ci</span><span class="co" style="color: #5E5E5E;">             # lint + format</span></span>
<span id="cb1-25"><span class="at" style="color: #657422;">      </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">run</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> npm run typecheck</span></span>
<span id="cb1-26"><span class="at" style="color: #657422;">      </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">run</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> npm test</span></span>
<span id="cb1-27"><span class="at" style="color: #657422;">      </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">run</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> npm run build</span></span></code></pre></div></div>
<p>Five habits that carry over to any language:</p>
<div class="table-responsive">
<table class="caption-top table">
<colgroup>
<col style="width: 33%">
<col style="width: 33%">
<col style="width: 33%">
</colgroup>
<thead>
<tr class="header">
<th>Habit</th>
<th>Why</th>
<th>R equivalent</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><code>permissions: contents: read</code></td>
<td>A compromised step can’t push or open releases</td>
<td>Same YAML</td>
</tr>
<tr class="even">
<td><code>concurrency</code> + <code>cancel-in-progress</code></td>
<td>No wasted minutes on stale pushes</td>
<td>Same YAML</td>
</tr>
<tr class="odd">
<td>Runtime version read from the repo</td>
<td>CI and laptops agree</td>
<td><code>setup-r</code> with <code>r-version: renv</code> reads <code>renv.lock</code></td>
</tr>
<tr class="even">
<td>Install from the lockfile</td>
<td>Reproducible dependencies</td>
<td><code>setup-renv</code>, or <code>setup-r-dependencies</code></td>
</tr>
<tr class="odd">
<td>Fail fast, cheapest check first</td>
<td>Quick feedback</td>
<td>lint → test → check</td>
</tr>
</tbody>
</table>
</div>
<p>When one step fails, the later steps are skipped. We saw this with a deliberate type error: <em>Typecheck: failure</em>, then <em>Unit tests: skipped</em>, <em>Build: skipped</em>.</p>
</section>
<section id="the-r-way-r-libactions" class="level2">
<h2 class="anchored" data-anchor-id="the-r-way-r-libactions">The R way: <code>r-lib/actions</code></h2>
<p><code>usethis</code> copies the maintained examples from <a href="https://github.com/r-lib/actions/tree/v2/examples"><code>r-lib/actions</code></a>:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r norun code-with-copy"><code class="sourceCode r"><span id="cb2-1">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">use_github_action</span>(<span class="st" style="color: #20794D;">"check-standard"</span>)  <span class="co" style="color: #5E5E5E;"># R CMD check: macOS, Windows, Ubuntu (devel/release/oldrel-1)</span></span>
<span id="cb2-2">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">use_github_action</span>(<span class="st" style="color: #20794D;">"test-coverage"</span>)   <span class="co" style="color: #5E5E5E;"># covr</span></span>
<span id="cb2-3">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">use_github_action</span>(<span class="st" style="color: #20794D;">"pkgdown"</span>)         <span class="co" style="color: #5E5E5E;"># build and deploy the package site</span></span>
<span id="cb2-4">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">use_github_action</span>(<span class="st" style="color: #20794D;">"lint"</span>)            <span class="co" style="color: #5E5E5E;"># lintr (see hooks, formatting &amp; linting)</span></span>
<span id="cb2-5">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">use_github_action</span>(<span class="st" style="color: #20794D;">"shiny-deploy"</span>)    <span class="co" style="color: #5E5E5E;"># deploy a Shiny app with rsconnect</span></span></code></pre></div></div>
<p>The core of <code>check-standard</code>:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb3-1"><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">uses</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> r-lib/actions/setup-pandoc@v2</span></span>
<span id="cb3-2"><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">uses</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> r-lib/actions/setup-r@v2</span></span>
<span id="cb3-3"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">with</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb3-4"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">r-version</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> ${{ matrix.config.r }}</span><span class="co" style="color: #5E5E5E;">     # or 'renv' to use the lockfile's version</span></span>
<span id="cb3-5"><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">uses</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> r-lib/actions/setup-r-dependencies@v2</span></span>
<span id="cb3-6"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">with</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb3-7"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">extra-packages</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> any::rcmdcheck</span></span>
<span id="cb3-8"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">needs</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> check</span></span>
<span id="cb3-9"><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">uses</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> r-lib/actions/check-r-package@v2</span></span>
<span id="cb3-10"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">with</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb3-11"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">upload-snapshots</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="ch" style="color: #20794D;">true</span><span class="co" style="color: #5E5E5E;">                # testthat/shinytest2 snapshots on failure</span></span></code></pre></div></div>
<p><strong>Two cheap hardening edits</strong> to the stock example: it ships with <code>permissions: read-all</code>, which you can narrow to <code>permissions: contents: read</code>, and it has no <code>concurrency</code> block, so add one.</p>
<p><strong>Shiny apps:</strong> <code>shinytest2</code> tests live in <code>tests/testthat/</code>, so they run inside <code>R CMD check</code> (for app-in-a-package) or with <code>testthat::test_dir()</code>. Failed snapshots are uploaded as artifacts.</p>
<p><strong>Quarto sites:</strong> use <code>quarto-dev/quarto-actions/setup</code> and <code>.../render</code>, pin the Quarto version, and add a link checker. This playbook’s own <code>.github/workflows/quarto.yml</code> is a worked example. It renders, checks internal links with <code>lychee</code>, and deploys a preview per PR.</p>
</section>
<section id="pinning-how-tightly" class="level2">
<h2 class="anchored" data-anchor-id="pinning-how-tightly">Pinning: how tightly?</h2>
<div class="table-responsive">
<table class="caption-top table">
<colgroup>
<col style="width: 33%">
<col style="width: 33%">
<col style="width: 33%">
</colgroup>
<thead>
<tr class="header">
<th>Style</th>
<th>Example</th>
<th>Trade-off</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Major tag</td>
<td><code>r-lib/actions/setup-r@v2</code></td>
<td>Gets fixes automatically; trusts the maintainer</td>
</tr>
<tr class="even">
<td>Exact tag</td>
<td><code>@v2.14.0</code></td>
<td>Reproducible; you must bump it</td>
</tr>
<tr class="odd">
<td>Commit SHA</td>
<td><code>@&lt;40-char sha&gt;</code></td>
<td>Immutable, best supply-chain safety; unreadable without comments</td>
</tr>
</tbody>
</table>
</div>
<p>Major tags plus <strong>Dependabot for <code>github-actions</code></strong> (<a href="https://insightsurge-dev.web.app/posts/dependencies-runtime-vetting/index.html">dependency updates &amp; vetting</a>) is a sensible default. Regulated production pipelines may justify SHA pinning.</p>
<p>Also pin the <strong>runner image</strong> if stability matters. <code>ubuntu-latest</code> moves over time: GitHub moves <code>ubuntu-latest</code> to Ubuntu 26.04 in a rollout that starts on 19 October 2026. On 2026-09-27, we moved the pinned runners in this repository to <code>runs-on: ubuntu-26.04</code> deliberately ahead of the rollout, rather than waiting for <code>ubuntu-latest</code> to transition underneath us.</p>
</section>
<section id="pitfalls" class="level2">
<h2 class="anchored" data-anchor-id="pitfalls">Pitfalls</h2>
<ul>
<li><strong>Generated files must be generated in CI.</strong> Our Next.js typecheck failed on a fresh checkout until CI ran <code>next typegen</code> first. The R version of this is an out-of-date <code>NAMESPACE</code>: run <code>devtools::document()</code> and commit the result, or check it in CI.</li>
<li><strong>Secrets in PRs from forks</strong> aren’t available (by design). Design deploy steps to skip cleanly.</li>
<li><strong>Don’t <code>continue-on-error</code> your way to green.</strong> A check that can’t fail isn’t a check.</li>
<li><strong>Watch the matrix size.</strong> Five OS/R combinations per push adds up on private repos, where Actions minutes are billed against your plan’s quota.</li>
</ul>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<p><strong>GitHub Actions</strong></p>
<ul>
<li><strong><code>permissions:</code> and <code>GITHUB_TOKEN</code></strong>: <a href="https://docs.github.com/en/actions/tutorials/authenticate-with-github_token">GitHub Docs: Use <code>GITHUB_TOKEN</code> for authentication in workflows</a></li>
<li><strong><code>concurrency:</code></strong>: <a href="https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/control-workflow-concurrency">GitHub Docs: Control the concurrency of workflows and jobs</a></li>
<li><strong>Secrets not available to workflows from forked-repo PRs</strong>: <a href="https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/use-secrets">GitHub Docs: Use secrets in GitHub Actions</a></li>
<li><strong><code>ubuntu-latest</code> moving to Ubuntu 26 (19 Oct–19 Nov 2026 rollout)</strong>: <a href="https://github.blog/changelog/2026-09-17-ubuntu-26-generally-available-and-latest-migration/">GitHub Changelog: Ubuntu 26 generally available and latest migration</a></li>
<li><strong>GitHub Actions runner images</strong> (<code>ubuntu-26.04</code> image definition): <a href="https://github.com/actions/runner-images">actions/runner-images</a></li>
<li><strong>r-lib/actions</strong> (<code>check-standard</code>, <code>setup-r</code>, <code>setup-r-dependencies</code>, <code>check-r-package</code>): <a href="https://github.com/r-lib/actions/tree/v2/examples">github.com/r-lib/actions</a></li>
<li><strong>quarto-dev/quarto-actions</strong>: <a href="https://github.com/quarto-dev/quarto-actions">github.com/quarto-dev/quarto-actions</a></li>
<li><strong>lychee</strong> (link checker): <a href="https://github.com/lycheeverse/lychee">github.com/lycheeverse/lychee</a></li>
</ul>
<p><strong>R package documentation</strong></p>
<ul>
<li><strong>usethis</strong> (<code>use_github_action()</code>): <a href="https://usethis.r-lib.org/">usethis.r-lib.org</a></li>
</ul>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Updates
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<ul>
<li><strong>2026-09-26:</strong> Removed the end-of-post checklist.</li>
<li><strong>2026-09-26:</strong> Pinned <code>runs-on: ubuntu-24.04</code> across all GitHub Actions workflows in both repositories ahead of GitHub’s scheduled <code>ubuntu-latest</code> transition to Ubuntu 26 (19 October 2026), deferring the runner upgrade until we validate it deliberately.</li>
<li><strong>2026-09-27:</strong> Added a Sources section.</li>
<li><strong>2026-09-27:</strong> Moved the pinned runners from ubuntu-24.04 to ubuntu-26.04, ahead of the ubuntu-latest rollout.</li>
</ul>
</div>
</div>
</div>



<div class="site-related">
<div class="site-series-nav">
<p><a href="https://insightsurge-dev.web.app/series/foundations.html" class="site-series-nav__series">Foundations series · part 5 of 16</a></p>
<div class="site-card-grid site-series-nav__links">
<div class="site-card-cell">
<a href="https://insightsurge-dev.web.app/posts/hooks-formatting-linting/index.html" class="is-card site-related-card site-series-nav__prev"><span class="is-card__eyebrow">Previous · part 4</span><span class="site-related-card__title">Pre-commit hooks, formatting &amp; linting</span></a>
</div>
<div class="site-card-cell">
<a href="https://insightsurge-dev.web.app/posts/secret-scanning/index.html" class="is-card site-related-card site-series-nav__next"><span class="is-card__eyebrow">Next · part 6</span><span class="site-related-card__title">Secret scanning with gitleaks</span></a>
</div>
</div>
</div>
<section id="keep-reading" class="level2 unnumbered unlisted no-anchor">
<h2 class="unnumbered unlisted no-anchor" data-anchor-id="keep-reading">Keep reading</h2>
<div class="site-link-list">
<ul>
<li><a href="https://insightsurge-dev.web.app/posts/coverage-and-test-evidence/index.html" class="site-link-row" title="Use covr to spot untested paths, export Cobertura and JUnit XML in CI, and build automated requirement traceability matrices."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Coverage and tests as evidence</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/shinytest2-end-to-end/index.html" class="site-link-row" title="Drive Shiny applications end to end with shinytest2 and headless Chrome, testing real browser rendering, user input sequences, and reactive outputs."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">End-to-end Shiny tests with shinytest2</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/quarto-firebase-previews/index.html" class="site-link-row" title="Deploy temporary Firebase Hosting preview channels on every pull request to review rendered Quarto sites before merging."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Deploy a Quarto site with a preview for every pull request</span></a></li>
</ul>
</div>
</section>
</div>

</section>

 ]]></description>
  <category>CI/CD</category>
  <category>R packages</category>
  <category>Shiny</category>
  <guid>https://insightsurge-dev.web.app/posts/ci-github-actions/</guid>
  <pubDate>Fri, 25 Sep 2026 18:30:00 GMT</pubDate>
</item>
<item>
  <title>Conventional commits &amp; PR title checks</title>
  <link>https://insightsurge-dev.web.app/posts/conventional-commits-pr-titles/</link>
  <description><![CDATA[ 





<!--
  Quarto 1.8.27's title-block.html with three changes: category badges and a
  series link ("Testing series · part 2") sit above the title, as in the brand's
  blog kit; and a post or series page with `trailer: true` shows its trailer beside the title
  (_filters/trailer.lua sets trailer-path; _includes/trailers.html plays it). On a Quarto upgrade, diff this against
  share/formats/html/templates/title-block.html and carry over any changes.
-->



<section id="the-problem" class="level2">
<h2 class="anchored" data-anchor-id="the-problem">The problem</h2>
<p>Look at the history of most R repos and you’ll see <code>update</code>, <code>fix</code>, <code>wip</code>, <code>final version</code>, <code>final version 2</code>. The code may be excellent, but the history can’t answer basic questions:</p>
<ul>
<li>What changed for <strong>users</strong> since the last release?</li>
<li>Which change <strong>broke</strong> something?</li>
<li>Does this release need a <strong>major</strong>, minor or patch version bump?</li>
</ul>
<p>In a GxP setting the same history is also part of your change-control evidence. “fix” is not an adequate change description.</p>
</section>
<section id="the-standard-conventional-commits" class="level2">
<h2 class="anchored" data-anchor-id="the-standard-conventional-commits">The standard: Conventional Commits</h2>
<p><a href="https://www.conventionalcommits.org">Conventional Commits</a> is a tiny grammar for the first line of a commit message:</p>
<pre><code>&lt;type&gt;(&lt;optional scope&gt;)&lt;optional !&gt;: &lt;description&gt;</code></pre>
<div class="table-responsive">
<table class="caption-top table">
<colgroup>
<col style="width: 33%">
<col style="width: 33%">
<col style="width: 33%">
</colgroup>
<thead>
<tr class="header">
<th>Type</th>
<th>Use it for</th>
<th>Version effect</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><code>feat</code></td>
<td>A new user-facing capability</td>
<td>minor</td>
</tr>
<tr class="even">
<td><code>fix</code></td>
<td>A bug fix</td>
<td>patch</td>
</tr>
<tr class="odd">
<td><code>docs</code></td>
<td>Documentation only</td>
<td>none</td>
</tr>
<tr class="even">
<td><code>test</code></td>
<td>Tests only</td>
<td>none</td>
</tr>
<tr class="odd">
<td><code>refactor</code></td>
<td>Code change with no behaviour change</td>
<td>none</td>
</tr>
<tr class="even">
<td><code>perf</code></td>
<td>Faster, same behaviour</td>
<td>patch</td>
</tr>
<tr class="odd">
<td><code>build</code>, <code>ci</code>, <code>chore</code>, <code>style</code>, <code>revert</code></td>
<td>Tooling, CI, housekeeping</td>
<td>none</td>
</tr>
<tr class="even">
<td><code>!</code> after the type, or a <code>BREAKING CHANGE:</code> footer</td>
<td>Breaks existing code</td>
<td><strong>major</strong></td>
</tr>
</tbody>
</table>
</div>
<p>R examples:</p>
<pre><code>feat(km_plot): add risk table below the curve
fix(read_adsl): keep labels when reading xpt files
docs: add vignette on ARD-based tables
feat!: require R &gt;= 4.3</code></pre>
<p>Scopes are free text. In an R package, use the <strong>function or module name</strong>, so that <code>git log --grep "(km_plot)"</code> finds every change to that function.</p>
</section>
<section id="the-key-idea-with-squash-merge-the-pr-title-is-the-commit" class="level2">
<h2 class="anchored" data-anchor-id="the-key-idea-with-squash-merge-the-pr-title-is-the-commit">The key idea: with squash-merge, the PR title <em>is</em> the commit</h2>
<p>If a repo allows only <strong>squash merges</strong> (<a href="https://insightsurge-dev.web.app/posts/git-workflow/index.html">git workflow</a>), each PR lands on <code>main</code> as <strong>one</strong> commit, and GitHub uses the <strong>PR title</strong> as that commit’s message:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb3-1"><span class="co" style="color: #5E5E5E;"># Repo setting, once (needs admin rights on the repo)</span></span>
<span id="cb3-2"><span class="ex" style="color: null;">gh</span> api <span class="at" style="color: #657422;">-X</span> PATCH repos/OWNER/REPO <span class="dt" style="color: #AD0000;">\</span></span>
<span id="cb3-3">  <span class="at" style="color: #657422;">-F</span> allow_squash_merge=true <span class="at" style="color: #657422;">-F</span> allow_merge_commit=false <span class="at" style="color: #657422;">-F</span> allow_rebase_merge=false <span class="dt" style="color: #AD0000;">\</span></span>
<span id="cb3-4">  <span class="at" style="color: #657422;">-f</span> squash_merge_commit_title=PR_TITLE <span class="at" style="color: #657422;">-f</span> squash_merge_commit_message=PR_BODY</span></code></pre></div></div>
<p>So the commits <em>on your branch</em> can stay informal (“try another approach”). What matters is the <strong>PR title</strong>, and that’s what you should check automatically.</p>
</section>
<section id="the-web-repo-way" class="level2">
<h2 class="anchored" data-anchor-id="the-web-repo-way">The web-repo way</h2>
<p>Two layers:</p>
<ol type="1">
<li><strong>Locally</strong>, <code>commitlint</code> runs in a <code>commit-msg</code> git hook (via <code>husky</code>) and rejects a bad message before the commit exists.</li>
<li><strong>In CI</strong>, a workflow checks the PR title on every edit:</li>
</ol>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb4-1"><span class="co" style="color: #5E5E5E;"># .github/workflows/pr-title.yml</span></span>
<span id="cb4-2"><span class="fu" style="color: #4758AB;">on</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-3"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">pull_request</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-4"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">types</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="kw" style="color: #003B4F;
font-weight: bold;">[</span><span class="at" style="color: #657422;">opened</span><span class="kw" style="color: #003B4F;
font-weight: bold;">,</span><span class="at" style="color: #657422;"> edited</span><span class="kw" style="color: #003B4F;
font-weight: bold;">,</span><span class="at" style="color: #657422;"> reopened</span><span class="kw" style="color: #003B4F;
font-weight: bold;">,</span><span class="at" style="color: #657422;"> synchronize</span><span class="kw" style="color: #003B4F;
font-weight: bold;">]</span></span>
<span id="cb4-5"><span class="fu" style="color: #4758AB;">permissions</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-6"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">pull-requests</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> read</span></span>
<span id="cb4-7"><span class="fu" style="color: #4758AB;">jobs</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-8"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">conventional-title</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-9"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">runs-on</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> ubuntu-latest</span></span>
<span id="cb4-10"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">steps</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-11"><span class="at" style="color: #657422;">      </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">uses</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> amannn/action-semantic-pull-request@v6</span></span>
<span id="cb4-12"><span class="at" style="color: #657422;">        </span><span class="fu" style="color: #4758AB;">env</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-13"><span class="at" style="color: #657422;">          </span><span class="fu" style="color: #4758AB;">GITHUB_TOKEN</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> ${{ secrets.GITHUB_TOKEN }}</span></span></code></pre></div></div>
<p>We tested this with a throwaway PR titled <code>updated the readme</code>. The check failed with <em>“No release type found in pull request title”</em>, while a PR titled <code>docs: clean PR probe</code> passed. Because the workflow also runs on <code>edited</code>, renaming a PR re-runs the check without a new commit.</p>
</section>
<section id="the-r-way" class="level2">
<h2 class="anchored" data-anchor-id="the-r-way">The R way</h2>
<p><strong>The CI layer needs no Node at all.</strong> <code>pr-title.yml</code> is a hosted action, so you can drop the same file into any R package or Shiny repo: <a href="https://insightsurge-dev.web.app/templates/github/workflows/pr-title.yml"><code>templates/github/workflows/pr-title.yml</code></a>.</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Full template: <code>pr-title.yml</code>
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb5-1"><span class="co" style="color: #5E5E5E;"># Drop into .github/workflows/ of an R package or Shiny app repo.</span></span>
<span id="cb5-2"><span class="co" style="color: #5E5E5E;"># With squash-merge, the PR title becomes the commit on main, so check it here.</span></span>
<span id="cb5-3"><span class="co" style="color: #5E5E5E;"># No Node or npm needed in the R repo: this is a hosted action.</span></span>
<span id="cb5-4"><span class="fu" style="color: #4758AB;">name</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> pr-title</span></span>
<span id="cb5-5"></span>
<span id="cb5-6"><span class="fu" style="color: #4758AB;">on</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb5-7"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">pull_request</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb5-8"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">types</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="kw" style="color: #003B4F;
font-weight: bold;">[</span><span class="at" style="color: #657422;">opened</span><span class="kw" style="color: #003B4F;
font-weight: bold;">,</span><span class="at" style="color: #657422;"> edited</span><span class="kw" style="color: #003B4F;
font-weight: bold;">,</span><span class="at" style="color: #657422;"> reopened</span><span class="kw" style="color: #003B4F;
font-weight: bold;">,</span><span class="at" style="color: #657422;"> synchronize</span><span class="kw" style="color: #003B4F;
font-weight: bold;">]</span></span>
<span id="cb5-9"></span>
<span id="cb5-10"><span class="fu" style="color: #4758AB;">permissions</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb5-11"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">pull-requests</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> read</span></span>
<span id="cb5-12"></span>
<span id="cb5-13"><span class="fu" style="color: #4758AB;">jobs</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb5-14"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">conventional-title</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb5-15"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">runs-on</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> ubuntu-latest</span></span>
<span id="cb5-16"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">steps</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb5-17"><span class="at" style="color: #657422;">      </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">uses</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> amannn/action-semantic-pull-request@v6</span></span>
<span id="cb5-18"><span class="at" style="color: #657422;">        </span><span class="fu" style="color: #4758AB;">env</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb5-19"><span class="at" style="color: #657422;">          </span><span class="fu" style="color: #4758AB;">GITHUB_TOKEN</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> ${{ secrets.GITHUB_TOKEN }}</span></span></code></pre></div></div>
</div>
</div>
</div>
<p><strong>For the local layer, skip <code>commitlint</code>.</strong> Pulling Node into an R package just for this isn’t worth it. A 15-line shell hook does the same job, and <code>usethis</code> installs it. Save <a href="https://insightsurge-dev.web.app/templates/git-hooks/commit-msg"><code>templates/git-hooks/commit-msg</code></a> in your project root as <code>commit-msg</code>:</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-2-contents" aria-controls="callout-2" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Full template: <code>commit-msg</code>
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-2" class="callout-2-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb6-1"><span class="co" style="color: #5E5E5E;">#!/bin/sh</span></span>
<span id="cb6-2"><span class="co" style="color: #5E5E5E;"># Conventional Commits check for repos without Node (R packages, Shiny apps).</span></span>
<span id="cb6-3"><span class="co" style="color: #5E5E5E;"># Install from R:  usethis::use_git_hook("commit-msg", readLines("commit-msg"))</span></span>
<span id="cb6-4"><span class="va" style="color: #111111;">first_line</span><span class="op" style="color: #5E5E5E;">=</span><span class="va" style="color: #111111;">$(</span><span class="fu" style="color: #4758AB;">head</span> <span class="at" style="color: #657422;">-n</span> 1 <span class="st" style="color: #20794D;">"</span><span class="va" style="color: #111111;">$1</span><span class="st" style="color: #20794D;">"</span><span class="va" style="color: #111111;">)</span></span>
<span id="cb6-5"><span class="cf" style="color: #003B4F;
font-weight: bold;">case</span> <span class="st" style="color: #20794D;">"</span><span class="va" style="color: #111111;">$first_line</span><span class="st" style="color: #20794D;">"</span> <span class="kw" style="color: #003B4F;
font-weight: bold;">in</span></span>
<span id="cb6-6">  <span class="ss" style="color: #20794D;">Merge</span><span class="dt" style="color: #AD0000;">\ </span><span class="pp" style="color: #AD0000;">*</span><span class="kw" style="color: #003B4F;
font-weight: bold;">|</span><span class="ss" style="color: #20794D;">Revert</span><span class="dt" style="color: #AD0000;">\ </span><span class="pp" style="color: #AD0000;">*</span><span class="kw" style="color: #003B4F;
font-weight: bold;">|</span><span class="ss" style="color: #20794D;">fixup!</span><span class="dt" style="color: #AD0000;">\ </span><span class="pp" style="color: #AD0000;">*</span><span class="kw" style="color: #003B4F;
font-weight: bold;">|</span><span class="ss" style="color: #20794D;">squash!</span><span class="dt" style="color: #AD0000;">\ </span><span class="pp" style="color: #AD0000;">*</span><span class="kw" style="color: #003B4F;
font-weight: bold;">)</span> <span class="bu" style="color: null;">exit</span> 0 <span class="cf" style="color: #003B4F;
font-weight: bold;">;;</span></span>
<span id="cb6-7"><span class="cf" style="color: #003B4F;
font-weight: bold;">esac</span></span>
<span id="cb6-8"><span class="va" style="color: #111111;">pattern</span><span class="op" style="color: #5E5E5E;">=</span><span class="st" style="color: #20794D;">'^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-zA-Z0-9_./-]+\))?!?: .+'</span></span>
<span id="cb6-9"><span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> <span class="bu" style="color: null;">printf</span> <span class="st" style="color: #20794D;">'%s'</span> <span class="st" style="color: #20794D;">"</span><span class="va" style="color: #111111;">$first_line</span><span class="st" style="color: #20794D;">"</span> <span class="kw" style="color: #003B4F;
font-weight: bold;">|</span> <span class="fu" style="color: #4758AB;">grep</span> <span class="at" style="color: #657422;">-Eq</span> <span class="st" style="color: #20794D;">"</span><span class="va" style="color: #111111;">$pattern</span><span class="st" style="color: #20794D;">"</span><span class="kw" style="color: #003B4F;
font-weight: bold;">;</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">then</span></span>
<span id="cb6-10">  <span class="bu" style="color: null;">exit</span> 0</span>
<span id="cb6-11"><span class="cf" style="color: #003B4F;
font-weight: bold;">fi</span></span>
<span id="cb6-12"><span class="bu" style="color: null;">echo</span> <span class="st" style="color: #20794D;">"✖ Commit message is not a Conventional Commit:"</span> <span class="op" style="color: #5E5E5E;">&gt;&amp;</span><span class="dv" style="color: #AD0000;">2</span></span>
<span id="cb6-13"><span class="bu" style="color: null;">echo</span> <span class="st" style="color: #20794D;">"    </span><span class="va" style="color: #111111;">$first_line</span><span class="st" style="color: #20794D;">"</span> <span class="op" style="color: #5E5E5E;">&gt;&amp;</span><span class="dv" style="color: #AD0000;">2</span></span>
<span id="cb6-14"><span class="bu" style="color: null;">echo</span> <span class="st" style="color: #20794D;">"  Expected: &lt;type&gt;(&lt;optional scope&gt;): &lt;description&gt;"</span> <span class="op" style="color: #5E5E5E;">&gt;&amp;</span><span class="dv" style="color: #AD0000;">2</span></span>
<span id="cb6-15"><span class="bu" style="color: null;">echo</span> <span class="st" style="color: #20794D;">"  e.g.  feat(read_adsl): support SAS transport files"</span> <span class="op" style="color: #5E5E5E;">&gt;&amp;</span><span class="dv" style="color: #AD0000;">2</span></span>
<span id="cb6-16"><span class="bu" style="color: null;">echo</span> <span class="st" style="color: #20794D;">"        fix: handle empty data in km_plot()"</span> <span class="op" style="color: #5E5E5E;">&gt;&amp;</span><span class="dv" style="color: #AD0000;">2</span></span>
<span id="cb6-17"><span class="bu" style="color: null;">exit</span> 1</span></code></pre></div></div>
</div>
</div>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r norun code-with-copy"><code class="sourceCode r"><span id="cb7-1">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">use_git_hook</span>(</span>
<span id="cb7-2">  <span class="st" style="color: #20794D;">"commit-msg"</span>,</span>
<span id="cb7-3">  <span class="fu" style="color: #4758AB;">readLines</span>(<span class="st" style="color: #20794D;">"commit-msg"</span>)</span>
<span id="cb7-4">)</span></code></pre></div></div>
<p>We tested the hook against these messages:</p>
<div class="table-responsive">
<table class="caption-top table">
<thead>
<tr class="header">
<th>Message</th>
<th>Result</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><code>feat(read_adsl): support xpt files</code></td>
<td>✓</td>
</tr>
<tr class="even">
<td><code>feat!: drop R 4.1 support</code></td>
<td>✓</td>
</tr>
<tr class="odd">
<td><code>Merge branch 'main'</code></td>
<td>✓ (merges and reverts are let through)</td>
</tr>
<tr class="even">
<td><code>updated stuff</code></td>
<td>✗</td>
</tr>
<tr class="odd">
<td><code>Feat: capitalised type</code></td>
<td>✗</td>
</tr>
<tr class="even">
<td><code>feat:missing space</code></td>
<td>✗</td>
</tr>
</tbody>
</table>
</div>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Hooks are local and optional; CI is the gate
</div>
</div>
<div class="callout-body-container callout-body">
<p>Git hooks live in <code>.git/hooks/</code>, which is never committed, so every clone has to install them. Treat the local hook as a convenience that catches mistakes early. The <strong>PR title check in CI</strong> is the actual rule, because nobody can skip it.</p>
</div>
</div>
</section>
<section id="what-you-get-in-return" class="level2">
<h2 class="anchored" data-anchor-id="what-you-get-in-return">What you get in return</h2>
<ul>
<li><strong>A readable history:</strong> <code>git log --oneline</code> reads like a changelog.</li>
<li><strong>Automatic version bumps and NEWS/CHANGELOG entries.</strong> Tools read <code>feat</code>/<code>fix</code>/<code>!</code> to decide the next version (<a href="https://insightsurge-dev.web.app/posts/releases-changelogs/index.html">releases &amp; changelogs</a>).</li>
<li><strong>Faster review:</strong> the title tells the reviewer what kind of change to expect.</li>
<li><strong>Better change-control evidence:</strong> each change on <code>main</code> has a type, a scope, a description and a linked PR with its review and CI results.</li>
</ul>
</section>
<section id="pitfalls" class="level2">
<h2 class="anchored" data-anchor-id="pitfalls">Pitfalls</h2>
<ul>
<li><strong>The title check only runs when the PR changes.</strong> It’s triggered by <code>edited</code>, so after renaming a PR the check re-runs by itself, and you don’t need to push again.</li>
<li><strong>Squash settings are per repo.</strong> New repos default to allowing all three merge methods. Set squash-only when you create the repo.</li>
<li><strong>Don’t over-engineer scopes.</strong> Free-text function names beat a mandated list nobody remembers.</li>
<li><strong>Merge commits from <code>git pull</code></strong> would fail a strict hook. The template lets <code>Merge …</code> and <code>Revert …</code> through, and <code>pull.rebase = true</code> avoids them anyway.</li>
</ul>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<p><strong>Standards and tools</strong></p>
<ul>
<li><strong>Conventional Commits</strong>: <a href="https://www.conventionalcommits.org/en/v1.0.0/">conventionalcommits.org</a></li>
<li><strong>commitlint</strong>: <a href="https://commitlint.js.org/">commitlint.js.org</a></li>
<li><strong>husky</strong>: <a href="https://typicode.github.io/husky/">typicode.github.io/husky</a></li>
<li><strong>amannn/action-semantic-pull-request</strong>: <a href="https://github.com/amannn/action-semantic-pull-request">github.com/amannn/action-semantic-pull-request</a></li>
<li><strong>Squash merging: PR title becomes the commit message</strong>: <a href="https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/configuring-commit-squashing-for-pull-requests">GitHub Docs: Configuring commit squashing for pull requests</a></li>
</ul>
<p><strong>R package documentation</strong></p>
<ul>
<li><strong>usethis</strong> (<code>use_git_hook()</code>): <a href="https://usethis.r-lib.org/">usethis.r-lib.org</a></li>
</ul>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-4-contents" aria-controls="callout-4" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Updates
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-4" class="callout-4-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<ul>
<li><strong>2026-09-26:</strong> Removed the end-of-post checklist.</li>
<li><strong>2026-09-27:</strong> Added a Sources section.</li>
<li><strong>2026-09-27:</strong> Linked every template file and showed it on the page.</li>
</ul>
</div>
</div>
</div>



<div class="site-related">
<div class="site-series-nav">
<p><a href="https://insightsurge-dev.web.app/series/foundations.html" class="site-series-nav__series">Foundations series · part 3 of 16</a></p>
<div class="site-card-grid site-series-nav__links">
<div class="site-card-cell">
<a href="https://insightsurge-dev.web.app/posts/git-workflow/index.html" class="is-card site-related-card site-series-nav__prev"><span class="is-card__eyebrow">Previous · part 2</span><span class="site-related-card__title">Git workflow: branches, squash-only merges, signed commits</span></a>
</div>
<div class="site-card-cell">
<a href="https://insightsurge-dev.web.app/posts/hooks-formatting-linting/index.html" class="is-card site-related-card site-series-nav__next"><span class="is-card__eyebrow">Next · part 4</span><span class="site-related-card__title">Pre-commit hooks, formatting &amp; linting</span></a>
</div>
</div>
</div>
<section id="keep-reading" class="level2 unnumbered unlisted no-anchor">
<h2 class="unnumbered unlisted no-anchor" data-anchor-id="keep-reading">Keep reading</h2>
<div class="site-link-list">
<ul>
<li><a href="https://insightsurge-dev.web.app/posts/releases-changelogs/index.html" class="site-link-row" title="Adopt semantic versioning, readable changelogs, and annotated git tags to support change control."><span class="is-card__eyebrow site-link-row__label">Read next</span><span class="site-link-row__title">Releases &amp; changelogs</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/from-scripts-to-a-package/index.html" class="site-link-row" title="Move reusable analysis helpers from sourced scripts into a minimal R package, and replace workspace pollution with the devtools::load_all() loop."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">From scripts to a package</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/package-dev-loop-r-cmd-check/index.html" class="site-link-row" title="Use the R package development loop, read R CMD check diagnostics, and fix four recurring problems."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">The package development loop and R CMD check</span></a></li>
</ul>
</div>
</section>
</div>

</section>

 ]]></description>
  <category>Git</category>
  <category>R packages</category>
  <category>Best practices</category>
  <guid>https://insightsurge-dev.web.app/posts/conventional-commits-pr-titles/</guid>
  <pubDate>Fri, 25 Sep 2026 18:30:00 GMT</pubDate>
</item>
<item>
  <title>Git workflow: branches, squash-only merges, signed commits</title>
  <link>https://insightsurge-dev.web.app/posts/git-workflow/</link>
  <description><![CDATA[ 





<!--
  Quarto 1.8.27's title-block.html with three changes: category badges and a
  series link ("Testing series · part 2") sit above the title, as in the brand's
  blog kit; and a post or series page with `trailer: true` shows its trailer beside the title
  (_filters/trailer.lua sets trailer-path; _includes/trailers.html plays it). On a Quarto upgrade, diff this against
  share/formats/html/templates/title-block.html and carry over any changes.
-->



<section id="the-problem" class="level2">
<h2 class="anchored" data-anchor-id="the-problem">The problem</h2>
<p>Solo R work often happens straight on <code>main</code>: edit, commit, push. It works until two people touch the same package, a half-finished change reaches a user, or someone asks “who approved this change, and what tests ran?”</p>
<p>A small workflow fixes all three, and every piece of it has an R-native helper.</p>
</section>
<section id="the-workflow" class="level2">
<h2 class="anchored" data-anchor-id="the-workflow">The workflow</h2>
<pre><code>main ──●───────────────●──────────  (always releasable; one squash commit per PR)
        \             /
         ●──●──●──●──●   feat/km-risk-table  (messy commits are fine here)
                      └─ PR: title "feat(km_plot): add risk table", CI green, reviewed</code></pre>
<ol type="1">
<li><strong>Branch</strong> from an up-to-date <code>main</code>, one branch per issue: <code>feat/…</code>, <code>fix/…</code>, <code>docs/…</code>.</li>
<li><strong>Commit freely</strong> on the branch.</li>
<li><strong>Open a PR.</strong> CI runs, someone reviews, and the PR title follows <a href="https://insightsurge-dev.web.app/posts/conventional-commits-pr-titles/index.html">Conventional Commits</a>.</li>
<li><strong>Squash-merge.</strong> The branch becomes one commit on <code>main</code>, and the branch is deleted.</li>
</ol>
</section>
<section id="the-web-repo-way-repo-settings" class="level2">
<h2 class="anchored" data-anchor-id="the-web-repo-way-repo-settings">The web-repo way: repo settings</h2>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb2-1"><span class="ex" style="color: null;">gh</span> api <span class="at" style="color: #657422;">-X</span> PATCH repos/OWNER/REPO <span class="dt" style="color: #AD0000;">\</span></span>
<span id="cb2-2">  <span class="at" style="color: #657422;">-F</span> allow_squash_merge=true <span class="at" style="color: #657422;">-F</span> allow_merge_commit=false <span class="at" style="color: #657422;">-F</span> allow_rebase_merge=false <span class="dt" style="color: #AD0000;">\</span></span>
<span id="cb2-3">  <span class="at" style="color: #657422;">-F</span> delete_branch_on_merge=true <span class="dt" style="color: #AD0000;">\</span></span>
<span id="cb2-4">  <span class="at" style="color: #657422;">-f</span> squash_merge_commit_title=PR_TITLE <span class="at" style="color: #657422;">-f</span> squash_merge_commit_message=PR_BODY</span></code></pre></div></div>
<div class="table-responsive">
<table class="caption-top table">
<colgroup>
<col style="width: 50%">
<col style="width: 50%">
</colgroup>
<thead>
<tr class="header">
<th>Setting</th>
<th>Why</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Squash only</td>
<td>Linear history, where one commit is one reviewed change. <code>git revert &lt;sha&gt;</code> undoes a whole feature.</td>
</tr>
<tr class="even">
<td>Title = PR title</td>
<td>The commit message is the reviewed, conventional title</td>
</tr>
<tr class="odd">
<td>Auto-delete branches</td>
<td>No graveyard of stale branches</td>
</tr>
</tbody>
</table>
</div>
<section id="branch-protection-check-your-plan" class="level3">
<h3 class="anchored" data-anchor-id="branch-protection-check-your-plan">Branch protection: check your plan</h3>
<p>Branch protection and rulesets are what <em>enforce</em> “no direct pushes to <code>main</code>” and “CI must pass”. <strong>On GitHub Free they only work on public repos.</strong> We checked a private repo on a free account, and the API answered: <em>“Upgrade to GitHub Pro or make this repository public to enable this feature.”</em></p>
<p>On a private free repo you have two options: follow the workflow <strong>by convention</strong> (and say so in <code>CONTRIBUTING.md</code>), or upgrade. On Team or Enterprise plans, turn on: require a PR, require status checks (<code>R-CMD-check</code>), require linear history, and block force-pushes.</p>
</section>
</section>
<section id="signed-commits" class="level2">
<h2 class="anchored" data-anchor-id="signed-commits">Signed commits</h2>
<p><code>user.email</code> is just text; anyone can type yours. A <strong>signature</strong> proves a commit came from a key you control, and GitHub then shows <strong>Verified</strong>. SSH signing reuses the kind of key you already push with:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode ini code-with-copy"><code class="sourceCode ini"><span id="cb3-1"><span class="kw" style="color: #003B4F;
font-weight: bold;">[gpg]</span></span>
<span id="cb3-2"><span class="dt" style="color: #AD0000;">    format </span><span class="ot" style="color: #003B4F;">=</span><span class="st" style="color: #20794D;"> ssh</span></span>
<span id="cb3-3"><span class="kw" style="color: #003B4F;
font-weight: bold;">[user]</span></span>
<span id="cb3-4"><span class="dt" style="color: #AD0000;">    signingkey </span><span class="ot" style="color: #003B4F;">=</span><span class="st" style="color: #20794D;"> ~/.ssh/id_ed25519_work.pub</span></span>
<span id="cb3-5"><span class="kw" style="color: #003B4F;
font-weight: bold;">[commit]</span></span>
<span id="cb3-6"><span class="dt" style="color: #AD0000;">    gpgsign </span><span class="ot" style="color: #003B4F;">=</span><span class="st" style="color: #20794D;"> </span><span class="kw" style="color: #003B4F;
font-weight: bold;">true</span></span>
<span id="cb3-7"><span class="kw" style="color: #003B4F;
font-weight: bold;">[tag]</span></span>
<span id="cb3-8"><span class="dt" style="color: #AD0000;">    gpgsign </span><span class="ot" style="color: #003B4F;">=</span><span class="st" style="color: #20794D;"> </span><span class="kw" style="color: #003B4F;
font-weight: bold;">true</span></span></code></pre></div></div>
<p>Add the <strong>same public key to GitHub a second time, as a Signing key</strong>. The Authentication key entry doesn’t cover signing.</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>“No signature” locally doesn’t mean unsigned
</div>
</div>
<div class="callout-body-container callout-body">
<p>After enabling signing, <code>git log --show-signature</code> printed <em>“No signature”</em> with an error about <code>gpg.ssh.allowedSignersFile</code>. The commit <strong>was</strong> signed: <code>git cat-file -p HEAD</code> showed a <code>BEGIN SSH SIGNATURE</code> block, and GitHub marked it Verified. Git simply had no list of keys to trust locally. Fix:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb4-1"><span class="bu" style="color: null;">echo</span> <span class="st" style="color: #20794D;">"you@users.noreply.github.com </span><span class="va" style="color: #111111;">$(</span><span class="fu" style="color: #4758AB;">cut</span> <span class="at" style="color: #657422;">-d</span><span class="st" style="color: #20794D;">' '</span> <span class="at" style="color: #657422;">-f1,2</span> ~/.ssh/id_ed25519_work.pub<span class="va" style="color: #111111;">)</span><span class="st" style="color: #20794D;">"</span> <span class="op" style="color: #5E5E5E;">&gt;</span> ~/.ssh/allowed_signers</span>
<span id="cb4-2"><span class="fu" style="color: #4758AB;">git</span> config gpg.ssh.allowedSignersFile ~/.ssh/allowed_signers</span></code></pre></div></div>
<p>Now <code>git log --show-signature</code> reports <em>Good “git” signature</em>.</p>
</div>
</div>
<p>For GxP, signed commits plus PR review are strong evidence of <strong>who</strong> made a change and <strong>who approved it</strong>. The same ALCOA+ <em>Attributable</em> point comes up in <a href="https://insightsurge-dev.web.app/posts/identity-isolation/index.html">identity and environment isolation</a>.</p>
</section>
<section id="the-r-way-usethispr_" class="level2">
<h2 class="anchored" data-anchor-id="the-r-way-usethispr_">The R way: <code>usethis::pr_*()</code></h2>
<p><code>usethis</code> wraps the whole loop, so you never need to remember the git commands:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r norun code-with-copy"><code class="sourceCode r"><span id="cb5-1">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">pr_init</span>(<span class="st" style="color: #20794D;">"feat-km-risk-table"</span>)  <span class="co" style="color: #5E5E5E;"># branch from an up-to-date default branch</span></span>
<span id="cb5-2"><span class="co" style="color: #5E5E5E;"># ... edit, commit (RStudio/Positron Git pane is fine) ...</span></span>
<span id="cb5-3">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">pr_push</span>()                       <span class="co" style="color: #5E5E5E;"># push and open the PR page in the browser</span></span>
<span id="cb5-4">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">pr_pull</span>()                       <span class="co" style="color: #5E5E5E;"># pull reviewer changes</span></span>
<span id="cb5-5">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">pr_merge_main</span>()                 <span class="co" style="color: #5E5E5E;"># bring in new commits from main</span></span>
<span id="cb5-6">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">pr_finish</span>()                     <span class="co" style="color: #5E5E5E;"># after merge: delete local branch, back to main</span></span>
<span id="cb5-7">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">pr_fetch</span>(<span class="dv" style="color: #AD0000;">42</span>)                    <span class="co" style="color: #5E5E5E;"># check out someone else's PR #42 to review it</span></span></code></pre></div></div>
<p>Squash-merge in the GitHub UI, or with <code>gh pr merge 42 --squash</code>. The IDE Git panes call your system <code>git</code>, so signing configured in git applies to IDE commits too.</p>
</section>
<section id="pitfalls" class="level2">
<h2 class="anchored" data-anchor-id="pitfalls">Pitfalls</h2>
<ul>
<li><strong><code>git pull</code> merge commits.</strong> Set <code>git config --global pull.rebase true</code>.</li>
<li><strong>Long-lived branches</strong> drift and conflict. Keep PRs small, and use <code>pr_merge_main()</code> often.</li>
<li><strong>Squash hides branch history on <code>main</code>.</strong> That’s the point: the PR keeps the detail.</li>
<li><strong>Signing key on a new machine.</strong> Signing fails until the key and config exist, so set it up once per machine (<a href="https://insightsurge-dev.web.app/posts/identity-isolation/index.html">identity and environment isolation</a>).</li>
</ul>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<p><strong>Git and GitHub</strong></p>
<ul>
<li><strong>git config (<code>gpg.format</code>, <code>gpg.ssh.allowedSignersFile</code>, <code>commit.gpgsign</code>)</strong>: <a href="https://git-scm.com/docs/git-config#Documentation/git-config.txt-gpgsshallowedSignersFile">git-scm.com/docs/git-config</a></li>
<li><strong>Repository settings API (squash-only merge, branch deletion)</strong>: <a href="https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#update-a-repository">GitHub REST API: Update a repository</a></li>
<li><strong>Branch protection</strong>: <a href="https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches">GitHub Docs: About protected branches</a></li>
<li><strong>Rulesets</strong>: <a href="https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/about-rulesets">GitHub Docs: About rulesets</a></li>
<li><strong>Signing commits (SSH signatures, Verified badge)</strong>: <a href="https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits">GitHub Docs: Signing commits</a></li>
<li><strong><code>gh pr merge</code></strong>: <a href="https://cli.github.com/manual/gh_pr_merge">cli.github.com/manual/gh_pr_merge</a></li>
</ul>
<p><strong>R package documentation</strong></p>
<ul>
<li><strong>usethis</strong> (<code>pr_init()</code>, <code>pr_push()</code>, <code>pr_pull()</code>, <code>pr_merge_main()</code>, <code>pr_finish()</code>, <code>pr_fetch()</code>): <a href="https://usethis.r-lib.org/">usethis.r-lib.org</a></li>
</ul>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-2-contents" aria-controls="callout-2" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Updates
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-2" class="callout-2-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<ul>
<li><strong>2026-09-26:</strong> Removed the end-of-post checklist.</li>
<li><strong>2026-09-27:</strong> Added a Sources section.</li>
</ul>
</div>
</div>
</div>



<div class="site-related">
<div class="site-series-nav">
<p><a href="https://insightsurge-dev.web.app/series/foundations.html" class="site-series-nav__series">Foundations series · part 2 of 16</a></p>
<div class="site-card-grid site-series-nav__links">
<div class="site-card-cell">
<a href="https://insightsurge-dev.web.app/posts/identity-isolation/index.html" class="is-card site-related-card site-series-nav__prev"><span class="is-card__eyebrow">Previous · part 1</span><span class="site-related-card__title">Identity &amp; environment isolation</span></a>
</div>
<div class="site-card-cell">
<a href="https://insightsurge-dev.web.app/posts/conventional-commits-pr-titles/index.html" class="is-card site-related-card site-series-nav__next"><span class="is-card__eyebrow">Next · part 3</span><span class="site-related-card__title">Conventional commits &amp; PR title checks</span></a>
</div>
</div>
</div>
<section id="keep-reading" class="level2 unnumbered unlisted no-anchor">
<h2 class="unnumbered unlisted no-anchor" data-anchor-id="keep-reading">Keep reading</h2>
<div class="site-link-list">
<ul>
<li><a href="https://insightsurge-dev.web.app/posts/test-your-guardrails/index.html" class="site-link-row" title="Challenge CI checks and pre-commit hooks deliberately with failing test PRs to prove guardrails work."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Test your guardrails: probe PRs</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/releases-changelogs/index.html" class="site-link-row" title="Adopt semantic versioning, readable changelogs, and annotated git tags to support change control."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Releases &amp; changelogs</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/two-model-workflow/index.html" class="site-link-row" title="Structure dual-model AI workflows with clear task ownership, written briefs, and human verification to maintain engineering rigor."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">One owner, two models: delegating to a second AI and verifying it</span></a></li>
</ul>
</div>
</section>
</div>

</section>

 ]]></description>
  <category>Git</category>
  <category>GxP</category>
  <category>Best practices</category>
  <guid>https://insightsurge-dev.web.app/posts/git-workflow/</guid>
  <pubDate>Fri, 25 Sep 2026 18:30:00 GMT</pubDate>
</item>
<item>
  <title>Identity &amp; environment isolation</title>
  <link>https://insightsurge-dev.web.app/posts/identity-isolation/</link>
  <description><![CDATA[ 





<!--
  Quarto 1.8.27's title-block.html with three changes: category badges and a
  series link ("Testing series · part 2") sit above the title, as in the brand's
  blog kit; and a post or series page with `trailer: true` shows its trailer beside the title
  (_filters/trailer.lua sets trailer-path; _includes/trailers.html plays it). On a Quarto upgrade, diff this against
  share/formats/html/templates/title-block.html and carry over any changes.
-->



<section id="the-problem" class="level2">
<h2 class="anchored" data-anchor-id="the-problem">The problem</h2>
<p>Many of us run more than one “self” on the same machine: a day job, a side project, open-source work, a client engagement. Each has its own:</p>
<ul>
<li><strong>git author</strong>: the name and email stamped on every commit;</li>
<li><strong>git transport credentials</strong>: the SSH key or token used to push;</li>
<li><strong>GitHub CLI/API login</strong>: what <code>gh</code>, or <code>gh::gh()</code> in R, acts as;</li>
<li><strong>cloud login</strong>: the account <code>gcloud</code>, <code>firebase</code> or <code>az</code> deploys with;</li>
<li><strong>AI tool account</strong>: which subscription, and which organisation’s data policy, your prompts fall under;</li>
<li><strong>package registry</strong>: where <code>npm install</code> or <code>install.packages()</code> downloads from.</li>
</ul>
<p>Get any one of these wrong and you can commit company work under a personal email, push to the wrong organisation, deploy into someone else’s cloud project, or send code to an AI tool under the wrong data agreement. None of these fail loudly.</p>
<p>In GxP terms this is <strong>ALCOA+ “Attributable”</strong>: every record, including a commit, should show unambiguously who created it. Identity isolation is how you make that true by construction, not by remembering.</p>
<blockquote class="blockquote">
<p><strong>Principle:</strong> scope identity to a <em>folder</em>, not to a <em>machine</em>, and have every session prove its identity before it does anything outward-facing.</p>
</blockquote>
</section>
<section id="the-web-repo-way" class="level2">
<h2 class="anchored" data-anchor-id="the-web-repo-way">The web-repo way</h2>
<p>The pattern below is common in JavaScript and TypeScript shops. All of a project’s repos live under one workspace folder, and every identity is pinned to that folder.</p>
<section id="folder-scoped-git-identity-with-includeif" class="level3">
<h3 class="anchored" data-anchor-id="folder-scoped-git-identity-with-includeif">1. Folder-scoped git identity with <code>includeIf</code></h3>
<p>Your global <code>~/.gitconfig</code> keeps your everyday identity. One extra block loads a second config file, but only for repos under the workspace folder:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode ini code-with-copy"><code class="sourceCode ini"><span id="cb1-1"><span class="co" style="color: #5E5E5E;"># ~/.gitconfig (the only global edit)</span></span>
<span id="cb1-2"><span class="kw" style="color: #003B4F;
font-weight: bold;">[includeIf "gitdir/i:~/Projects/Acme/"]</span></span>
<span id="cb1-3"><span class="dt" style="color: #AD0000;">    path </span><span class="ot" style="color: #003B4F;">=</span><span class="st" style="color: #20794D;"> ~/Projects/Acme/.gitconfig-acme</span></span></code></pre></div></div>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode ini code-with-copy"><code class="sourceCode ini"><span id="cb2-1"><span class="co" style="color: #5E5E5E;"># ~/Projects/Acme/.gitconfig-acme</span></span>
<span id="cb2-2"><span class="kw" style="color: #003B4F;
font-weight: bold;">[user]</span></span>
<span id="cb2-3"><span class="dt" style="color: #AD0000;">    name </span><span class="ot" style="color: #003B4F;">=</span><span class="st" style="color: #20794D;"> Your Name</span></span>
<span id="cb2-4"><span class="dt" style="color: #AD0000;">    email </span><span class="ot" style="color: #003B4F;">=</span><span class="st" style="color: #20794D;"> 12345+acme-bot@users.noreply.github.com   # GitHub noreply address</span></span>
<span id="cb2-5"><span class="dt" style="color: #AD0000;">    signingkey </span><span class="ot" style="color: #003B4F;">=</span><span class="st" style="color: #20794D;"> ~/.ssh/id_ed25519_acme.pub</span></span>
<span id="cb2-6"><span class="kw" style="color: #003B4F;
font-weight: bold;">[core]</span></span>
<span id="cb2-7"><span class="dt" style="color: #AD0000;">    sshCommand </span><span class="ot" style="color: #003B4F;">=</span><span class="st" style="color: #20794D;"> ssh -i ~/.ssh/id_ed25519_acme -o IdentitiesOnly=yes</span></span>
<span id="cb2-8"><span class="kw" style="color: #003B4F;
font-weight: bold;">[gpg]</span></span>
<span id="cb2-9"><span class="dt" style="color: #AD0000;">    format </span><span class="ot" style="color: #003B4F;">=</span><span class="st" style="color: #20794D;"> ssh</span></span>
<span id="cb2-10"><span class="kw" style="color: #003B4F;
font-weight: bold;">[commit]</span></span>
<span id="cb2-11"><span class="dt" style="color: #AD0000;">    gpgsign </span><span class="ot" style="color: #003B4F;">=</span><span class="st" style="color: #20794D;"> </span><span class="kw" style="color: #003B4F;
font-weight: bold;">true</span></span>
<span id="cb2-12"><span class="kw" style="color: #003B4F;
font-weight: bold;">[credential]</span></span>
<span id="cb2-13"><span class="dt" style="color: #AD0000;">    helper </span><span class="ot" style="color: #003B4F;">=</span><span class="st" style="color: #20794D;">                                  # blank: never reuse another account's token</span></span>
<span id="cb2-14"><span class="kw" style="color: #003B4F;
font-weight: bold;">[url "git@github.com:"]</span></span>
<span id="cb2-15"><span class="dt" style="color: #AD0000;">    insteadOf </span><span class="ot" style="color: #003B4F;">=</span><span class="st" style="color: #20794D;"> https://github.com/           # always use SSH, so always this key</span></span></code></pre></div></div>
<p>What each line buys you:</p>
<div class="table-responsive">
<table class="caption-top table">
<colgroup>
<col style="width: 50%">
<col style="width: 50%">
</colgroup>
<thead>
<tr class="header">
<th>Setting</th>
<th>Protects against</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><code>gitdir/i:</code> with a trailing <code>/</code></td>
<td>Case differences on macOS; the <code>/</code> means “everything under this folder”</td>
</tr>
<tr class="even">
<td>noreply email</td>
<td>Exposing a personal inbox; commits still link to the right account</td>
</tr>
<tr class="odd">
<td><code>IdentitiesOnly=yes</code> + a dedicated key</td>
<td>SSH offering your <em>other</em> key first and pushing as the wrong user</td>
</tr>
<tr class="even">
<td>blank <code>credential.helper</code></td>
<td>An HTTPS token saved in the OS keychain for another account being reused</td>
</tr>
<tr class="odd">
<td><code>insteadOf</code></td>
<td>An <code>https://</code> URL quietly bypassing the SSH key</td>
</tr>
<tr class="even">
<td>SSH commit signing</td>
<td>Anyone setting <code>user.email</code> to your address. GitHub shows <strong>Verified</strong> only for your key</td>
</tr>
</tbody>
</table>
</div>
<p>Check it from inside a repo:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb3-1"><span class="fu" style="color: #4758AB;">git</span> config <span class="at" style="color: #657422;">--show-origin</span> user.email      <span class="co" style="color: #5E5E5E;"># shows which file the value came from</span></span>
<span id="cb3-2"><span class="fu" style="color: #4758AB;">ssh</span> <span class="at" style="color: #657422;">-T</span> git@github.com                    <span class="co" style="color: #5E5E5E;"># greets the account that owns the key</span></span></code></pre></div></div>
<section id="hardening-dedicated-keys-with-a-passphrase" class="level4">
<h4 class="anchored" data-anchor-id="hardening-dedicated-keys-with-a-passphrase">Hardening dedicated keys with a passphrase</h4>
<p>Never leave private SSH keys unencrypted on disk. Add a passphrase to your dedicated key and delegate passphrase caching to the macOS keychain:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb4-1"><span class="fu" style="color: #4758AB;">ssh-keygen</span> <span class="at" style="color: #657422;">-p</span> <span class="at" style="color: #657422;">-f</span> ~/.ssh/id_ed25519_acme</span>
<span id="cb4-2"><span class="fu" style="color: #4758AB;">ssh-add</span> <span class="at" style="color: #657422;">--apple-use-keychain</span> ~/.ssh/id_ed25519_acme</span></code></pre></div></div>
<p>An empty passphrase is the same as none; it provides no protection if a local file is read or exfiltrated. Once the key is loaded into the agent, SSH commit signing and git operations continue working without interactive passphrase prompts on every commit.</p>
</section>
</section>
<section id="cli-logins-in-the-workspace-not-in-your-home-folder" class="level3">
<h3 class="anchored" data-anchor-id="cli-logins-in-the-workspace-not-in-your-home-folder">2. CLI logins in the workspace, not in your home folder</h3>
<p>Most CLIs store their login in a config folder that an environment variable can override. Point these variables inside the workspace, and the logins can’t collide with your other accounts:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb5-1"><span class="bu" style="color: null;">export</span> <span class="va" style="color: #111111;">GH_CONFIG_DIR</span><span class="op" style="color: #5E5E5E;">=</span><span class="st" style="color: #20794D;">"</span><span class="va" style="color: #111111;">$WS</span><span class="st" style="color: #20794D;">/.config/gh"</span>            <span class="co" style="color: #5E5E5E;"># GitHub CLI</span></span>
<span id="cb5-2"><span class="bu" style="color: null;">export</span> <span class="va" style="color: #111111;">CLOUDSDK_CONFIG</span><span class="op" style="color: #5E5E5E;">=</span><span class="st" style="color: #20794D;">"</span><span class="va" style="color: #111111;">$WS</span><span class="st" style="color: #20794D;">/.config/gcloud"</span>      <span class="co" style="color: #5E5E5E;"># gcloud</span></span>
<span id="cb5-3"><span class="bu" style="color: null;">export</span> <span class="va" style="color: #111111;">XDG_CONFIG_HOME</span><span class="op" style="color: #5E5E5E;">=</span><span class="st" style="color: #20794D;">"</span><span class="va" style="color: #111111;">$WS</span><span class="st" style="color: #20794D;">/.config"</span>             <span class="co" style="color: #5E5E5E;"># many other CLIs (firebase, etc.)</span></span></code></pre></div></div>
<p>Put these in an <code>activate.sh</code> that you <code>source</code> when you start work, the way you’d activate a Python virtual environment.</p>
</section>
<section id="guards-print-every-identity-and-refuse-on-a-mismatch" class="level3">
<h3 class="anchored" data-anchor-id="guards-print-every-identity-and-refuse-on-a-mismatch">3. Guards: print every identity and refuse on a mismatch</h3>
<p>The activation script ends by printing each identity, and <strong>aborts and rolls back</strong> if any of them matches a pattern you never want active here, such as your employer’s domain. The patterns live in a local, never-committed file, so the script itself stays generic.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb6-1"><span class="va" style="color: #111111;">login</span><span class="op" style="color: #5E5E5E;">=</span><span class="st" style="color: #20794D;">"</span><span class="va" style="color: #111111;">$(</span><span class="ex" style="color: null;">gh</span> api user <span class="at" style="color: #657422;">--jq</span> .login<span class="va" style="color: #111111;">)</span><span class="st" style="color: #20794D;">"</span></span>
<span id="cb6-2"><span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> <span class="bu" style="color: null;">printf</span> <span class="st" style="color: #20794D;">'%s'</span> <span class="st" style="color: #20794D;">"</span><span class="va" style="color: #111111;">$login</span><span class="st" style="color: #20794D;">"</span> <span class="kw" style="color: #003B4F;
font-weight: bold;">|</span> <span class="fu" style="color: #4758AB;">grep</span> <span class="at" style="color: #657422;">-Eiq</span> <span class="st" style="color: #20794D;">"</span><span class="va" style="color: #111111;">$BLOCKED</span><span class="st" style="color: #20794D;">"</span><span class="kw" style="color: #003B4F;
font-weight: bold;">;</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">then</span></span>
<span id="cb6-3">  <span class="bu" style="color: null;">echo</span> <span class="st" style="color: #20794D;">"✗ gh is logged in as </span><span class="va" style="color: #111111;">$login</span><span class="st" style="color: #20794D;">, aborting"</span><span class="kw" style="color: #003B4F;
font-weight: bold;">;</span> <span class="ex" style="color: null;">deactivate</span><span class="kw" style="color: #003B4F;
font-weight: bold;">;</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">return</span> <span class="dv" style="color: #AD0000;">1</span></span>
<span id="cb6-4"><span class="cf" style="color: #003B4F;
font-weight: bold;">fi</span></span>
<span id="cb6-5"><span class="bu" style="color: null;">echo</span> <span class="st" style="color: #20794D;">"✓ gh: </span><span class="va" style="color: #111111;">$login</span><span class="st" style="color: #20794D;">"</span></span></code></pre></div></div>
</section>
<section id="no-global-installs-pin-the-registry" class="level3">
<h3 class="anchored" data-anchor-id="no-global-installs-pin-the-registry">4. No global installs; pin the registry</h3>
<p>Tools go into the project as <code>devDependencies</code>, and a project <code>.npmrc</code> pins <code>registry=https://registry.npmjs.org/</code>. Nothing from another context (a corporate mirror in <code>~/.npmrc</code>, or a globally installed CLI at a different version) can leak in.</p>
</section>
<section id="gui-apps-dont-read-your-shell" class="level3">
<h3 class="anchored" data-anchor-id="gui-apps-dont-read-your-shell">5. GUI apps don’t read your shell</h3>
<p>Desktop apps and IDE extensions usually <strong>don’t</strong> source <code>activate.sh</code>. For those, use the tool’s own project-level settings file (for example a local, gitignored settings file that sets the same environment variables). Before any GitHub action, check which account is active again: <code>gh api user --jq .login</code>.</p>
</section>
</section>
<section id="the-r-way" class="level2">
<h2 class="anchored" data-anchor-id="the-r-way">The R way</h2>
<p>R already has most of these ideas, spread across a few tools you probably use.</p>
<section id="projects-are-the-folder-scope" class="level3">
<h3 class="anchored" data-anchor-id="projects-are-the-folder-scope">Projects are the “folder scope”</h3>
<p>An RStudio project (<code>.Rproj</code>) or a Positron folder sets the <strong>working directory</strong> when it opens. R then reads a <code>.Renviron</code> from that directory at startup, so it works as a per-project set of environment variables:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb7-1"><span class="co" style="color: #5E5E5E;"># my-project/.Renviron (gitignored)</span></span>
<span id="cb7-2"><span class="va" style="color: #111111;">GITHUB_PAT_GITHUB_COM</span><span class="op" style="color: #5E5E5E;">=</span>ghp_...          <span class="co" style="color: #5E5E5E;"># the token for THIS project's account</span></span>
<span id="cb7-3"><span class="va" style="color: #111111;">R_CONFIG_ACTIVE</span><span class="op" style="color: #5E5E5E;">=</span>dev</span></code></pre></div></div>
<div class="callout callout-style-default callout-warning callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Warning</span>Gotcha: a project <code>.Renviron</code> <em>replaces</em> your personal one
</div>
</div>
<div class="callout-body-container callout-body">
<p>R reads the <strong>first</strong> <code>.Renviron</code> it finds: the one in the working directory, <em>otherwise</em> <code>~/.Renviron</code>. It does not merge them. We checked this with two files: the variables from <code>~/.Renviron</code> disappeared once a project <code>.Renviron</code> existed. If your project needs something from your personal file, copy it across deliberately.</p>
</div>
</div>
<p><code>usethis</code> writes the right file for the right scope:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r norun code-with-copy"><code class="sourceCode r"><span id="cb8-1">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">edit_r_environ</span>(<span class="at" style="color: #657422;">scope =</span> <span class="st" style="color: #20794D;">"project"</span>)   <span class="co" style="color: #5E5E5E;"># opens my-project/.Renviron</span></span>
<span id="cb8-2">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">edit_r_environ</span>(<span class="at" style="color: #657422;">scope =</span> <span class="st" style="color: #20794D;">"user"</span>)      <span class="co" style="color: #5E5E5E;"># opens ~/.Renviron</span></span></code></pre></div></div>
</section>
<section id="which-github-account-does-r-act-as" class="level3">
<h3 class="anchored" data-anchor-id="which-github-account-does-r-act-as">Which GitHub account does R act as?</h3>
<p><code>gh::gh()</code> and <code>usethis</code> find a GitHub token in this order. We checked this with <code>gh</code> 1.4.1:</p>
<ol type="1">
<li><code>GITHUB_PAT_GITHUB_COM</code> (host-specific, the most precise)</li>
<li><code>GITHUB_PAT</code></li>
<li>the <strong>git credential helper</strong>, via <code>gitcreds</code></li>
</ol>
<p>A host-specific PAT in the project <code>.Renviron</code> therefore beats whatever token is saved in your keychain. It’s the R equivalent of <code>GH_CONFIG_DIR</code>.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">gh<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">gh_whoami</span>()          <span class="co" style="color: #5E5E5E;"># which account R is acting as, and the token's scopes</span></span></code></pre></div></div>
</section>
<section id="git-identity-per-repo-with-usethis" class="level3">
<h3 class="anchored" data-anchor-id="git-identity-per-repo-with-usethis">Git identity per repo with <code>usethis</code></h3>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r norun code-with-copy"><code class="sourceCode r"><span id="cb10-1">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">use_git_config</span>(</span>
<span id="cb10-2">  <span class="at" style="color: #657422;">scope =</span> <span class="st" style="color: #20794D;">"project"</span>,</span>
<span id="cb10-3">  <span class="at" style="color: #657422;">user.name  =</span> <span class="st" style="color: #20794D;">"Your Name"</span>,</span>
<span id="cb10-4">  <span class="at" style="color: #657422;">user.email =</span> <span class="st" style="color: #20794D;">"12345+acme-bot@users.noreply.github.com"</span></span>
<span id="cb10-5">)</span></code></pre></div></div>
<p>This writes to <em>that repo’s</em> <code>.git/config</code>, so it’s per repo, not per folder. It’s fine for one repo, but it’s easy to forget on the next clone. The <code>includeIf</code> block covers every repo under the workspace automatically, including commits made from the <strong>RStudio or Positron Git pane</strong>, because both IDEs call your system <code>git</code>.</p>
</section>
<section id="the-situation-report-is-your-guard" class="level3">
<h3 class="anchored" data-anchor-id="the-situation-report-is-your-guard">The situation report is your guard</h3>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">git_sitrep</span>()    <span class="co" style="color: #5E5E5E;"># git user, signing, default branch, GitHub user and token</span></span></code></pre></div></div>
<p><code>git_sitrep()</code> prints the same identities an <code>activate.sh</code> checks. <a href="https://insightsurge-dev.web.app/posts/identity-isolation/scripts/identity-check.R">scripts/identity-check.R</a> wraps it in a hard stop you can put at the top of a deployment script (save the companion file in your project as <code>R/identity-check.R</code>):</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r norun code-with-copy"><code class="sourceCode r"><span id="cb12-1"><span class="fu" style="color: #4758AB;">source</span>(<span class="st" style="color: #20794D;">"R/identity-check.R"</span>)</span>
<span id="cb12-2"><span class="fu" style="color: #4758AB;">assert_identity</span>(</span>
<span id="cb12-3">  <span class="at" style="color: #657422;">expected_email_pattern =</span> <span class="st" style="color: #20794D;">"noreply</span><span class="sc" style="color: #5E5E5E;">\\</span><span class="st" style="color: #20794D;">.github</span><span class="sc" style="color: #5E5E5E;">\\</span><span class="st" style="color: #20794D;">.com$"</span>,</span>
<span id="cb12-4">  <span class="at" style="color: #657422;">blocked_pattern        =</span> <span class="st" style="color: #20794D;">"@example-employer</span><span class="sc" style="color: #5E5E5E;">\\</span><span class="st" style="color: #20794D;">.com$"</span></span>
<span id="cb12-5">)</span></code></pre></div></div>
</section>
<section id="renv-isolates-packages-not-people" class="level3">
<h3 class="anchored" data-anchor-id="renv-isolates-packages-not-people"><code>renv</code> isolates packages, not people</h3>
<p><code>renv</code> gives each project its own library and a lockfile, just as <code>node_modules</code> and <code>package-lock.json</code> do. That’s <strong>dependency</strong> isolation, a separate question from <strong>identity</strong> isolation, and you need both. <code>renv.lock</code> also records the R version, much as <code>.nvmrc</code> pins the Node version.</p>
</section>
</section>
<section id="side-by-side" class="level2">
<h2 class="anchored" data-anchor-id="side-by-side">Side by side</h2>
<div class="table-responsive">
<table class="caption-top table">
<colgroup>
<col style="width: 33%">
<col style="width: 33%">
<col style="width: 33%">
</colgroup>
<thead>
<tr class="header">
<th>Concern</th>
<th>Web-repo way</th>
<th>R way</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Folder scope</td>
<td><code>includeIf "gitdir/i:…"</code></td>
<td>RStudio/Positron project + project <code>.Renviron</code></td>
</tr>
<tr class="even">
<td>Git author</td>
<td>workspace <code>.gitconfig-*</code></td>
<td><code>usethis::use_git_config(scope = "project")</code></td>
</tr>
<tr class="odd">
<td>GitHub account for tools</td>
<td><code>GH_CONFIG_DIR</code></td>
<td><code>GITHUB_PAT_GITHUB_COM</code> in project <code>.Renviron</code></td>
</tr>
<tr class="even">
<td>Verify before acting</td>
<td><code>activate.sh</code> guards, <code>gh api user</code></td>
<td><code>usethis::git_sitrep()</code>, <code>gh::gh_whoami()</code></td>
</tr>
<tr class="odd">
<td>Commit signing</td>
<td>SSH signing (<code>gpg.format=ssh</code>)</td>
<td>Same git setting; the IDE Git pane uses it</td>
</tr>
<tr class="even">
<td>Dependencies</td>
<td><code>devDependencies</code>, <code>package-lock.json</code>, <code>.nvmrc</code></td>
<td><code>renv</code> library, <code>renv.lock</code></td>
</tr>
<tr class="odd">
<td>Registry</td>
<td>project <code>.npmrc</code></td>
<td><code>options(repos = …)</code> in project <code>.Rprofile</code>, or via <code>renv</code></td>
</tr>
</tbody>
</table>
</div>
</section>
<section id="pitfalls-we-hit" class="level2">
<h2 class="anchored" data-anchor-id="pitfalls-we-hit">Pitfalls we hit</h2>
<ul>
<li><strong><code>includeIf</code> only applies once the folder is a git repo.</strong> Before <code>git init</code>, <code>git config user.email</code> still shows your global identity. Check again straight after init.</li>
<li><strong>Desktop apps ignore your shell.</strong> An IDE or desktop agent launched from the Dock never sources <code>activate.sh</code>. Configure the same variables in the tool’s project settings.</li>
<li><strong>A project <code>.Renviron</code> hides <code>~/.Renviron</code></strong> (see the callout above).</li>
<li><strong>Tools can refuse your runtime.</strong> One CLI refused to install on a newer Node than it supports. Pin the runtime per project (<code>.nvmrc</code>, or <code>renv.lock</code>’s R version) instead of upgrading or downgrading the whole machine.</li>
<li><strong>The blocked-pattern file is sensitive.</strong> It names the identities you’re guarding against. Keep it local and never commit it.</li>
</ul>
</section>
<section id="companion-code" class="level2">
<h2 class="anchored" data-anchor-id="companion-code">Companion code</h2>
<p><a href="https://insightsurge-dev.web.app/posts/identity-isolation/scripts/identity-check.R">View <code>identity-check.R</code></a> · <a href="https://insightsurge-dev.web.app/posts/identity-isolation/scripts/identity-check.R" download="identity-check.R">Download</a></p>
<p>Defines <code>assert_identity()</code> to stop execution if git <code>user.email</code> or the active GitHub account does not match expected patterns or matches a blocked identity. Uses base R and optionally calls <code>{gh}</code>.</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-2-contents" aria-controls="callout-2" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Full script: <code>identity-check.R</code>
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-2" class="callout-2-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><span class="co" style="color: #5E5E5E;"># Identity guard for R projects.</span></span>
<span id="cb13-2"><span class="co" style="color: #5E5E5E;"># Stops with an error if the git author or GitHub account in use is not the</span></span>
<span id="cb13-3"><span class="co" style="color: #5E5E5E;"># one this project expects. Source it at the top of any script that commits,</span></span>
<span id="cb13-4"><span class="co" style="color: #5E5E5E;"># pushes, publishes or deploys.</span></span>
<span id="cb13-5"><span class="co" style="color: #5E5E5E;">#</span></span>
<span id="cb13-6"><span class="co" style="color: #5E5E5E;"># nolint start: commented_code_linter. Usage example.</span></span>
<span id="cb13-7"><span class="co" style="color: #5E5E5E;">#   source("R/identity-check.R")</span></span>
<span id="cb13-8"><span class="co" style="color: #5E5E5E;">#   assert_identity(</span></span>
<span id="cb13-9"><span class="co" style="color: #5E5E5E;">#     expected_email_pattern = "noreply\\.github\\.com$",</span></span>
<span id="cb13-10"><span class="co" style="color: #5E5E5E;">#     blocked_pattern        = "@example-employer\\.com$",</span></span>
<span id="cb13-11"><span class="co" style="color: #5E5E5E;">#     expected_github_login  = "my-company-bot"      # optional</span></span>
<span id="cb13-12"><span class="co" style="color: #5E5E5E;">#   )</span></span>
<span id="cb13-13"><span class="co" style="color: #5E5E5E;"># nolint end</span></span>
<span id="cb13-14"></span>
<span id="cb13-15">git_value <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">function</span>(key) {</span>
<span id="cb13-16">  out <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">suppressWarnings</span>(</span>
<span id="cb13-17">    <span class="fu" style="color: #4758AB;">system2</span>(<span class="st" style="color: #20794D;">"git"</span>, <span class="fu" style="color: #4758AB;">c</span>(<span class="st" style="color: #20794D;">"config"</span>, <span class="st" style="color: #20794D;">"--get"</span>, key), <span class="at" style="color: #657422;">stdout =</span> <span class="cn" style="color: #8f5902;">TRUE</span>, <span class="at" style="color: #657422;">stderr =</span> <span class="cn" style="color: #8f5902;">FALSE</span>)</span>
<span id="cb13-18">  )</span>
<span id="cb13-19">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">length</span>(out) <span class="sc" style="color: #5E5E5E;">==</span> <span class="dv" style="color: #AD0000;">0</span>) <span class="cn" style="color: #8f5902;">NA_character_</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> out[[<span class="dv" style="color: #AD0000;">1</span>]]</span>
<span id="cb13-20">}</span>
<span id="cb13-21"></span>
<span id="cb13-22">github_login <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">function</span>() {</span>
<span id="cb13-23">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="sc" style="color: #5E5E5E;">!</span><span class="fu" style="color: #4758AB;">requireNamespace</span>(<span class="st" style="color: #20794D;">"gh"</span>, <span class="at" style="color: #657422;">quietly =</span> <span class="cn" style="color: #8f5902;">TRUE</span>)) {</span>
<span id="cb13-24">    <span class="fu" style="color: #4758AB;">return</span>(<span class="cn" style="color: #8f5902;">NA_character_</span>)</span>
<span id="cb13-25">  }</span>
<span id="cb13-26">  <span class="co" style="color: #5E5E5E;"># gh_whoami() returns NULL (with a message) when no token is found.</span></span>
<span id="cb13-27">  who <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">tryCatch</span>(<span class="fu" style="color: #4758AB;">suppressMessages</span>(gh<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">gh_whoami</span>()), <span class="at" style="color: #657422;">error =</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">function</span>(e) <span class="cn" style="color: #8f5902;">NULL</span>)</span>
<span id="cb13-28">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">is.null</span>(who<span class="sc" style="color: #5E5E5E;">$</span>login)) <span class="cn" style="color: #8f5902;">NA_character_</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> who<span class="sc" style="color: #5E5E5E;">$</span>login</span>
<span id="cb13-29">}</span>
<span id="cb13-30"></span>
<span id="cb13-31">assert_identity <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">function</span>(</span>
<span id="cb13-32">  expected_email_pattern,</span>
<span id="cb13-33">  <span class="at" style="color: #657422;">blocked_pattern =</span> <span class="cn" style="color: #8f5902;">NULL</span>,</span>
<span id="cb13-34">  <span class="at" style="color: #657422;">expected_github_login =</span> <span class="cn" style="color: #8f5902;">NULL</span></span>
<span id="cb13-35">) {</span>
<span id="cb13-36">  email <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">git_value</span>(<span class="st" style="color: #20794D;">"user.email"</span>)</span>
<span id="cb13-37">  login <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">is.null</span>(expected_github_login)) <span class="cn" style="color: #8f5902;">NA_character_</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> <span class="fu" style="color: #4758AB;">github_login</span>()</span>
<span id="cb13-38">  checked <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">c</span>(email, login)</span>
<span id="cb13-39">  checked <span class="ot" style="color: #003B4F;">&lt;-</span> checked[<span class="sc" style="color: #5E5E5E;">!</span><span class="fu" style="color: #4758AB;">is.na</span>(checked)]</span>
<span id="cb13-40"></span>
<span id="cb13-41">  problems <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">character</span>()</span>
<span id="cb13-42">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">is.na</span>(email)) {</span>
<span id="cb13-43">    problems <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">c</span>(problems, <span class="st" style="color: #20794D;">"git user.email is not set"</span>)</span>
<span id="cb13-44">  } <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="sc" style="color: #5E5E5E;">!</span><span class="fu" style="color: #4758AB;">grepl</span>(expected_email_pattern, email)) {</span>
<span id="cb13-45">    problems <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">c</span>(</span>
<span id="cb13-46">      problems,</span>
<span id="cb13-47">      <span class="fu" style="color: #4758AB;">sprintf</span>(</span>
<span id="cb13-48">        <span class="st" style="color: #20794D;">"git user.email '%s' does not match '%s'"</span>,</span>
<span id="cb13-49">        email,</span>
<span id="cb13-50">        expected_email_pattern</span>
<span id="cb13-51">      )</span>
<span id="cb13-52">    )</span>
<span id="cb13-53">  }</span>
<span id="cb13-54">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (</span>
<span id="cb13-55">    <span class="sc" style="color: #5E5E5E;">!</span><span class="fu" style="color: #4758AB;">is.null</span>(blocked_pattern) <span class="sc" style="color: #5E5E5E;">&amp;&amp;</span></span>
<span id="cb13-56">      <span class="fu" style="color: #4758AB;">any</span>(<span class="fu" style="color: #4758AB;">grepl</span>(blocked_pattern, checked, <span class="at" style="color: #657422;">ignore.case =</span> <span class="cn" style="color: #8f5902;">TRUE</span>))</span>
<span id="cb13-57">  ) {</span>
<span id="cb13-58">    problems <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">c</span>(problems, <span class="st" style="color: #20794D;">"an active identity matches the blocked pattern"</span>)</span>
<span id="cb13-59">  }</span>
<span id="cb13-60">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (</span>
<span id="cb13-61">    <span class="sc" style="color: #5E5E5E;">!</span><span class="fu" style="color: #4758AB;">is.null</span>(expected_github_login) <span class="sc" style="color: #5E5E5E;">&amp;&amp;</span> <span class="sc" style="color: #5E5E5E;">!</span><span class="fu" style="color: #4758AB;">identical</span>(login, expected_github_login)</span>
<span id="cb13-62">  ) {</span>
<span id="cb13-63">    problems <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">c</span>(</span>
<span id="cb13-64">      problems,</span>
<span id="cb13-65">      <span class="fu" style="color: #4758AB;">sprintf</span>(</span>
<span id="cb13-66">        <span class="st" style="color: #20794D;">"GitHub login is '%s', expected '%s'"</span>,</span>
<span id="cb13-67">        login,</span>
<span id="cb13-68">        expected_github_login</span>
<span id="cb13-69">      )</span>
<span id="cb13-70">    )</span>
<span id="cb13-71">  }</span>
<span id="cb13-72"></span>
<span id="cb13-73">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">length</span>(problems) <span class="sc" style="color: #5E5E5E;">&gt;</span> <span class="dv" style="color: #AD0000;">0</span>) {</span>
<span id="cb13-74">    <span class="fu" style="color: #4758AB;">stop</span>(</span>
<span id="cb13-75">      <span class="st" style="color: #20794D;">"Identity check failed:</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">- "</span>,</span>
<span id="cb13-76">      <span class="fu" style="color: #4758AB;">paste</span>(problems, <span class="at" style="color: #657422;">collapse =</span> <span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">- "</span>),</span>
<span id="cb13-77">      <span class="at" style="color: #657422;">call. =</span> <span class="cn" style="color: #8f5902;">FALSE</span></span>
<span id="cb13-78">    )</span>
<span id="cb13-79">  }</span>
<span id="cb13-80">  <span class="fu" style="color: #4758AB;">message</span>(</span>
<span id="cb13-81">    <span class="st" style="color: #20794D;">"✓ git: "</span>,</span>
<span id="cb13-82">    email,</span>
<span id="cb13-83">    <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="sc" style="color: #5E5E5E;">!</span><span class="fu" style="color: #4758AB;">is.na</span>(login)) <span class="fu" style="color: #4758AB;">paste0</span>(<span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">✓ GitHub: "</span>, login) <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> <span class="st" style="color: #20794D;">""</span></span>
<span id="cb13-84">  )</span>
<span id="cb13-85">  <span class="fu" style="color: #4758AB;">invisible</span>(<span class="cn" style="color: #8f5902;">TRUE</span>)</span>
<span id="cb13-86">}</span></code></pre></div></div>
</div>
</div>
</div>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<p><strong>Git and SSH</strong></p>
<ul>
<li><strong>git config (<code>includeIf</code>, <code>credential.helper</code>, <code>url.insteadOf</code>, <code>gpg.format</code>)</strong>: <a href="https://git-scm.com/docs/git-config">git-scm.com/docs/git-config</a></li>
<li><strong><code>ssh-add --apple-use-keychain</code></strong>: <a href="https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent">GitHub Docs: Generating a new SSH key and adding it to the ssh-agent</a></li>
</ul>
<p><strong>CLIs and their config-directory variables</strong></p>
<ul>
<li><strong>GitHub CLI (<code>gh</code>), <code>GH_CONFIG_DIR</code></strong>: <a href="https://cli.github.com/manual/gh_help_environment">cli.github.com/manual</a></li>
<li><strong><code>gh api</code></strong>: <a href="https://cli.github.com/manual/gh_api">cli.github.com/manual/gh_api</a></li>
<li><strong>gcloud CLI, <code>CLOUDSDK_CONFIG</code></strong>: <a href="https://docs.cloud.google.com/sdk/docs/configurations">Google Cloud SDK: Configurations</a></li>
</ul>
<p><strong>R package documentation</strong></p>
<ul>
<li><strong>gh</strong> (R client for the GitHub API; token lookup order): <a href="https://gh.r-lib.org/">gh.r-lib.org</a></li>
<li><strong>usethis</strong>: <a href="https://usethis.r-lib.org/">usethis.r-lib.org</a></li>
<li><strong>renv</strong>: <a href="https://rstudio.github.io/renv/">rstudio.github.io/renv</a></li>
</ul>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-3-contents" aria-controls="callout-3" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Updates
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-3" class="callout-3-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<ul>
<li><strong>2026-09-26:</strong> Removed the end-of-post checklist.</li>
<li><strong>2026-09-26:</strong> Hardened the dedicated SSH key by adding a passphrase via <code>ssh-keygen -p</code> and storing it in the macOS keychain agent using <code>ssh-add --apple-use-keychain</code>. Verified that signed commits continue working automatically once the key is resident in the agent.</li>
<li><strong>2026-09-27:</strong> Added a Sources section.</li>
<li><strong>2026-09-27:</strong> Added a Companion code section with the full script.</li>
</ul>
</div>
</div>
</div>



<div class="site-related">
<div class="site-series-nav">
<p><a href="https://insightsurge-dev.web.app/series/foundations.html" class="site-series-nav__series">Foundations series · part 1 of 16</a></p>
<div class="site-card-grid site-series-nav__links">
<div class="site-card-cell">
<a href="https://insightsurge-dev.web.app/posts/git-workflow/index.html" class="is-card site-related-card site-series-nav__next"><span class="is-card__eyebrow">Next · part 2</span><span class="site-related-card__title">Git workflow: branches, squash-only merges, signed commits</span></a>
</div>
</div>
</div>
<section id="keep-reading" class="level2 unnumbered unlisted no-anchor">
<h2 class="unnumbered unlisted no-anchor" data-anchor-id="keep-reading">Keep reading</h2>
<div class="site-link-list">
<ul>
<li><a href="https://insightsurge-dev.web.app/posts/secrets-management/index.html" class="site-link-row" title="Separate configuration names in version control from secrets stored in vaults and environment variables."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Secrets management</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/keyless-ci-auth-oidc/index.html" class="site-link-row" title="Use OpenID Connect and Google Cloud Workload Identity Federation to authenticate CI pipelines without long-lived JSON keys."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Keyless deploys: let CI prove who it is (OIDC)</span></a></li>
</ul>
</div>
</section>
</div>

</section>

 ]]></description>
  <category>R</category>
  <category>Git</category>
  <category>Security</category>
  <guid>https://insightsurge-dev.web.app/posts/identity-isolation/</guid>
  <pubDate>Fri, 25 Sep 2026 18:30:00 GMT</pubDate>
</item>
<item>
  <title>Issue forms, PR templates, labels &amp; milestones</title>
  <link>https://insightsurge-dev.web.app/posts/issue-forms-pr-templates/</link>
  <description><![CDATA[ 





<!--
  Quarto 1.8.27's title-block.html with three changes: category badges and a
  series link ("Testing series · part 2") sit above the title, as in the brand's
  blog kit; and a post or series page with `trailer: true` shows its trailer beside the title
  (_filters/trailer.lua sets trailer-path; _includes/trailers.html plays it). On a Quarto upgrade, diff this against
  share/formats/html/templates/title-block.html and carry over any changes.
-->



<section id="the-problem" class="level2">
<h2 class="anchored" data-anchor-id="the-problem">The problem</h2>
<p>A typical bug report on an internal R package says “km_plot is broken”. You then spend three messages collecting the R version, the package version, the data shape and what “broken” means. Feature requests arrive with no acceptance criteria, so nobody can say when they’re done. PRs arrive with no tests, no <code>NEWS.md</code> bullet and undocumented arguments.</p>
<p>GitHub can ask for all of this up front. The same structure also gives you <strong>traceability</strong>, which GxP work needs anyway: requirement → issue → PR → test → release.</p>
</section>
<section id="issue-forms-yaml-vs-issue-templates-markdown" class="level2">
<h2 class="anchored" data-anchor-id="issue-forms-yaml-vs-issue-templates-markdown">Issue forms (YAML) vs issue templates (Markdown)</h2>
<p>GitHub has two kinds of issue template in <code>.github/ISSUE_TEMPLATE/</code>:</p>
<div class="table-responsive">
<table class="caption-top table">
<colgroup>
<col style="width: 33%">
<col style="width: 33%">
<col style="width: 33%">
</colgroup>
<thead>
<tr class="header">
<th></th>
<th>Markdown template (<code>*.md</code>)</th>
<th>Issue form (<code>*.yml</code>)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>What the reporter sees</td>
<td>A pre-filled text box they can overwrite</td>
<td>Real form fields: text areas, inputs, dropdowns, checkboxes</td>
</tr>
<tr class="even">
<td>Required fields</td>
<td>No; headings get deleted</td>
<td><strong>Yes</strong>, with <code>validations: required: true</code></td>
</tr>
<tr class="odd">
<td>Code/log fields</td>
<td>Reporter must add backticks</td>
<td><code>render: r</code> formats the field as a code block automatically</td>
</tr>
<tr class="even">
<td>Auto labels</td>
<td>Yes</td>
<td>Yes</td>
</tr>
</tbody>
</table>
</div>
<p><code>usethis::use_tidy_github()</code> creates the <strong>Markdown</strong> kind (<code>issue_template.md</code>). It’s a fine start, but forms are the upgrade: required fields can’t be skipped.</p>
<p>GitHub’s documentation still labels issue forms as <em>public preview</em>. After adding them, open <code>…/issues/new/choose</code> in your repo to check that they render.</p>
</section>
<section id="the-web-repo-way" class="level2">
<h2 class="anchored" data-anchor-id="the-web-repo-way">The web-repo way</h2>
<p>Three small files:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb1-1"><span class="co" style="color: #5E5E5E;"># .github/ISSUE_TEMPLATE/config.yml: force people to pick a form</span></span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;">blank_issues_enabled</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="ch" style="color: #20794D;">false</span></span></code></pre></div></div>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb2-1"><span class="co" style="color: #5E5E5E;"># .github/ISSUE_TEMPLATE/feature.yml (abridged)</span></span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;">name</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Feature request</span></span>
<span id="cb2-3"><span class="fu" style="color: #4758AB;">description</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> A new page, section, capability or standard</span></span>
<span id="cb2-4"><span class="fu" style="color: #4758AB;">labels</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="kw" style="color: #003B4F;
font-weight: bold;">[</span><span class="st" style="color: #20794D;">"type: feature"</span><span class="kw" style="color: #003B4F;
font-weight: bold;">]</span></span>
<span id="cb2-5"><span class="fu" style="color: #4758AB;">body</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb2-6"><span class="at" style="color: #657422;">  </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">type</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> textarea</span></span>
<span id="cb2-7"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">id</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> problem</span></span>
<span id="cb2-8"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">attributes</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="kw" style="color: #003B4F;
font-weight: bold;">{</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">label</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Problem or goal </span><span class="kw" style="color: #003B4F;
font-weight: bold;">}</span></span>
<span id="cb2-9"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">validations</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="kw" style="color: #003B4F;
font-weight: bold;">{</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">required</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="ch" style="color: #20794D;">true</span><span class="at" style="color: #657422;"> </span><span class="kw" style="color: #003B4F;
font-weight: bold;">}</span></span>
<span id="cb2-10"><span class="at" style="color: #657422;">  </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">type</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> textarea</span></span>
<span id="cb2-11"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">id</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> acceptance</span></span>
<span id="cb2-12"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">attributes</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb2-13"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">label</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Acceptance criteria</span></span>
<span id="cb2-14"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">description</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Testable conditions that mean this is done.</span></span>
<span id="cb2-15"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">validations</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="kw" style="color: #003B4F;
font-weight: bold;">{</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">required</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="ch" style="color: #20794D;">true</span><span class="at" style="color: #657422;"> </span><span class="kw" style="color: #003B4F;
font-weight: bold;">}</span></span></code></pre></div></div>
<p>Add a <code>.github/PULL_REQUEST_TEMPLATE.md</code> with <em>What / Why / Closes #… / Checklist</em>, plus a <strong>label taxonomy</strong> and <strong>milestones with exit criteria</strong>:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb3-1"><span class="ex" style="color: null;">gh</span> label create <span class="st" style="color: #20794D;">"type: bug"</span>     <span class="at" style="color: #657422;">--color</span> d73a4a <span class="at" style="color: #657422;">--description</span> <span class="st" style="color: #20794D;">"Something is broken"</span></span>
<span id="cb3-2"><span class="ex" style="color: null;">gh</span> label create <span class="st" style="color: #20794D;">"area: ci"</span>      <span class="at" style="color: #657422;">--color</span> 1d76db <span class="at" style="color: #657422;">--description</span> <span class="st" style="color: #20794D;">"GitHub Actions, hooks, release tooling"</span></span>
<span id="cb3-3"><span class="ex" style="color: null;">gh</span> api repos/OWNER/REPO/milestones <span class="at" style="color: #657422;">-f</span> title=<span class="st" style="color: #20794D;">"M2 Static site"</span> <span class="dt" style="color: #AD0000;">\</span></span>
<span id="cb3-4">  <span class="at" style="color: #657422;">-f</span> description=<span class="st" style="color: #20794D;">"Exit: Lighthouse &gt;= 95; 0 broken links; form returns 400 on invalid input"</span></span></code></pre></div></div>
<p>Prefixed labels (<code>type: …</code>, <code>area: …</code>) group nicely in GitHub’s label picker and in filters (<code>label:"type: bug" label:"area: ci"</code>).</p>
</section>
<section id="the-r-way" class="level2">
<h2 class="anchored" data-anchor-id="the-r-way">The R way</h2>
<p>Drop-in files for R packages and Shiny apps are catalogued in <a href="https://insightsurge-dev.web.app/templates/README.md"><code>templates/README.md</code></a>, including:</p>
<ul>
<li><a href="https://insightsurge-dev.web.app/templates/github/ISSUE_TEMPLATE/config.yml"><code>templates/github/ISSUE_TEMPLATE/config.yml</code></a> to disable blank issues and require forms</li>
<li><a href="https://insightsurge-dev.web.app/templates/github/ISSUE_TEMPLATE/bug.yml"><code>templates/github/ISSUE_TEMPLATE/bug.yml</code></a> for reproducible bug reports</li>
<li><a href="https://insightsurge-dev.web.app/templates/github/ISSUE_TEMPLATE/feature.yml"><code>templates/github/ISSUE_TEMPLATE/feature.yml</code></a> for feature requests with acceptance criteria</li>
<li><a href="https://insightsurge-dev.web.app/templates/github/PULL_REQUEST_TEMPLATE.md"><code>templates/github/PULL_REQUEST_TEMPLATE.md</code></a> for pull request reviews</li>
</ul>
<section id="bug-form-reprex-and-session-info-are-required" class="level3">
<h3 class="anchored" data-anchor-id="bug-form-reprex-and-session-info-are-required">Bug form: reprex and session info are required</h3>
<p>The complete bug form template is provided in <a href="https://insightsurge-dev.web.app/templates/github/ISSUE_TEMPLATE/bug.yml"><code>templates/github/ISSUE_TEMPLATE/bug.yml</code></a>:</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Full template: <code>bug.yml</code>
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb4-1"><span class="fu" style="color: #4758AB;">name</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Bug report</span></span>
<span id="cb4-2"><span class="fu" style="color: #4758AB;">description</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Something in the package or app does not work as documented</span></span>
<span id="cb4-3"><span class="fu" style="color: #4758AB;">labels</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="kw" style="color: #003B4F;
font-weight: bold;">[</span><span class="st" style="color: #20794D;">"type: bug"</span><span class="kw" style="color: #003B4F;
font-weight: bold;">]</span></span>
<span id="cb4-4"><span class="fu" style="color: #4758AB;">body</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-5"><span class="at" style="color: #657422;">  </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">type</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> markdown</span></span>
<span id="cb4-6"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">attributes</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-7"><span class="fu" style="color: #4758AB;">      value</span><span class="kw" style="color: #003B4F;
font-weight: bold;">: </span><span class="ch" style="color: #20794D;">|</span></span>
<span id="cb4-8">        Thanks! Please use **synthetic or public data only**. Never paste real patient or client data.</span>
<span id="cb4-9"><span class="at" style="color: #657422;">  </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">type</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> textarea</span></span>
<span id="cb4-10"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">id</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> what</span></span>
<span id="cb4-11"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">attributes</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-12"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">label</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> What happened, and what did you expect?</span></span>
<span id="cb4-13"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">validations</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-14"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">required</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="ch" style="color: #20794D;">true</span></span>
<span id="cb4-15"><span class="at" style="color: #657422;">  </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">type</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> textarea</span></span>
<span id="cb4-16"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">id</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> reprex</span></span>
<span id="cb4-17"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">attributes</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-18"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">label</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Reproducible example</span></span>
<span id="cb4-19"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">description</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Ideally the output of `reprex::reprex()`. For Shiny apps, the steps to reproduce.</span></span>
<span id="cb4-20"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">render</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> r</span></span>
<span id="cb4-21"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">validations</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-22"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">required</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="ch" style="color: #20794D;">true</span></span>
<span id="cb4-23"><span class="at" style="color: #657422;">  </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">type</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> textarea</span></span>
<span id="cb4-24"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">id</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> session</span></span>
<span id="cb4-25"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">attributes</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-26"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">label</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Session info</span></span>
<span id="cb4-27"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">description</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Output of `sessioninfo::session_info()` (or `sessionInfo()`).</span></span>
<span id="cb4-28"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">render</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> text</span></span>
<span id="cb4-29"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">validations</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-30"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">required</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="ch" style="color: #20794D;">true</span></span>
<span id="cb4-31"><span class="at" style="color: #657422;">  </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">type</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> input</span></span>
<span id="cb4-32"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">id</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> where</span></span>
<span id="cb4-33"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">attributes</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-34"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">label</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Where did you see it?</span></span>
<span id="cb4-35"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">placeholder</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="st" style="color: #20794D;">"local R 4.5.1 / Posit Connect / shinyapps.io / browser + version"</span></span></code></pre></div></div>
</div>
</div>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb5-1"><span class="at" style="color: #657422;">  </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">type</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> textarea</span></span>
<span id="cb5-2"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">id</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> reprex</span></span>
<span id="cb5-3"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">attributes</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb5-4"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">label</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Reproducible example</span></span>
<span id="cb5-5"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">description</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Ideally the output of `reprex::reprex()`. For Shiny apps, the steps to reproduce.</span></span>
<span id="cb5-6"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">render</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> r</span></span>
<span id="cb5-7"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">validations</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="kw" style="color: #003B4F;
font-weight: bold;">{</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">required</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="ch" style="color: #20794D;">true</span><span class="at" style="color: #657422;"> </span><span class="kw" style="color: #003B4F;
font-weight: bold;">}</span></span>
<span id="cb5-8"><span class="at" style="color: #657422;">  </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">type</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> textarea</span></span>
<span id="cb5-9"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">id</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> session</span></span>
<span id="cb5-10"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">attributes</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb5-11"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">label</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Session info</span></span>
<span id="cb5-12"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">description</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Output of `sessioninfo::session_info()` (or `sessionInfo()`).</span></span>
<span id="cb5-13"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">render</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> text</span></span>
<span id="cb5-14"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">validations</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="kw" style="color: #003B4F;
font-weight: bold;">{</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">required</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="ch" style="color: #20794D;">true</span><span class="at" style="color: #657422;"> </span><span class="kw" style="color: #003B4F;
font-weight: bold;">}</span></span></code></pre></div></div>
<p>The form also opens with a reminder to use <strong>synthetic or public data only</strong>. In pharma, that sentence prevents a real incident.</p>
</section>
<section id="feature-form-acceptance-criteria-become-tests" class="level3">
<h3 class="anchored" data-anchor-id="feature-form-acceptance-criteria-become-tests">Feature form: acceptance criteria become tests</h3>
<p>The feature form has a required <strong>Acceptance criteria</strong> field and an optional <strong>Requirement ID</strong> field (for example <code>URS-042</code>). Write the criteria so each one maps to an <code>expect_*()</code> call or a <code>shinytest2</code> snapshot. The issue then traces requirement → test, which is exactly what a validation reviewer asks for.</p>
</section>
<section id="pr-template-the-r-definition-of-done" class="level3">
<h3 class="anchored" data-anchor-id="pr-template-the-r-definition-of-done">PR template: the R definition of done</h3>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode markdown code-with-copy"><code class="sourceCode markdown"><span id="cb6-1"><span class="ss" style="color: #20794D;">- </span><span class="va" style="color: #111111;">[ ]</span> <span class="in" style="color: #5E5E5E;">`devtools::check()`</span> clean (0 errors, 0 warnings, notes explained)</span>
<span id="cb6-2"><span class="ss" style="color: #20794D;">- </span><span class="va" style="color: #111111;">[ ]</span> Tests added or updated (<span class="in" style="color: #5E5E5E;">`testthat`</span> / <span class="in" style="color: #5E5E5E;">`shinytest2`</span>)</span>
<span id="cb6-3"><span class="ss" style="color: #20794D;">- </span><span class="va" style="color: #111111;">[ ]</span> <span class="in" style="color: #5E5E5E;">`devtools::document()`</span> run; roxygen docs updated</span>
<span id="cb6-4"><span class="ss" style="color: #20794D;">- </span><span class="va" style="color: #111111;">[ ]</span> <span class="in" style="color: #5E5E5E;">`NEWS.md`</span> bullet added (user-facing changes only)</span>
<span id="cb6-5"><span class="ss" style="color: #20794D;">- </span><span class="va" style="color: #111111;">[ ]</span> Code styled (<span class="in" style="color: #5E5E5E;">`air format .`</span> or <span class="in" style="color: #5E5E5E;">`styler`</span>) and <span class="in" style="color: #5E5E5E;">`lintr::lint_package()`</span> clean</span>
<span id="cb6-6"><span class="ss" style="color: #20794D;">- </span><span class="va" style="color: #111111;">[ ]</span> No secrets, tokens or real patient/client data in the diff</span></code></pre></div></div>
</section>
<section id="labels-from-r" class="level3">
<h3 class="anchored" data-anchor-id="labels-from-r">Labels from R</h3>
<p><code>usethis</code> can manage labels without leaving R:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r norun code-with-copy"><code class="sourceCode r"><span id="cb7-1">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">use_github_labels</span>(</span>
<span id="cb7-2">  <span class="at" style="color: #657422;">labels =</span> <span class="fu" style="color: #4758AB;">c</span>(<span class="st" style="color: #20794D;">"type: bug"</span>, <span class="st" style="color: #20794D;">"type: feature"</span>, <span class="st" style="color: #20794D;">"area: shiny"</span>, <span class="st" style="color: #20794D;">"area: validation"</span>),</span>
<span id="cb7-3">  <span class="at" style="color: #657422;">colours =</span> <span class="fu" style="color: #4758AB;">c</span>(<span class="st" style="color: #20794D;">"type: bug"</span> <span class="ot" style="color: #003B4F;">=</span> <span class="st" style="color: #20794D;">"d73a4a"</span>, <span class="st" style="color: #20794D;">"type: feature"</span> <span class="ot" style="color: #003B4F;">=</span> <span class="st" style="color: #20794D;">"0e8a16"</span>,</span>
<span id="cb7-4">              <span class="st" style="color: #20794D;">"area: shiny"</span> <span class="ot" style="color: #003B4F;">=</span> <span class="st" style="color: #20794D;">"c5def5"</span>, <span class="st" style="color: #20794D;">"area: validation"</span> <span class="ot" style="color: #003B4F;">=</span> <span class="st" style="color: #20794D;">"5319e7"</span>)</span>
<span id="cb7-5">)</span>
<span id="cb7-6"><span class="co" style="color: #5E5E5E;"># or the tidyverse's standard set:</span></span>
<span id="cb7-7">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">use_tidy_github_labels</span>()</span></code></pre></div></div>
</section>
<section id="keep-.github-out-of-the-package" class="level3">
<h3 class="anchored" data-anchor-id="keep-.github-out-of-the-package">Keep <code>.github/</code> out of the package</h3>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r norun code-with-copy"><code class="sourceCode r"><span id="cb8-1">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">use_build_ignore</span>(<span class="st" style="color: #20794D;">".github"</span>)   <span class="co" style="color: #5E5E5E;"># adds ^\.github$ to .Rbuildignore</span></span></code></pre></div></div>
</section>
</section>
<section id="milestones-releases-with-exit-criteria" class="level2">
<h2 class="anchored" data-anchor-id="milestones-releases-with-exit-criteria">Milestones: releases with exit criteria</h2>
<p>In an R package, a milestone is naturally a <strong>release</strong> (<code>v1.3.0</code>), and its description is the release’s <strong>exit criteria</strong>: which issues, and what checks must pass. Closing the milestone is part of cutting the release (<a href="https://insightsurge-dev.web.app/posts/releases-changelogs/index.html">releases &amp; changelogs</a>). For a Shiny app, a milestone can be a deployment (“UAT build for study X”).</p>
</section>
<section id="pitfalls" class="level2">
<h2 class="anchored" data-anchor-id="pitfalls">Pitfalls</h2>
<ul>
<li><strong>Create labels before forms reference them.</strong> GitHub’s docs don’t say what happens with a missing label, so don’t rely on it. Create the taxonomy first and check that a test issue gets its label.</li>
<li><strong><code>blank_issues_enabled: false</code> doesn’t stop maintainers.</strong> Per GitHub’s docs, users with write access or above still see a “Blank issue (Maintainers only)” option. Only Read/Triage users are limited to the forms. Add <code>contact_links</code> to route questions, for example to Discussions.</li>
<li><strong>Checklists aren’t enforcement.</strong> The PR template reminds; CI enforces (<code>R CMD check</code>, <a href="https://insightsurge-dev.web.app/posts/ci-github-actions/index.html">CI with GitHub Actions</a>). Don’t rely on ticked boxes.</li>
<li><strong>Don’t over-ask.</strong> Every required field is friction. Keep bug forms to what you truly need.</li>
</ul>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<p><strong>GitHub</strong></p>
<ul>
<li><strong>Issue forms syntax (documented as public preview)</strong>: <a href="https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-issue-forms">GitHub Docs: Syntax for issue forms</a></li>
<li><strong>Configuring issue templates (<code>blank_issues_enabled</code>; write-access users still see “Blank issue (Maintainers only)”)</strong>: <a href="https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/configuring-issue-templates-for-your-repository">GitHub Docs: Configuring issue templates for your repository</a></li>
<li><strong>Milestones</strong>: <a href="https://docs.github.com/en/issues/using-labels-and-milestones-to-track-work/about-milestones">GitHub Docs: About milestones</a></li>
<li><strong>Labels</strong>: <a href="https://docs.github.com/en/issues/using-labels-and-milestones-to-track-work/managing-labels">GitHub Docs: Managing labels</a></li>
<li><strong><code>gh label create</code></strong>: <a href="https://cli.github.com/manual/gh_label_create">cli.github.com/manual/gh_label_create</a></li>
</ul>
<p><strong>R package documentation</strong></p>
<ul>
<li><strong>usethis</strong> (<code>use_tidy_github()</code>, <code>use_github_labels()</code>, <code>use_tidy_github_labels()</code>, <code>use_build_ignore()</code>): <a href="https://usethis.r-lib.org/">usethis.r-lib.org</a></li>
<li><strong>reprex</strong>: <a href="https://reprex.tidyverse.org/">reprex.tidyverse.org</a></li>
<li><strong>sessioninfo</strong>: <a href="https://sessioninfo.r-lib.org/">sessioninfo.r-lib.org</a></li>
<li><strong>shinytest2</strong>: <a href="https://rstudio.github.io/shinytest2/">rstudio.github.io/shinytest2</a></li>
</ul>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-2-contents" aria-controls="callout-2" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Updates
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-2" class="callout-2-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<ul>
<li><strong>2026-09-26:</strong> Removed the end-of-post checklist.</li>
<li><strong>2026-09-27:</strong> Added a Sources section.</li>
<li><strong>2026-09-27:</strong> Linked every template file and showed it on the page.</li>
</ul>
</div>
</div>
</div>



<div class="site-related">
<div class="site-series-nav">
<p><a href="https://insightsurge-dev.web.app/series/foundations.html" class="site-series-nav__series">Foundations series · part 8 of 16</a></p>
<div class="site-card-grid site-series-nav__links">
<div class="site-card-cell">
<a href="https://insightsurge-dev.web.app/posts/secrets-management/index.html" class="is-card site-related-card site-series-nav__prev"><span class="is-card__eyebrow">Previous · part 7</span><span class="site-related-card__title">Secrets management</span></a>
</div>
<div class="site-card-cell">
<a href="https://insightsurge-dev.web.app/posts/releases-changelogs/index.html" class="is-card site-related-card site-series-nav__next"><span class="is-card__eyebrow">Next · part 9</span><span class="site-related-card__title">Releases &amp; changelogs</span></a>
</div>
</div>
</div>
<section id="keep-reading" class="level2 unnumbered unlisted no-anchor">
<h2 class="unnumbered unlisted no-anchor" data-anchor-id="keep-reading">Keep reading</h2>
<div class="site-link-list">
<ul>
<li><a href="https://insightsurge-dev.web.app/posts/adrs-and-evidence/index.html" class="site-link-row" title="Record architectural decisions with ADRs and verify technical documentation against upstream evidence."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">ADRs &amp; evidence: record decisions, verify docs</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/introducing-mascot/index.html" class="site-link-row" title="The mascot package is now on CRAN: add mood-driven characters to Shiny apps and Quarto pages, with visible status text, speech bubbles, click menus and reduced-motion support."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">mascot is on CRAN: live, mood-driven mascots for Shiny and Quarto</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/package-dependencies-namespace/index.html" class="site-link-row" title="Declare external packages in DESCRIPTION Imports and Suggests, call functions through pkg::fun() or @importFrom, and guard optional dependencies cleanly."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Dependencies: DESCRIPTION and NAMESPACE</span></a></li>
</ul>
</div>
</section>
</div>

</section>

 ]]></description>
  <category>Git</category>
  <category>R packages</category>
  <category>GxP</category>
  <guid>https://insightsurge-dev.web.app/posts/issue-forms-pr-templates/</guid>
  <pubDate>Fri, 25 Sep 2026 18:30:00 GMT</pubDate>
</item>
<item>
  <title>Keyless deploys: let CI prove who it is (OIDC)</title>
  <link>https://insightsurge-dev.web.app/posts/keyless-ci-auth-oidc/</link>
  <description><![CDATA[ 





<!--
  Quarto 1.8.27's title-block.html with three changes: category badges and a
  series link ("Testing series · part 2") sit above the title, as in the brand's
  blog kit; and a post or series page with `trailer: true` shows its trailer beside the title
  (_filters/trailer.lua sets trailer-path; _includes/trailers.html plays it). On a Quarto upgrade, diff this against
  share/formats/html/templates/title-block.html and carry over any changes.
-->



<section id="the-problem" class="level2">
<h2 class="anchored" data-anchor-id="the-problem">The problem</h2>
<p>Deploying code from CI to cloud providers traditionally begins with a dangerous ritual:</p>
<ol type="1">
<li>Generate a service account in your cloud console.</li>
<li>Download a long-lived credential file (such as a Google Cloud JSON service account key or an AWS access key pair).</li>
<li>Paste that JSON blob into GitHub repository secrets (<code>GCP_SA_KEY</code>).</li>
<li>Hope nobody ever logs it, forks the repo, or compromises an action that reads it.</li>
</ol>
<p>This practice carries severe operational and compliance liabilities:</p>
<ul>
<li><strong>No built-in expiration.</strong> A service account JSON key never expires. If an action dumps environment variables or a malicious dependency exfiltrates the secret, the key remains valid until someone manually notices and revokes it.</li>
<li><strong>Rotation debt.</strong> Rotating keys across multiple repositories is tedious, so teams rarely do it. In GxP environments, static shared keys weaken the audit trail because any system holding the key appears identical in access logs.</li>
<li><strong>Accidental exposure.</strong> A single misplaced <code>echo</code> statement or debugging chunk in an R Markdown or Quarto document can print environment variables into build logs, exposing the entire key (see <a href="https://insightsurge-dev.web.app/posts/secret-scanning/index.html">secret scanning</a>).</li>
</ul>
<p>The solution is to <strong>eliminate static keys entirely</strong>. Instead of storing a secret in GitHub, let GitHub cryptographically prove its identity to the cloud on every single run.</p>
</section>
<section id="the-web-repo-way-workload-identity-federation" class="level2">
<h2 class="anchored" data-anchor-id="the-web-repo-way-workload-identity-federation">The web-repo way: Workload Identity Federation</h2>
<p>Modern cloud architectures use <strong>OpenID Connect (OIDC)</strong> and <strong>Workload Identity Federation (WIF)</strong>.</p>
<section id="how-oidc-authentication-works" class="level3">
<h3 class="anchored" data-anchor-id="how-oidc-authentication-works">How OIDC authentication works</h3>
<ol type="1">
<li>When a workflow job starts, GitHub’s OIDC token service generates a signed, short-lived JSON Web Token (JWT) describing the workflow (the repository, the commit, the branch, and the triggering event).</li>
<li>The GitHub Action sends this token to Google Cloud’s Security Token Service (STS).</li>
<li>Google Cloud validates the token’s cryptographic signature using GitHub’s published signing keys (OIDC discovery/JWKS at the issuer: <code>https://token.actions.githubusercontent.com</code>).</li>
<li>If the token claims match the configured trust rules, Google exchanges the GitHub token for a temporary, short-lived (by default about an hour) Google Cloud access token.</li>
<li>The workflow deploys using that short-lived token. When the job finishes, the token expires automatically.</li>
</ol>
</section>
<section id="configuring-keyless-federation-in-google-cloud" class="level3">
<h3 class="anchored" data-anchor-id="configuring-keyless-federation-in-google-cloud">Configuring keyless federation in Google Cloud</h3>
<p>In Google Cloud, we configure a Workload Identity Pool and an OIDC Provider pinned strictly to the repository:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb1-1"><span class="va" style="color: #111111;">PROJECT_ID</span><span class="op" style="color: #5E5E5E;">=</span>my-project</span>
<span id="cb1-2"><span class="va" style="color: #111111;">PROJECT_NUMBER</span><span class="op" style="color: #5E5E5E;">=</span><span class="va" style="color: #111111;">$(</span><span class="ex" style="color: null;">gcloud</span> projects describe <span class="va" style="color: #111111;">$PROJECT_ID</span> <span class="at" style="color: #657422;">--format</span><span class="op" style="color: #5E5E5E;">=</span><span class="st" style="color: #20794D;">'value(projectNumber)'</span><span class="va" style="color: #111111;">)</span></span>
<span id="cb1-3"><span class="va" style="color: #111111;">SA</span><span class="op" style="color: #5E5E5E;">=</span>gh-deploy@<span class="va" style="color: #111111;">$PROJECT_ID</span>.iam.gserviceaccount.com</span>
<span id="cb1-4"></span>
<span id="cb1-5"><span class="co" style="color: #5E5E5E;"># 1. Create the pool and GitHub OIDC provider</span></span>
<span id="cb1-6"><span class="ex" style="color: null;">gcloud</span> iam workload-identity-pools create github <span class="at" style="color: #657422;">--project</span><span class="op" style="color: #5E5E5E;">=</span><span class="va" style="color: #111111;">$PROJECT_ID</span> <span class="dt" style="color: #AD0000;">\</span></span>
<span id="cb1-7">  <span class="at" style="color: #657422;">--location</span><span class="op" style="color: #5E5E5E;">=</span>global <span class="at" style="color: #657422;">--display-name</span><span class="op" style="color: #5E5E5E;">=</span><span class="st" style="color: #20794D;">"GitHub Actions"</span></span>
<span id="cb1-8"></span>
<span id="cb1-9"><span class="ex" style="color: null;">gcloud</span> iam workload-identity-pools providers create-oidc playbook <span class="at" style="color: #657422;">--project</span><span class="op" style="color: #5E5E5E;">=</span><span class="va" style="color: #111111;">$PROJECT_ID</span> <span class="dt" style="color: #AD0000;">\</span></span>
<span id="cb1-10">  <span class="at" style="color: #657422;">--location</span><span class="op" style="color: #5E5E5E;">=</span>global <span class="at" style="color: #657422;">--workload-identity-pool</span><span class="op" style="color: #5E5E5E;">=</span>github <span class="at" style="color: #657422;">--display-name</span><span class="op" style="color: #5E5E5E;">=</span><span class="st" style="color: #20794D;">"my-site"</span> <span class="dt" style="color: #AD0000;">\</span></span>
<span id="cb1-11">  <span class="at" style="color: #657422;">--issuer-uri</span><span class="op" style="color: #5E5E5E;">=</span><span class="st" style="color: #20794D;">"https://token.actions.githubusercontent.com"</span> <span class="dt" style="color: #AD0000;">\</span></span>
<span id="cb1-12">  <span class="at" style="color: #657422;">--attribute-mapping</span><span class="op" style="color: #5E5E5E;">=</span><span class="st" style="color: #20794D;">"google.subject=assertion.sub,attribute.repository_id=assertion.repository_id,attribute.repository_owner_id=assertion.repository_owner_id"</span> <span class="dt" style="color: #AD0000;">\</span></span>
<span id="cb1-13">  <span class="at" style="color: #657422;">--attribute-condition</span><span class="op" style="color: #5E5E5E;">=</span><span class="st" style="color: #20794D;">"assertion.repository_owner_id=='&lt;OWNER_ID&gt;' &amp;&amp; assertion.repository_id=='&lt;REPO_ID&gt;'"</span></span>
<span id="cb1-14"></span>
<span id="cb1-15"><span class="co" style="color: #5E5E5E;"># 2. Grant minimal IAM roles to a dedicated deployment service account</span></span>
<span id="cb1-16"><span class="ex" style="color: null;">gcloud</span> iam service-accounts create gh-deploy <span class="at" style="color: #657422;">--project</span><span class="op" style="color: #5E5E5E;">=</span><span class="va" style="color: #111111;">$PROJECT_ID</span> <span class="dt" style="color: #AD0000;">\</span></span>
<span id="cb1-17">  <span class="at" style="color: #657422;">--display-name</span><span class="op" style="color: #5E5E5E;">=</span><span class="st" style="color: #20794D;">"GitHub deploy: my-site"</span></span>
<span id="cb1-18"></span>
<span id="cb1-19"><span class="ex" style="color: null;">gcloud</span> projects add-iam-policy-binding <span class="va" style="color: #111111;">$PROJECT_ID</span> <span class="at" style="color: #657422;">--member</span><span class="op" style="color: #5E5E5E;">=</span><span class="st" style="color: #20794D;">"serviceAccount:</span><span class="va" style="color: #111111;">$SA</span><span class="st" style="color: #20794D;">"</span> <span class="dt" style="color: #AD0000;">\</span></span>
<span id="cb1-20">  <span class="at" style="color: #657422;">--role</span><span class="op" style="color: #5E5E5E;">=</span>roles/firebasehosting.admin</span>
<span id="cb1-21"><span class="ex" style="color: null;">gcloud</span> projects add-iam-policy-binding <span class="va" style="color: #111111;">$PROJECT_ID</span> <span class="at" style="color: #657422;">--member</span><span class="op" style="color: #5E5E5E;">=</span><span class="st" style="color: #20794D;">"serviceAccount:</span><span class="va" style="color: #111111;">$SA</span><span class="st" style="color: #20794D;">"</span> <span class="dt" style="color: #AD0000;">\</span></span>
<span id="cb1-22">  <span class="at" style="color: #657422;">--role</span><span class="op" style="color: #5E5E5E;">=</span>roles/serviceusage.apiKeysViewer</span>
<span id="cb1-23"></span>
<span id="cb1-24"><span class="co" style="color: #5E5E5E;"># 3. Allow workflows matching our repository ID to impersonate the service account</span></span>
<span id="cb1-25"><span class="ex" style="color: null;">gcloud</span> iam service-accounts add-iam-policy-binding <span class="va" style="color: #111111;">$SA</span> <span class="at" style="color: #657422;">--project</span><span class="op" style="color: #5E5E5E;">=</span><span class="va" style="color: #111111;">$PROJECT_ID</span> <span class="dt" style="color: #AD0000;">\</span></span>
<span id="cb1-26">  <span class="at" style="color: #657422;">--role</span><span class="op" style="color: #5E5E5E;">=</span>roles/iam.workloadIdentityUser <span class="dt" style="color: #AD0000;">\</span></span>
<span id="cb1-27">  <span class="at" style="color: #657422;">--member</span><span class="op" style="color: #5E5E5E;">=</span><span class="st" style="color: #20794D;">"principalSet://iam.googleapis.com/projects/</span><span class="va" style="color: #111111;">$PROJECT_NUMBER</span><span class="st" style="color: #20794D;">/locations/global/workloadIdentityPools/github/attribute.repository_id/&lt;REPO_ID&gt;"</span></span></code></pre></div></div>
<p>Notice the attribute condition:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb2-1"><span class="ex" style="color: null;">assertion.repository_owner_id</span> == <span class="st" style="color: #20794D;">'&lt;OWNER_ID&gt;'</span> <span class="kw" style="color: #003B4F;
font-weight: bold;">&amp;&amp;</span> <span class="ex" style="color: null;">assertion.repository_id</span> == <span class="st" style="color: #20794D;">'&lt;REPO_ID&gt;'</span></span></code></pre></div></div>
<p>We pin to GitHub’s <strong>numeric repository and owner IDs</strong> rather than the string repository name. If the repository or organization is later renamed, the identity assertion cannot be hijacked or broken.</p>
</section>
<section id="the-github-actions-workflow" class="level3">
<h3 class="anchored" data-anchor-id="the-github-actions-workflow">The GitHub Actions workflow</h3>
<p>In <code>.github/workflows/quarto.yml</code>, the job requests an OIDC token by declaring <code>id-token: write</code> permissions, then uses <code>google-github-actions/auth@v3</code>:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb3-1"><span class="fu" style="color: #4758AB;">permissions</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb3-2"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">contents</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> read</span></span>
<span id="cb3-3"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">id-token</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> write</span><span class="co" style="color: #5E5E5E;">          # Required for requesting the GitHub OIDC JWT</span></span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="fu" style="color: #4758AB;">steps</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb3-6"><span class="at" style="color: #657422;">  </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">uses</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> actions/checkout@v7</span></span>
<span id="cb3-7"></span>
<span id="cb3-8"><span class="at" style="color: #657422;">  </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">name</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Authenticate to Google Cloud (keyless)</span></span>
<span id="cb3-9"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">if</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> env.DEPLOY_ENABLED == 'true'</span></span>
<span id="cb3-10"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">uses</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> google-github-actions/auth@v3</span></span>
<span id="cb3-11"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">with</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb3-12"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">workload_identity_provider</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> ${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER }}</span></span>
<span id="cb3-13"><span class="at" style="color: #657422;">      </span><span class="fu" style="color: #4758AB;">service_account</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> ${{ vars.GCP_SERVICE_ACCOUNT }}</span></span>
<span id="cb3-14"></span>
<span id="cb3-15"><span class="at" style="color: #657422;">  </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">name</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Deploy site</span></span>
<span id="cb3-16"><span class="fu" style="color: #4758AB;">    run</span><span class="kw" style="color: #003B4F;
font-weight: bold;">: </span><span class="ch" style="color: #20794D;">|</span></span>
<span id="cb3-17">      npx --yes "$FIREBASE_TOOLS" deploy --only hosting \</span>
<span id="cb3-18">        --project "${{ vars.FIREBASE_PROJECT_ID }}"</span></code></pre></div></div>
</section>
<section id="variables-not-secrets" class="level3">
<h3 class="anchored" data-anchor-id="variables-not-secrets">Variables, not secrets</h3>
<p>Notice the workflow syntax: <code>${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER }}</code>.</p>
<p>Because Workload Identity Federation uses cryptographic attestation rather than shared passwords, the provider URI, service account email, and project ID are <strong>public identifiers, not secrets</strong>. They are stored in repository variables, visible in plain text in the repo settings. An attacker who copies those values cannot authenticate from their own machine or from another repository because Google STS verifies that the requesting JWT originates from our specific GitHub repository ID.</p>
</section>
<section id="why-not-firebases-official-github-action" class="level3">
<h3 class="anchored" data-anchor-id="why-not-firebases-official-github-action">Why not Firebase’s official GitHub Action?</h3>
<p>The official Firebase deployment action (<code>FirebaseExtended/action-hosting-deploy</code>) requires users to paste a service account JSON key into GitHub Secrets (<code>FIREBASE_SERVICE_ACCOUNT_...</code>).</p>
<p>Our secrets standard forbids JSON keys (see <a href="https://insightsurge-dev.web.app/posts/secrets-management/index.html">secrets management</a>). Instead, we authenticate keylessly via <code>google-github-actions/auth@v3</code>, which writes a short-lived <strong>credential configuration</strong> file (external account, no private key) and points <code>GOOGLE_APPLICATION_CREDENTIALS</code> at it. We then invoke <code>firebase-tools</code> directly using <code>npx</code>. The Firebase CLI automatically picks up the temporary credentials.</p>
</section>
</section>
<section id="the-r-way-an-analogy-for-r-developers" class="level2">
<h2 class="anchored" data-anchor-id="the-r-way-an-analogy-for-r-developers">The R way: an analogy for R developers</h2>
<p>For developers accustomed to R and Shiny, OIDC authentication is the difference between writing your database password into a <code>.Renviron</code> file versus authenticating through your organisation’s Single Sign-On (SSO) system.</p>
<ul>
<li><strong>The static key approach:</strong> Copying a static API token into <code>.Renviron</code> or <code>.Renviron.site</code>. If that laptop or server is compromised, the token remains valid indefinitely.</li>
<li><strong>The OIDC approach:</strong> When you log into an enterprise RStudio Server or Posit Workbench instance via SAML/OIDC, the identity provider checks your credentials, confirms your group memberships, and issues a temporary session token. No service password is typed into R, and access revokes automatically when the session closes.</li>
</ul>
<section id="cloud-and-platform-support" class="level3">
<h3 class="anchored" data-anchor-id="cloud-and-platform-support">Cloud and platform support</h3>
<p>GitHub provides native OIDC token generation for the three major cloud providers: - <strong>Google Cloud:</strong> Workload Identity Federation (used here). - <strong>Amazon Web Services (AWS):</strong> IAM OpenID Connect identity providers and role assumption (<code>aws-actions/configure-aws-credentials</code>). - <strong>Microsoft Azure:</strong> Azure AD / Entra ID federated credentials (<code>azure/login</code>).</p>
</section>
<section id="what-about-posit-connect-and-shinyapps.io" class="level3">
<h3 class="anchored" data-anchor-id="what-about-posit-connect-and-shinyapps.io">What about Posit Connect and shinyapps.io?</h3>
<p>When deploying Shiny applications or Quarto reports to hosting platforms: - <strong>Cloud-native targets:</strong> Targets you reach through a cloud’s own IAM (e.g.&nbsp;deploying to Cloud Run) can use the same keyless pattern. - <strong>Dedicated hosting platforms:</strong> Posit Connect and shinyapps.io commonly authenticate deploys with API keys; check your platform’s docs for federation support. If federation is unavailable, follow strict secret discipline (see <a href="https://insightsurge-dev.web.app/posts/secrets-management/index.html">secrets management</a>): create a scoped, minimally privileged API key, store it in GitHub Secrets, and implement a regular rotation schedule.</p>
</section>
</section>
<section id="pitfalls-we-hit" class="level2">
<h2 class="anchored" data-anchor-id="pitfalls-we-hit">Pitfalls we hit</h2>
<ul>
<li><strong>Missing <code>id-token: write</code> permission.</strong> If your GitHub Actions workflow omits <code>permissions: id-token: write</code>, GitHub will not provide a token. The auth step fails because no OIDC token is available.</li>
<li><strong>Pinning repository names instead of IDs.</strong> Trusting <code>assertion.repository == "org/repo"</code> is vulnerable if a repository is renamed or an account is transferred. Always pin <code>assertion.repository_id</code> using the immutable numeric identifier.</li>
<li><strong>Over-privileged service accounts.</strong> Assigning <code>roles/owner</code> or <code>roles/editor</code> to the CI service account breaks the principle of least privilege. Our service account receives only <code>roles/firebasehosting.admin</code> and <code>roles/serviceusage.apiKeysViewer</code>.</li>
<li><strong>Assuming third-party actions support keyless auth.</strong> Many legacy GitHub Actions still expect a static token or JSON secret. Check action documentation before adopting it; running the underlying CLI tool directly via <code>npx</code> or shell scripts is often cleaner.</li>
</ul>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Updates
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<ul>
<li><strong>2026-09-26:</strong> Removed the end-of-post checklist.</li>
</ul>
</div>
</div>
</div>



</section>
<div class="site-related">
<section id="also-in" class="level2 unnumbered unlisted no-anchor">
<h2 class="unnumbered unlisted no-anchor" data-anchor-id="also-in">Also in</h2>
<div class="site-link-list">
<ul>
<li><a href="https://insightsurge-dev.web.app/series/foundations.html" class="site-link-row" title="Build the everyday practices around R code: safe identities, version control, CI, releases, dependencies and decisions. Each part connects a web-repo practice to work in an R package or Shiny app."><span class="is-card__eyebrow site-link-row__label">Series · 16 parts</span><span class="site-link-row__title">Foundations series</span></a></li>
</ul>
</div>
</section>
<section id="keep-reading" class="level2 unnumbered unlisted no-anchor">
<h2 class="unnumbered unlisted no-anchor" data-anchor-id="keep-reading">Keep reading</h2>
<div class="site-link-list">
<ul>
<li><a href="https://insightsurge-dev.web.app/posts/secrets-management/index.html" class="site-link-row" title="Separate configuration names in version control from secrets stored in vaults and environment variables."><span class="is-card__eyebrow site-link-row__label">Read first</span><span class="site-link-row__title">Secrets management</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/ci-github-actions/index.html" class="site-link-row" title="Run R CMD check, tests, and link validation automatically on clean GitHub Actions runners with pinned dependencies."><span class="is-card__eyebrow site-link-row__label">Builds on</span><span class="site-link-row__title">CI with GitHub Actions</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/quarto-firebase-previews/index.html" class="site-link-row" title="Deploy temporary Firebase Hosting preview channels on every pull request to review rendered Quarto sites before merging."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Deploy a Quarto site with a preview for every pull request</span></a></li>
</ul>
</div>
</section>
</div>


 ]]></description>
  <category>Security</category>
  <category>CI/CD</category>
  <category>Best practices</category>
  <guid>https://insightsurge-dev.web.app/posts/keyless-ci-auth-oidc/</guid>
  <pubDate>Fri, 25 Sep 2026 18:30:00 GMT</pubDate>
</item>
<item>
  <title>Catch broken links before your readers do</title>
  <link>https://insightsurge-dev.web.app/posts/link-checking-rendered-sites/</link>
  <description><![CDATA[ 





<!--
  Quarto 1.8.27's title-block.html with three changes: category badges and a
  series link ("Testing series · part 2") sit above the title, as in the brand's
  blog kit; and a post or series page with `trailer: true` shows its trailer beside the title
  (_filters/trailer.lua sets trailer-path; _includes/trailers.html plays it). On a Quarto upgrade, diff this against
  share/formats/html/templates/title-block.html and carry over any changes.
-->



<section id="the-problem" class="level2">
<h2 class="anchored" data-anchor-id="the-problem">The problem</h2>
<p>Broken internal links are among the quickest ways to erode reader trust. In technical engineering documentation, clinical study reports, or package reference sites, a link resolving to a 404 page signals sloppy maintenance:</p>
<ul>
<li><strong>Slug and path refactoring.</strong> Renaming a topic from <code>topics/01-isolation/</code> to <code>posts/identity-isolation/</code> instantly breaks every incoming relative link unless every reference is updated.</li>
<li><strong>Markdown vs HTML disconnect.</strong> Authors write <code>[Read more](../foo/index.qmd)</code> or <code>[Read more](../foo/)</code>, assuming the static site generator will figure out the rendered destination. If the target file or anchor does not exist in the output directory, the error is invisible until a human clicks it.</li>
<li><strong>Manual clicking does not scale.</strong> A site with 15 articles, cross-references, navigation menus, and footers easily generates many internal hyperlinks. Nobody can verify them manually on every pull request.</li>
</ul>
<p>To maintain documentation integrity, link verification must be automated as a mandatory, blocking gate in CI (see <a href="https://insightsurge-dev.web.app/posts/test-your-guardrails/index.html">test your guardrails</a>).</p>
</section>
<section id="the-web-repo-way-lychee-in-ci" class="level2">
<h2 class="anchored" data-anchor-id="the-web-repo-way-lychee-in-ci">The web-repo way: lychee in CI</h2>
<p>Modern documentation pipelines use automated link checkers such as <a href="https://github.com/lycheeverse/lychee">lychee</a>, a fast, asynchronous link validator written in Rust.</p>
<section id="the-ci-step" class="level3">
<h3 class="anchored" data-anchor-id="the-ci-step">The CI step</h3>
<p>In <code>.github/workflows/quarto.yml</code>, link checking executes immediately after the site renders to <code>_site/</code> and before any deployment step can run:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb1-1"><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">name</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Check internal links</span></span>
<span id="cb1-2"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">uses</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> lycheeverse/lychee-action@v2</span></span>
<span id="cb1-3"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">with</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-4"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">args</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> --offline --no-progress --root-dir "${{ github.workspace }}/_site" '_site/**/*.html'</span></span>
<span id="cb1-5"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">fail</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="ch" style="color: #20794D;">true</span></span></code></pre></div></div>
<p>Key arguments in this configuration: - <code>--offline</code>: Instructs lychee to ignore all external HTTP/HTTPS URLs. It checks exclusively local file paths and root-relative links (<code>/posts/...</code>). (Note that lychee does not check <code>#fragments</code> by default unless <code>--include-fragments</code> is supplied, and our local script also ignores fragments.) - <code>--root-dir</code>: Sets the root directory for absolute paths. A link written as <code>/about.html</code> is resolved against <code>${{ github.workspace }}/_site/about.html</code>. - <code>fail: true</code>: Configures the action to return an exit code of 1 if any broken link is found, immediately failing the PR build and preventing deployment.</p>
</section>
<section id="what-we-observed-in-practice" class="level3">
<h3 class="anchored" data-anchor-id="what-we-observed-in-practice">What we observed in practice</h3>
<p>On our initial CI run, lychee scanned <strong>570 internal links</strong> across the rendered HTML files and reported <strong>0 errors</strong>.</p>
<p>Because the scan runs in offline mode, it runs without sending outbound network requests. More importantly, prior to opening the PR, local checking caught an issue with <strong>directory links</strong>: relative paths pointing to a folder that had no <code>index.html</code> at all (for example, a link to this playbook’s GitHub templates folder). The fix was linking directly to a file (<a href="https://insightsurge-dev.web.app/templates/README.md"><code>templates/README.md</code></a> or <a href="https://insightsurge-dev.web.app/templates/agentic/handoff-skill/SKILL.md"><code>SKILL.md</code></a>).</p>
</section>
<section id="mirroring-ci-locally" class="level3">
<h3 class="anchored" data-anchor-id="mirroring-ci-locally">Mirroring CI locally</h3>
<p>In CI, lychee runs inside GitHub Actions. Locally, I mirror its offline check with a small script using base R and <a href="https://xml2.r-lib.org/">{xml2}</a>. It scans the rendered HTML files, extracts <code>href</code> and <code>src</code> attributes, strips fragments and query strings, URL-decodes path segments, and checks that every target exists on disk (requiring folders to contain an <code>index.html</code>):</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r norun code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="co" style="color: #5E5E5E;"># Parse HTML and extract internal links</span></span>
<span id="cb2-2">doc <span class="ot" style="color: #003B4F;">&lt;-</span> xml2<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">read_html</span>(html_file, <span class="at" style="color: #657422;">encoding =</span> <span class="st" style="color: #20794D;">"UTF-8"</span>)</span>
<span id="cb2-3">hrefs <span class="ot" style="color: #003B4F;">&lt;-</span> xml2<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">xml_attr</span>(xml2<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">xml_find_all</span>(doc, <span class="st" style="color: #20794D;">"//*[@href]"</span>), <span class="st" style="color: #20794D;">"href"</span>)</span>
<span id="cb2-4">srcs <span class="ot" style="color: #003B4F;">&lt;-</span> xml2<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">xml_attr</span>(xml2<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">xml_find_all</span>(doc, <span class="st" style="color: #20794D;">"//*[@src]"</span>), <span class="st" style="color: #20794D;">"src"</span>)</span>
<span id="cb2-5"></span>
<span id="cb2-6"><span class="co" style="color: #5E5E5E;"># Skip external protocols, mailto, and anchor fragments</span></span>
<span id="cb2-7">skip_pattern <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="st" style="color: #20794D;">"^(https?:|mailto:|#|data:|javascript:|tel:)"</span></span>
<span id="cb2-8">links <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">c</span>(hrefs, srcs)</span>
<span id="cb2-9">internal_links <span class="ot" style="color: #003B4F;">&lt;-</span> links[<span class="sc" style="color: #5E5E5E;">!</span><span class="fu" style="color: #4758AB;">grepl</span>(skip_pattern, links, <span class="at" style="color: #657422;">ignore.case =</span> <span class="cn" style="color: #8f5902;">TRUE</span>)]</span></code></pre></div></div>
<p>Each internal link is cleaned with <code>sub("[#?].*$", "", link)</code> to drop fragments and query parameters, decoded with <code>utils::URLdecode()</code>, and resolved against either the site root (for root-relative paths starting with <code>/</code>) or the page’s parent directory (for relative paths).</p>
<p>Reading attributes with a parser matters: a regex that searches the raw HTML for <code>href="https://insightsurge-dev.web.app/posts/link-checking-rendered-sites/…"</code> also counts example links shown inside code blocks. On this very page, the full script below builds a small test site whose HTML appears as text, and a regex version of the check reported three of its example links as broken; the parser-based check correctly ignores them.</p>
<p>Running the check locally gives immediate feedback before opening a pull request, without requiring a containerised CI environment. The full standalone implementation is in the companion script (<a href="https://insightsurge-dev.web.app/posts/link-checking-rendered-sites/scripts/check-links.R">scripts/check-links.R</a>).</p>
</section>
</section>
<section id="the-r-way-pkgdown-bookdown-and-quarto" class="level2">
<h2 class="anchored" data-anchor-id="the-r-way-pkgdown-bookdown-and-quarto">The R way: pkgdown, bookdown, and Quarto</h2>
<p>In the R ecosystem, documentation is compiled into static HTML across multiple frameworks: - <strong><code>pkgdown</code>:</strong> Builds package documentation into the <code>docs/</code> directory. - <strong><code>bookdown</code>:</strong> Compiles books or long-form documentation into <code>_book/</code>. - <strong>R Markdown websites (<code>rmarkdown::render_site()</code>):</strong> Renders to <code>_site/</code>. - <strong>Quarto sites and books:</strong> Renders to <code>_site/</code>.</p>
<p>Because lychee and our R checker operate on standard HTML files on disk, they are completely agnostic to the generator that created them. You can add the identical check to any R package repository’s GitHub Actions workflow:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb3-1"><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">name</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Build pkgdown site</span></span>
<span id="cb3-2"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">run</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Rscript -e 'pkgdown::build_site()'</span></span>
<span id="cb3-3"></span>
<span id="cb3-4"><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">name</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Verify package documentation links</span></span>
<span id="cb3-5"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">uses</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> lycheeverse/lychee-action@v2</span></span>
<span id="cb3-6"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">with</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb3-7"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">args</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> --offline --no-progress --root-dir "docs" 'docs/**/*.html'</span></span>
<span id="cb3-8"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">fail</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="ch" style="color: #20794D;">true</span></span></code></pre></div></div>
<p>If a vignette links to a deleted article or page, the CI build fails with the file and the broken URL before the documentation ever deploys.</p>
</section>
<section id="separate-internal-links-from-external-links" class="level2">
<h2 class="anchored" data-anchor-id="separate-internal-links-from-external-links">Separate internal links from external links</h2>
<p>A common mistake is attempting to check external internet links inside the same pull request check.</p>
<p><strong>External link checks should never block a pull request.</strong> External web servers fail for reasons outside your control: - Temporary network timeouts and DNS glitches; - Anti-scraping firewalls returning 403 or 429 status codes; - Third-party endpoints undergoing maintenance.</p>
<p>If your PR gate checks external URLs, your team’s pull requests will randomly turn red due to third-party outages.</p>
<p>The correct architectural pattern is <strong>separation of concerns</strong>: 1. <strong>Internal links:</strong> Checked synchronously in the PR workflow with <code>--offline</code> and <code>fail: true</code>. Internal links must be fully deterministic and blocking. 2. <strong>External links:</strong> Checked asynchronously in a scheduled weekly cron workflow (e.g.&nbsp;<code>schedule: [{cron: "0 9 * * 1"}]</code>). If an external link rots, the workflow opens a GitHub issue or sends an alert without halting daily pull request merges.</p>
</section>
<section id="pitfalls-we-hit" class="level2">
<h2 class="anchored" data-anchor-id="pitfalls-we-hit">Pitfalls we hit</h2>
<ul>
<li><strong>Checking source Markdown instead of rendered HTML.</strong> Markdown files often contain shortcodes, includes, or generated relative links that only resolve after compilation. Checking the raw Markdown produces false positive errors. Always check the rendered output directory (<code>_site</code> or <code>docs</code>).</li>
<li><strong>Linking to directories without an <code>index.html</code>.</strong> A link pointing to a folder that has no <code>index.html</code> file at all (such as a templates folder) fails verification. Always link to a specific target file (e.g.&nbsp;<code>README.md</code> or <code>SKILL.md</code>).</li>
<li><strong>Tip on fragment checking.</strong> By default, lychee’s <code>--offline</code> check and our local script do not validate <code>#fragments</code>. If you want to verify in-page header anchors, pass <code>--include-fragments</code> to lychee (we have not enabled this).</li>
<li><strong>Unescaped characters in file paths.</strong> Query parameters or spaces in file names can cause path resolution to fail unless properly decoded via <code>utils::URLdecode()</code>.</li>
</ul>
</section>
<section id="companion-code" class="level2">
<h2 class="anchored" data-anchor-id="companion-code">Companion code</h2>
<p><a href="https://insightsurge-dev.web.app/posts/link-checking-rendered-sites/scripts/check-links.R">View <code>check-links.R</code></a> · <a href="https://insightsurge-dev.web.app/posts/link-checking-rendered-sites/scripts/check-links.R" download="check-links.R">Download</a></p>
<p>An offline internal link checker using base R and <code>{xml2}</code>. Scans rendered HTML files for <code>href</code> and <code>src</code> attributes, resolves root-relative and relative paths, validates directory targets for <code>index.html</code>, and reports broken references. Run with <code>Rscript check-links.R _site</code> or execute without arguments to run the self-contained demonstration.</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Full script: <code>check-links.R</code>
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="co" style="color: #5E5E5E;"># Offline internal link checker for rendered Quarto, pkgdown, and static HTML sites.</span></span>
<span id="cb4-2"><span class="co" style="color: #5E5E5E;"># Scans HTML files, extracts href and src attributes, resolves root-relative and</span></span>
<span id="cb4-3"><span class="co" style="color: #5E5E5E;"># relative links, and flags missing files or directory links without index.html.</span></span>
<span id="cb4-4"><span class="co" style="color: #5E5E5E;">#</span></span>
<span id="cb4-5"><span class="co" style="color: #5E5E5E;"># Usage:</span></span>
<span id="cb4-6"><span class="co" style="color: #5E5E5E;">#   Rscript check-links.R _site</span></span>
<span id="cb4-7"><span class="co" style="color: #5E5E5E;">#</span></span>
<span id="cb4-8"><span class="co" style="color: #5E5E5E;"># Or run without arguments to execute the built-in demonstration:</span></span>
<span id="cb4-9"><span class="co" style="color: #5E5E5E;">#   Rscript check-links.R</span></span>
<span id="cb4-10"></span>
<span id="cb4-11"><span class="co" style="color: #5E5E5E;">#' Simplify path by resolving '.' and '..' segments</span></span>
<span id="cb4-12"><span class="co" style="color: #5E5E5E;">#'</span></span>
<span id="cb4-13"><span class="co" style="color: #5E5E5E;">#' @param path Character vector of paths to simplify.</span></span>
<span id="cb4-14"><span class="co" style="color: #5E5E5E;">#' @return Simplified path string.</span></span>
<span id="cb4-15"><span class="co" style="color: #5E5E5E;">#' @keywords internal</span></span>
<span id="cb4-16">simplify_path <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">function</span>(path) {</span>
<span id="cb4-17">  is_abs <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">startsWith</span>(path, <span class="st" style="color: #20794D;">"/"</span>)</span>
<span id="cb4-18">  parts <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">strsplit</span>(path, <span class="st" style="color: #20794D;">"/+"</span>)[[<span class="dv" style="color: #AD0000;">1</span>L]]</span>
<span id="cb4-19">  stack <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">character</span>()</span>
<span id="cb4-20">  <span class="cf" style="color: #003B4F;
font-weight: bold;">for</span> (part <span class="cf" style="color: #003B4F;
font-weight: bold;">in</span> parts) {</span>
<span id="cb4-21">    <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (part <span class="sc" style="color: #5E5E5E;">==</span> <span class="st" style="color: #20794D;">""</span> <span class="sc" style="color: #5E5E5E;">||</span> part <span class="sc" style="color: #5E5E5E;">==</span> <span class="st" style="color: #20794D;">"."</span>) {</span>
<span id="cb4-22">      <span class="cf" style="color: #003B4F;
font-weight: bold;">next</span></span>
<span id="cb4-23">    }</span>
<span id="cb4-24">    <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (part <span class="sc" style="color: #5E5E5E;">==</span> <span class="st" style="color: #20794D;">".."</span>) {</span>
<span id="cb4-25">      <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">length</span>(stack) <span class="sc" style="color: #5E5E5E;">&gt;</span> <span class="dv" style="color: #AD0000;">0</span>L <span class="sc" style="color: #5E5E5E;">&amp;&amp;</span> stack[<span class="fu" style="color: #4758AB;">length</span>(stack)] <span class="sc" style="color: #5E5E5E;">!=</span> <span class="st" style="color: #20794D;">".."</span>) {</span>
<span id="cb4-26">        stack <span class="ot" style="color: #003B4F;">&lt;-</span> stack[<span class="sc" style="color: #5E5E5E;">-</span><span class="fu" style="color: #4758AB;">length</span>(stack)]</span>
<span id="cb4-27">      } <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="sc" style="color: #5E5E5E;">!</span>is_abs) {</span>
<span id="cb4-28">        stack <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">c</span>(stack, part)</span>
<span id="cb4-29">      }</span>
<span id="cb4-30">    } <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> {</span>
<span id="cb4-31">      stack <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">c</span>(stack, part)</span>
<span id="cb4-32">    }</span>
<span id="cb4-33">  }</span>
<span id="cb4-34">  res <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">paste</span>(stack, <span class="at" style="color: #657422;">collapse =</span> <span class="st" style="color: #20794D;">"/"</span>)</span>
<span id="cb4-35">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (is_abs) <span class="fu" style="color: #4758AB;">paste0</span>(<span class="st" style="color: #20794D;">"/"</span>, res) <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> res</span>
<span id="cb4-36">}</span>
<span id="cb4-37"></span>
<span id="cb4-38"><span class="co" style="color: #5E5E5E;">#' Scan rendered HTML files for broken internal links</span></span>
<span id="cb4-39"><span class="co" style="color: #5E5E5E;">#'</span></span>
<span id="cb4-40"><span class="co" style="color: #5E5E5E;">#' @param site_dir Root directory of the rendered static site.</span></span>
<span id="cb4-41"><span class="co" style="color: #5E5E5E;">#' @return A list containing `broken` (a data frame of broken links with columns</span></span>
<span id="cb4-42"><span class="co" style="color: #5E5E5E;">#'   `page`, `link`, and `resolved_path`) and `checked` (the total count of</span></span>
<span id="cb4-43"><span class="co" style="color: #5E5E5E;">#'   internal links checked).</span></span>
<span id="cb4-44"><span class="co" style="color: #5E5E5E;">#' @export</span></span>
<span id="cb4-45">check_links <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">function</span>(<span class="at" style="color: #657422;">site_dir =</span> <span class="st" style="color: #20794D;">"_site"</span>) {</span>
<span id="cb4-46">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="sc" style="color: #5E5E5E;">!</span><span class="fu" style="color: #4758AB;">dir.exists</span>(site_dir)) {</span>
<span id="cb4-47">    <span class="fu" style="color: #4758AB;">stop</span>(</span>
<span id="cb4-48">      <span class="fu" style="color: #4758AB;">sprintf</span>(<span class="st" style="color: #20794D;">"Site directory '%s' does not exist."</span>, site_dir),</span>
<span id="cb4-49">      <span class="at" style="color: #657422;">call. =</span> <span class="cn" style="color: #8f5902;">FALSE</span></span>
<span id="cb4-50">    )</span>
<span id="cb4-51">  }</span>
<span id="cb4-52"></span>
<span id="cb4-53">  norm_site_dir <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">normalizePath</span>(site_dir, <span class="at" style="color: #657422;">winslash =</span> <span class="st" style="color: #20794D;">"/"</span>, <span class="at" style="color: #657422;">mustWork =</span> <span class="cn" style="color: #8f5902;">TRUE</span>)</span>
<span id="cb4-54">  html_files <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">list.files</span>(</span>
<span id="cb4-55">    norm_site_dir,</span>
<span id="cb4-56">    <span class="at" style="color: #657422;">pattern =</span> <span class="st" style="color: #20794D;">"</span><span class="sc" style="color: #5E5E5E;">\\</span><span class="st" style="color: #20794D;">.html$"</span>,</span>
<span id="cb4-57">    <span class="at" style="color: #657422;">recursive =</span> <span class="cn" style="color: #8f5902;">TRUE</span>,</span>
<span id="cb4-58">    <span class="at" style="color: #657422;">full.names =</span> <span class="cn" style="color: #8f5902;">TRUE</span></span>
<span id="cb4-59">  )</span>
<span id="cb4-60"></span>
<span id="cb4-61">  bad_pages <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">character</span>()</span>
<span id="cb4-62">  bad_links <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">character</span>()</span>
<span id="cb4-63">  bad_paths <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">character</span>()</span>
<span id="cb4-64">  n_checked <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="dv" style="color: #AD0000;">0</span>L</span>
<span id="cb4-65"></span>
<span id="cb4-66">  <span class="co" style="color: #5E5E5E;"># Skip external protocols, anchor fragments, data URIs, and scripts</span></span>
<span id="cb4-67">  skip_pattern <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="st" style="color: #20794D;">"^(https?:|mailto:|#|data:|javascript:|tel:)"</span></span>
<span id="cb4-68"></span>
<span id="cb4-69">  <span class="cf" style="color: #003B4F;
font-weight: bold;">for</span> (html_file <span class="cf" style="color: #003B4F;
font-weight: bold;">in</span> html_files) {</span>
<span id="cb4-70">    norm_html <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">normalizePath</span>(html_file, <span class="at" style="color: #657422;">winslash =</span> <span class="st" style="color: #20794D;">"/"</span>, <span class="at" style="color: #657422;">mustWork =</span> <span class="cn" style="color: #8f5902;">TRUE</span>)</span>
<span id="cb4-71">    rel_page <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">substring</span>(norm_html, <span class="fu" style="color: #4758AB;">nchar</span>(norm_site_dir) <span class="sc" style="color: #5E5E5E;">+</span> <span class="dv" style="color: #AD0000;">2</span>L)</span>
<span id="cb4-72">    html_dir <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">dirname</span>(norm_html)</span>
<span id="cb4-73"></span>
<span id="cb4-74">    doc <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">tryCatch</span>(</span>
<span id="cb4-75">      xml2<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">read_html</span>(norm_html, <span class="at" style="color: #657422;">encoding =</span> <span class="st" style="color: #20794D;">"UTF-8"</span>),</span>
<span id="cb4-76">      <span class="at" style="color: #657422;">error =</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">function</span>(e) <span class="cn" style="color: #8f5902;">NULL</span></span>
<span id="cb4-77">    )</span>
<span id="cb4-78">    <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">is.null</span>(doc)) {</span>
<span id="cb4-79">      <span class="cf" style="color: #003B4F;
font-weight: bold;">next</span></span>
<span id="cb4-80">    }</span>
<span id="cb4-81"></span>
<span id="cb4-82">    href_nodes <span class="ot" style="color: #003B4F;">&lt;-</span> xml2<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">xml_find_all</span>(doc, <span class="st" style="color: #20794D;">"//*[@href]"</span>)</span>
<span id="cb4-83">    hrefs <span class="ot" style="color: #003B4F;">&lt;-</span> xml2<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">xml_attr</span>(href_nodes, <span class="st" style="color: #20794D;">"href"</span>)</span>
<span id="cb4-84"></span>
<span id="cb4-85">    src_nodes <span class="ot" style="color: #003B4F;">&lt;-</span> xml2<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">xml_find_all</span>(doc, <span class="st" style="color: #20794D;">"//*[@src]"</span>)</span>
<span id="cb4-86">    srcs <span class="ot" style="color: #003B4F;">&lt;-</span> xml2<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">xml_attr</span>(src_nodes, <span class="st" style="color: #20794D;">"src"</span>)</span>
<span id="cb4-87"></span>
<span id="cb4-88">    raw_links <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">c</span>(hrefs, srcs)</span>
<span id="cb4-89">    raw_links <span class="ot" style="color: #003B4F;">&lt;-</span> raw_links[<span class="sc" style="color: #5E5E5E;">!</span><span class="fu" style="color: #4758AB;">is.na</span>(raw_links) <span class="sc" style="color: #5E5E5E;">&amp;</span> <span class="fu" style="color: #4758AB;">nzchar</span>(<span class="fu" style="color: #4758AB;">trimws</span>(raw_links))]</span>
<span id="cb4-90"></span>
<span id="cb4-91">    <span class="cf" style="color: #003B4F;
font-weight: bold;">for</span> (u <span class="cf" style="color: #003B4F;
font-weight: bold;">in</span> raw_links) {</span>
<span id="cb4-92">      u_trim <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">trimws</span>(u)</span>
<span id="cb4-93">      <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">grepl</span>(skip_pattern, u_trim, <span class="at" style="color: #657422;">ignore.case =</span> <span class="cn" style="color: #8f5902;">TRUE</span>)) {</span>
<span id="cb4-94">        <span class="cf" style="color: #003B4F;
font-weight: bold;">next</span></span>
<span id="cb4-95">      }</span>
<span id="cb4-96"></span>
<span id="cb4-97">      <span class="co" style="color: #5E5E5E;"># Drop #fragment and ?query</span></span>
<span id="cb4-98">      clean_u <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">sub</span>(<span class="st" style="color: #20794D;">"[#?].*$"</span>, <span class="st" style="color: #20794D;">""</span>, u_trim)</span>
<span id="cb4-99">      p <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">tryCatch</span>(</span>
<span id="cb4-100">        utils<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">URLdecode</span>(clean_u),</span>
<span id="cb4-101">        <span class="at" style="color: #657422;">error =</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">function</span>(e) clean_u</span>
<span id="cb4-102">      )</span>
<span id="cb4-103"></span>
<span id="cb4-104">      <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="sc" style="color: #5E5E5E;">!</span><span class="fu" style="color: #4758AB;">nzchar</span>(p)) {</span>
<span id="cb4-105">        <span class="cf" style="color: #003B4F;
font-weight: bold;">next</span></span>
<span id="cb4-106">      }</span>
<span id="cb4-107"></span>
<span id="cb4-108">      n_checked <span class="ot" style="color: #003B4F;">&lt;-</span> n_checked <span class="sc" style="color: #5E5E5E;">+</span> <span class="dv" style="color: #AD0000;">1</span>L</span>
<span id="cb4-109"></span>
<span id="cb4-110">      <span class="co" style="color: #5E5E5E;"># Resolve root-relative vs relative path</span></span>
<span id="cb4-111">      <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">startsWith</span>(p, <span class="st" style="color: #20794D;">"/"</span>)) {</span>
<span id="cb4-112">        rel_p <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">sub</span>(<span class="st" style="color: #20794D;">"^/+"</span>, <span class="st" style="color: #20794D;">""</span>, p)</span>
<span id="cb4-113">        target_path <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">file.path</span>(norm_site_dir, rel_p)</span>
<span id="cb4-114">      } <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> {</span>
<span id="cb4-115">        target_path <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">file.path</span>(html_dir, p)</span>
<span id="cb4-116">      }</span>
<span id="cb4-117"></span>
<span id="cb4-118">      norm_target <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">simplify_path</span>(target_path)</span>
<span id="cb4-119"></span>
<span id="cb4-120">      <span class="co" style="color: #5E5E5E;"># Check target existence: a folder link must contain index.html</span></span>
<span id="cb4-121">      is_valid <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">dir.exists</span>(norm_target)) {</span>
<span id="cb4-122">        idx <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">file.path</span>(norm_target, <span class="st" style="color: #20794D;">"index.html"</span>)</span>
<span id="cb4-123">        <span class="fu" style="color: #4758AB;">file.exists</span>(idx) <span class="sc" style="color: #5E5E5E;">&amp;&amp;</span> <span class="sc" style="color: #5E5E5E;">!</span><span class="fu" style="color: #4758AB;">dir.exists</span>(idx)</span>
<span id="cb4-124">      } <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> {</span>
<span id="cb4-125">        <span class="fu" style="color: #4758AB;">file.exists</span>(norm_target)</span>
<span id="cb4-126">      }</span>
<span id="cb4-127"></span>
<span id="cb4-128">      <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="sc" style="color: #5E5E5E;">!</span>is_valid) {</span>
<span id="cb4-129">        bad_pages <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">c</span>(bad_pages, rel_page)</span>
<span id="cb4-130">        bad_links <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">c</span>(bad_links, u)</span>
<span id="cb4-131">        bad_paths <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">c</span>(bad_paths, norm_target)</span>
<span id="cb4-132">      }</span>
<span id="cb4-133">    }</span>
<span id="cb4-134">  }</span>
<span id="cb4-135"></span>
<span id="cb4-136">  broken_df <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">data.frame</span>(</span>
<span id="cb4-137">    <span class="at" style="color: #657422;">page =</span> bad_pages,</span>
<span id="cb4-138">    <span class="at" style="color: #657422;">link =</span> bad_links,</span>
<span id="cb4-139">    <span class="at" style="color: #657422;">resolved_path =</span> bad_paths,</span>
<span id="cb4-140">    <span class="at" style="color: #657422;">stringsAsFactors =</span> <span class="cn" style="color: #8f5902;">FALSE</span></span>
<span id="cb4-141">  )</span>
<span id="cb4-142">  <span class="fu" style="color: #4758AB;">attr</span>(broken_df, <span class="st" style="color: #20794D;">"checked"</span>) <span class="ot" style="color: #003B4F;">&lt;-</span> n_checked</span>
<span id="cb4-143"></span>
<span id="cb4-144">  <span class="fu" style="color: #4758AB;">list</span>(</span>
<span id="cb4-145">    <span class="at" style="color: #657422;">broken =</span> broken_df,</span>
<span id="cb4-146">    <span class="at" style="color: #657422;">checked =</span> n_checked</span>
<span id="cb4-147">  )</span>
<span id="cb4-148">}</span>
<span id="cb4-149"></span>
<span id="cb4-150"><span class="co" style="color: #5E5E5E;">#' Run demonstration on a temporary mock site</span></span>
<span id="cb4-151"><span class="co" style="color: #5E5E5E;">#' @return A list containing `broken` and `checked`.</span></span>
<span id="cb4-152"><span class="co" style="color: #5E5E5E;">#' @export</span></span>
<span id="cb4-153">run_link_demo <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="cf" style="color: #003B4F;
font-weight: bold;">function</span>() {</span>
<span id="cb4-154">  demo_dir <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">file.path</span>(<span class="fu" style="color: #4758AB;">tempdir</span>(), <span class="fu" style="color: #4758AB;">paste0</span>(<span class="st" style="color: #20794D;">"link_demo_"</span>, <span class="fu" style="color: #4758AB;">Sys.getpid</span>()))</span>
<span id="cb4-155">  <span class="fu" style="color: #4758AB;">dir.create</span>(demo_dir, <span class="at" style="color: #657422;">recursive =</span> <span class="cn" style="color: #8f5902;">TRUE</span>, <span class="at" style="color: #657422;">showWarnings =</span> <span class="cn" style="color: #8f5902;">FALSE</span>)</span>
<span id="cb4-156">  <span class="fu" style="color: #4758AB;">on.exit</span>(<span class="fu" style="color: #4758AB;">unlink</span>(demo_dir, <span class="at" style="color: #657422;">recursive =</span> <span class="cn" style="color: #8f5902;">TRUE</span>), <span class="at" style="color: #657422;">add =</span> <span class="cn" style="color: #8f5902;">TRUE</span>)</span>
<span id="cb4-157"></span>
<span id="cb4-158">  <span class="co" style="color: #5E5E5E;"># 1. Target with encoded space (valid target)</span></span>
<span id="cb4-159">  <span class="fu" style="color: #4758AB;">writeLines</span>(</span>
<span id="cb4-160">    <span class="st" style="color: #20794D;">"&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;body&gt;Target with space&lt;/body&gt;&lt;/html&gt;"</span>,</span>
<span id="cb4-161">    <span class="fu" style="color: #4758AB;">file.path</span>(demo_dir, <span class="st" style="color: #20794D;">"my file.html"</span>)</span>
<span id="cb4-162">  )</span>
<span id="cb4-163"></span>
<span id="cb4-164">  <span class="co" style="color: #5E5E5E;"># 2. Folder without index.html (broken directory target)</span></span>
<span id="cb4-165">  templates_dir <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">file.path</span>(demo_dir, <span class="st" style="color: #20794D;">"templates"</span>)</span>
<span id="cb4-166">  <span class="fu" style="color: #4758AB;">dir.create</span>(templates_dir, <span class="at" style="color: #657422;">recursive =</span> <span class="cn" style="color: #8f5902;">TRUE</span>, <span class="at" style="color: #657422;">showWarnings =</span> <span class="cn" style="color: #8f5902;">FALSE</span>)</span>
<span id="cb4-167">  <span class="fu" style="color: #4758AB;">writeLines</span>(<span class="st" style="color: #20794D;">"plain text"</span>, <span class="fu" style="color: #4758AB;">file.path</span>(templates_dir, <span class="st" style="color: #20794D;">"README.txt"</span>))</span>
<span id="cb4-168"></span>
<span id="cb4-169">  <span class="co" style="color: #5E5E5E;"># 3. Main HTML page with:</span></span>
<span id="cb4-170">  <span class="co" style="color: #5E5E5E;">#    - one broken link ("missing.html")</span></span>
<span id="cb4-171">  <span class="co" style="color: #5E5E5E;">#    - one folder link without index.html ("templates/")</span></span>
<span id="cb4-172">  <span class="co" style="color: #5E5E5E;">#    - one encoded space ("my%20file.html")</span></span>
<span id="cb4-173">  <span class="fu" style="color: #4758AB;">writeLines</span>(</span>
<span id="cb4-174">    <span class="fu" style="color: #4758AB;">c</span>(</span>
<span id="cb4-175">      <span class="st" style="color: #20794D;">"&lt;!DOCTYPE html&gt;"</span>,</span>
<span id="cb4-176">      <span class="st" style="color: #20794D;">"&lt;html&gt;"</span>,</span>
<span id="cb4-177">      <span class="st" style="color: #20794D;">"&lt;head&gt;&lt;title&gt;Link Checker Demo&lt;/title&gt;&lt;/head&gt;"</span>,</span>
<span id="cb4-178">      <span class="st" style="color: #20794D;">"&lt;body&gt;"</span>,</span>
<span id="cb4-179">      <span class="st" style="color: #20794D;">'  &lt;a href="https://insightsurge-dev.web.app/posts/link-checking-rendered-sites/missing.html"&gt;Missing Page&lt;/a&gt;'</span>,</span>
<span id="cb4-180">      <span class="st" style="color: #20794D;">'  &lt;a href="https://insightsurge-dev.web.app/posts/link-checking-rendered-sites/templates/"&gt;Templates Folder&lt;/a&gt;'</span>,</span>
<span id="cb4-181">      <span class="st" style="color: #20794D;">'  &lt;a href="https://insightsurge-dev.web.app/posts/link-checking-rendered-sites/my%20file.html"&gt;File with Space&lt;/a&gt;'</span>,</span>
<span id="cb4-182">      <span class="st" style="color: #20794D;">"&lt;/body&gt;"</span>,</span>
<span id="cb4-183">      <span class="st" style="color: #20794D;">"&lt;/html&gt;"</span></span>
<span id="cb4-184">    ),</span>
<span id="cb4-185">    <span class="fu" style="color: #4758AB;">file.path</span>(demo_dir, <span class="st" style="color: #20794D;">"index.html"</span>)</span>
<span id="cb4-186">  )</span>
<span id="cb4-187"></span>
<span id="cb4-188">  <span class="fu" style="color: #4758AB;">check_links</span>(demo_dir)</span>
<span id="cb4-189">}</span>
<span id="cb4-190"></span>
<span id="cb4-191"><span class="co" style="color: #5E5E5E;"># Run demo or check CLI directory when invoked directly as a script</span></span>
<span id="cb4-192"><span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">sys.nframe</span>() <span class="sc" style="color: #5E5E5E;">==</span> <span class="dv" style="color: #AD0000;">0</span>L) {</span>
<span id="cb4-193">  args <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">commandArgs</span>(<span class="at" style="color: #657422;">trailingOnly =</span> <span class="cn" style="color: #8f5902;">TRUE</span>)</span>
<span id="cb4-194">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">length</span>(args) <span class="sc" style="color: #5E5E5E;">&gt;</span> <span class="dv" style="color: #AD0000;">0</span>L) {</span>
<span id="cb4-195">    target_dir <span class="ot" style="color: #003B4F;">&lt;-</span> args[<span class="dv" style="color: #AD0000;">1</span>L]</span>
<span id="cb4-196">    <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="sc" style="color: #5E5E5E;">!</span><span class="fu" style="color: #4758AB;">dir.exists</span>(target_dir)) {</span>
<span id="cb4-197">      <span class="fu" style="color: #4758AB;">cat</span>(</span>
<span id="cb4-198">        <span class="fu" style="color: #4758AB;">sprintf</span>(<span class="st" style="color: #20794D;">"Error: Directory '%s' does not exist.</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>, target_dir),</span>
<span id="cb4-199">        <span class="at" style="color: #657422;">file =</span> <span class="fu" style="color: #4758AB;">stderr</span>()</span>
<span id="cb4-200">      )</span>
<span id="cb4-201">      <span class="fu" style="color: #4758AB;">quit</span>(<span class="at" style="color: #657422;">save =</span> <span class="st" style="color: #20794D;">"no"</span>, <span class="at" style="color: #657422;">status =</span> <span class="dv" style="color: #AD0000;">1</span>L)</span>
<span id="cb4-202">    }</span>
<span id="cb4-203">    <span class="fu" style="color: #4758AB;">cat</span>(<span class="fu" style="color: #4758AB;">sprintf</span>(<span class="st" style="color: #20794D;">"Checking internal links in '%s'...</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>, target_dir))</span>
<span id="cb4-204">    report <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">check_links</span>(target_dir)</span>
<span id="cb4-205">  } <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> {</span>
<span id="cb4-206">    <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"Running offline link check demonstration in temporary directory...</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb4-207">    report <span class="ot" style="color: #003B4F;">&lt;-</span> <span class="fu" style="color: #4758AB;">run_link_demo</span>()</span>
<span id="cb4-208">  }</span>
<span id="cb4-209"></span>
<span id="cb4-210">  <span class="fu" style="color: #4758AB;">cat</span>(<span class="fu" style="color: #4758AB;">sprintf</span>(</span>
<span id="cb4-211">    <span class="st" style="color: #20794D;">"Checked %d internal links; broken: %d</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>,</span>
<span id="cb4-212">    report<span class="sc" style="color: #5E5E5E;">$</span>checked,</span>
<span id="cb4-213">    <span class="fu" style="color: #4758AB;">nrow</span>(report<span class="sc" style="color: #5E5E5E;">$</span>broken)</span>
<span id="cb4-214">  ))</span>
<span id="cb4-215">  <span class="cf" style="color: #003B4F;
font-weight: bold;">if</span> (<span class="fu" style="color: #4758AB;">nrow</span>(report<span class="sc" style="color: #5E5E5E;">$</span>broken) <span class="sc" style="color: #5E5E5E;">&gt;</span> <span class="dv" style="color: #AD0000;">0</span>L) {</span>
<span id="cb4-216">    <span class="cf" style="color: #003B4F;
font-weight: bold;">for</span> (i <span class="cf" style="color: #003B4F;
font-weight: bold;">in</span> <span class="fu" style="color: #4758AB;">seq_len</span>(<span class="fu" style="color: #4758AB;">min</span>(<span class="dv" style="color: #AD0000;">50</span>L, <span class="fu" style="color: #4758AB;">nrow</span>(report<span class="sc" style="color: #5E5E5E;">$</span>broken)))) {</span>
<span id="cb4-217">      <span class="fu" style="color: #4758AB;">cat</span>(<span class="fu" style="color: #4758AB;">sprintf</span>(</span>
<span id="cb4-218">        <span class="st" style="color: #20794D;">"  [%s] %s -&gt; %s</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>,</span>
<span id="cb4-219">        report<span class="sc" style="color: #5E5E5E;">$</span>broken<span class="sc" style="color: #5E5E5E;">$</span>page[i],</span>
<span id="cb4-220">        report<span class="sc" style="color: #5E5E5E;">$</span>broken<span class="sc" style="color: #5E5E5E;">$</span>link[i],</span>
<span id="cb4-221">        report<span class="sc" style="color: #5E5E5E;">$</span>broken<span class="sc" style="color: #5E5E5E;">$</span>resolved_path[i]</span>
<span id="cb4-222">      ))</span>
<span id="cb4-223">    }</span>
<span id="cb4-224">    <span class="fu" style="color: #4758AB;">quit</span>(<span class="at" style="color: #657422;">save =</span> <span class="st" style="color: #20794D;">"no"</span>, <span class="at" style="color: #657422;">status =</span> <span class="dv" style="color: #AD0000;">1</span>L)</span>
<span id="cb4-225">  } <span class="cf" style="color: #003B4F;
font-weight: bold;">else</span> {</span>
<span id="cb4-226">    <span class="fu" style="color: #4758AB;">cat</span>(<span class="st" style="color: #20794D;">"All internal links resolved successfully.</span><span class="sc" style="color: #5E5E5E;">\n</span><span class="st" style="color: #20794D;">"</span>)</span>
<span id="cb4-227">    <span class="fu" style="color: #4758AB;">quit</span>(<span class="at" style="color: #657422;">save =</span> <span class="st" style="color: #20794D;">"no"</span>, <span class="at" style="color: #657422;">status =</span> <span class="dv" style="color: #AD0000;">0</span>L)</span>
<span id="cb4-228">  }</span>
<span id="cb4-229">}</span></code></pre></div></div>
</div>
</div>
</div>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<p><strong>Link checking and CI tools</strong></p>
<ul>
<li><strong>lychee</strong>: <a href="https://lychee.cli.rs/">lychee.cli.rs</a></li>
<li><strong>lychee-action</strong>: <a href="https://github.com/lycheeverse/lychee-action">github.com/lycheeverse/lychee-action</a></li>
</ul>
<p><strong>R package documentation</strong></p>
<ul>
<li><strong>xml2</strong>: <a href="https://xml2.r-lib.org/">xml2.r-lib.org</a></li>
<li><strong>pkgdown</strong>: <a href="https://pkgdown.r-lib.org/">pkgdown.r-lib.org</a></li>
</ul>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-2-contents" aria-controls="callout-2" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Updates
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-2" class="callout-2-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<ul>
<li><strong>2026-09-26:</strong> Removed the end-of-post checklist.</li>
<li><strong>2026-09-27:</strong> Clarified directory link recommendations.</li>
<li><strong>2026-09-27:</strong> Replaced the Python script with an R link checker ({xml2}) and added companion code.</li>
</ul>
</div>
</div>
</div>



</section>
<section id="keep-reading" class="level2 unnumbered unlisted no-anchor site-related">
<h2 class="unnumbered unlisted no-anchor" data-anchor-id="keep-reading">Keep reading</h2>
<div class="site-link-list">
<ul>
<li><a href="https://insightsurge-dev.web.app/posts/ci-github-actions/index.html" class="site-link-row" title="Run R CMD check, tests, and link validation automatically on clean GitHub Actions runners with pinned dependencies."><span class="is-card__eyebrow site-link-row__label">Builds on</span><span class="site-link-row__title">CI with GitHub Actions</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/quarto-firebase-previews/index.html" class="site-link-row" title="Deploy temporary Firebase Hosting preview channels on every pull request to review rendered Quarto sites before merging."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Deploy a Quarto site with a preview for every pull request</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/building-this-blog/index.html" class="site-link-row" title="How we transformed a 14-part topic site into a Quarto engineering blog and portfolio using URL aliases, living-document conventions, and multi-model agentic collaboration."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Building this blog: from numbered topics to a living Quarto publication</span></a></li>
</ul>
</div>
</section>


 ]]></description>
  <category>Quarto</category>
  <category>CI/CD</category>
  <category>R packages</category>
  <guid>https://insightsurge-dev.web.app/posts/link-checking-rendered-sites/</guid>
  <pubDate>Fri, 25 Sep 2026 18:30:00 GMT</pubDate>
</item>
<item>
  <title>Deploy a Quarto site with a preview for every pull request</title>
  <link>https://insightsurge-dev.web.app/posts/quarto-firebase-previews/</link>
  <description><![CDATA[ 





<!--
  Quarto 1.8.27's title-block.html with three changes: category badges and a
  series link ("Testing series · part 2") sit above the title, as in the brand's
  blog kit; and a post or series page with `trailer: true` shows its trailer beside the title
  (_filters/trailer.lua sets trailer-path; _includes/trailers.html plays it). On a Quarto upgrade, diff this against
  share/formats/html/templates/title-block.html and carry over any changes.
-->



<section id="the-problem" class="level2">
<h2 class="anchored" data-anchor-id="the-problem">The problem</h2>
<p>Reviewing technical documentation or rendered reports in a pull request diff is notoriously unreliable:</p>
<ol type="1">
<li><strong>Markdown diffs hide visual defects.</strong> A git diff shows line changes, but it cannot show broken CSS layouts, overflowing tables, mangled cross-references, or misaligned typography.</li>
<li><strong>Local rendering does not scale across a team.</strong> Asking reviewers to clone the branch, install matching tool versions, and run <code>quarto render</code> locally creates friction. Small errors slip into production because nobody rendered the full site.</li>
<li><strong>GitHub Pages limitations.</strong> On GitHub Free accounts, GitHub Pages functions exclusively on <strong>public</strong> repositories. If your source code, drafting notes, or research documents are kept in a private repository, GitHub Pages is unavailable. Even on GitHub Pro plans where private repositories can publish to Pages, the rendered site is published to a single static URL with no native concept of pull request preview channels.</li>
</ol>
<p>Teams need isolated, temporary preview environments for every pull request that spin up automatically, update on subsequent pushes, and expire when review concludes.</p>
</section>
<section id="the-web-repo-way-firebase-hosting-channels" class="level2">
<h2 class="anchored" data-anchor-id="the-web-repo-way-firebase-hosting-channels">The web-repo way: Firebase Hosting channels</h2>
<p>Modern web applications solve this using ephemeral hosting channels. Google Firebase Hosting provides preview channels out-of-the-box, allowing static sites to deploy to an unlisted, temporary URL.</p>
<section id="minimal-hosting-configuration" class="level3">
<h3 class="anchored" data-anchor-id="minimal-hosting-configuration">1. Minimal hosting configuration</h3>
<p>A standard <code>firebase.json</code> file in the repository root defines the static output directory generated by Quarto (<code>_site</code>):</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode json code-with-copy"><code class="sourceCode json"><span id="cb1-1"><span class="fu" style="color: #4758AB;">{</span></span>
<span id="cb1-2">  <span class="dt" style="color: #AD0000;">"hosting"</span><span class="fu" style="color: #4758AB;">:</span> <span class="fu" style="color: #4758AB;">{</span></span>
<span id="cb1-3">    <span class="dt" style="color: #AD0000;">"public"</span><span class="fu" style="color: #4758AB;">:</span> <span class="st" style="color: #20794D;">"_site"</span><span class="fu" style="color: #4758AB;">,</span></span>
<span id="cb1-4">    <span class="dt" style="color: #AD0000;">"cleanUrls"</span><span class="fu" style="color: #4758AB;">:</span> <span class="kw" style="color: #003B4F;
font-weight: bold;">true</span><span class="fu" style="color: #4758AB;">,</span></span>
<span id="cb1-5">    <span class="dt" style="color: #AD0000;">"ignore"</span><span class="fu" style="color: #4758AB;">:</span> <span class="ot" style="color: #003B4F;">[</span><span class="st" style="color: #20794D;">"firebase.json"</span><span class="ot" style="color: #003B4F;">,</span> <span class="st" style="color: #20794D;">"**/.*"</span><span class="ot" style="color: #003B4F;">]</span></span>
<span id="cb1-6">  <span class="fu" style="color: #4758AB;">}</span></span>
<span id="cb1-7"><span class="fu" style="color: #4758AB;">}</span></span></code></pre></div></div>
<p>Setting <code>cleanUrls: true</code> ensures that Firebase Hosting serves <code>page.html</code> at <code>/page</code> (dropping the <code>.html</code> extension) and redirects <code>.html</code> URLs to the clean form.</p>
</section>
<section id="ephemeral-previews-in-github-actions" class="level3">
<h3 class="anchored" data-anchor-id="ephemeral-previews-in-github-actions">2. Ephemeral previews in GitHub Actions</h3>
<p>In <code>.github/workflows/quarto.yml</code>, the workflow renders the site and deploys PRs directly to a designated channel named <code>pr-&lt;number&gt;</code>:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb2-1"><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">name</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Deploy PR preview channel</span></span>
<span id="cb2-2"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">if</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> env.DEPLOY_ENABLED == 'true' &amp;&amp; github.event_name == 'pull_request'</span></span>
<span id="cb2-3"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">id</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> preview</span></span>
<span id="cb2-4"><span class="fu" style="color: #4758AB;">  run</span><span class="kw" style="color: #003B4F;
font-weight: bold;">: </span><span class="ch" style="color: #20794D;">|</span></span>
<span id="cb2-5">    npx --yes "$FIREBASE_TOOLS" hosting:channel:deploy "pr-${{ github.event.number }}" \</span>
<span id="cb2-6">      --project "${{ vars.FIREBASE_PROJECT_ID }}" --expires 7d --json &gt; deploy.json</span>
<span id="cb2-7">    url=$(node -e 'const r=require("./deploy.json").result;console.log(Object.values(r)[0].url)')</span>
<span id="cb2-8">    echo "url=$url" &gt;&gt; "$GITHUB_OUTPUT"</span>
<span id="cb2-9"></span>
<span id="cb2-10"><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">name</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Comment preview URL</span></span>
<span id="cb2-11"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">if</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> steps.preview.outputs.url != ''</span></span>
<span id="cb2-12"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">env</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb2-13"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">GH_TOKEN</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> ${{ secrets.GITHUB_TOKEN }}</span></span>
<span id="cb2-14"><span class="fu" style="color: #4758AB;">  run</span><span class="kw" style="color: #003B4F;
font-weight: bold;">: </span><span class="ch" style="color: #20794D;">|</span></span>
<span id="cb2-15">    gh pr comment "${{ github.event.number }}" --edit-last --create-if-none \</span>
<span id="cb2-16">      --body "📘 Preview: ${{ steps.preview.outputs.url }} (expires in 7 days)"</span></code></pre></div></div>
</section>
<section id="posting-and-updating-the-review-link" class="level3">
<h3 class="anchored" data-anchor-id="posting-and-updating-the-review-link">3. Posting and updating the review link</h3>
<p>The workflow captures the generated preview URL—which follows the structure <code>https://&lt;project&gt;--pr-&lt;number&gt;-&lt;hash&gt;.web.app</code>—and comments it directly onto the pull request. Using <code>gh pr comment --edit-last --create-if-none</code> ensures that repeated commits to the same pull request update the existing comment rather than generating comment spam.</p>
<p>When the branch is merged into <code>main</code>, the workflow executes a standard live deployment:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb3-1"><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">name</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> Deploy live (dev) site</span></span>
<span id="cb3-2"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">if</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> env.DEPLOY_ENABLED == 'true' &amp;&amp; github.event_name != 'pull_request'</span></span>
<span id="cb3-3"><span class="fu" style="color: #4758AB;">  run</span><span class="kw" style="color: #003B4F;
font-weight: bold;">: </span><span class="ch" style="color: #20794D;">|</span></span>
<span id="cb3-4">    npx --yes "$FIREBASE_TOOLS" deploy --only hosting \</span>
<span id="cb3-5">      --project "${{ vars.FIREBASE_PROJECT_ID }}" --non-interactive</span></code></pre></div></div>
<p>All credentials are exchanged keylessly via Workload Identity Federation (see <a href="https://insightsurge-dev.web.app/posts/keyless-ci-auth-oidc/index.html">keyless CI deploys</a>), meaning no service account keys exist in the repository.</p>
</section>
</section>
<section id="what-we-observed" class="level2">
<h2 class="anchored" data-anchor-id="what-we-observed">What we observed</h2>
<p>Our live dev deployment and preview channels were verified on 2026-09-26:</p>
<ul>
<li><strong>Automated commenting:</strong> On opening a pull request, the workflow authenticated, provisioned the Firebase Hosting channel <code>pr-2</code>, and left a single formatted comment with the live preview link.</li>
<li><strong>Graceful degradation:</strong> The deployment step evaluates a safety gate (<code>DEPLOY_ENABLED</code>). If the repository variables for Google Cloud have not yet been configured, the deployment steps skip without breaking the build, allowing Quarto rendering and link checking to proceed unhindered.</li>
<li><strong>Fork security:</strong> Fork PRs get a read-only token and no secrets; our workflow additionally skips deploys when <code>head.repo.full_name != github.repository</code>.</li>
<li><strong>Automatic retirement:</strong> Channels deploy with <code>--expires 7d</code>. Channels expire 7 days after the last deploy to that channel (each push redeploys and resets the timer), preventing orphaned staging sites from accumulating.</li>
</ul>
</section>
<section id="the-r-way-pkgdown-sites-and-quarto-reports" class="level2">
<h2 class="anchored" data-anchor-id="the-r-way-pkgdown-sites-and-quarto-reports">The R way: pkgdown sites and Quarto reports</h2>
<p>This architecture is not restricted to websites; it fits any static HTML generated by R tooling.</p>
<section id="pkgdown-documentation" class="level3">
<h3 class="anchored" data-anchor-id="pkgdown-documentation">pkgdown documentation</h3>
<p>An R package documentation site created with <code>pkgdown::build_site()</code> writes its static assets to the <code>docs/</code> folder. By pointing <code>firebase.json</code>’s <code>public</code> key to <code>docs</code>, the exact same preview pipeline can deploy previews of your package documentation whenever an author opens a pull request. Reviewers can click through reference manual updates and vignettes before the code is merged.</p>
</section>
<section id="quarto-clinical-and-scientific-reports" class="level3">
<h3 class="anchored" data-anchor-id="quarto-clinical-and-scientific-reports">Quarto clinical and scientific reports</h3>
<p>Complex Quarto reports often contain tabsets, interactive HTML widgets, and extensive data tables that cannot be adequately evaluated in code review. Building the report in CI and shipping it to an ephemeral preview channel gives statisticians, clinicians, and quality auditors a fully functional artifact to examine.</p>
</section>
<section id="deployment-alternatives" class="level3">
<h3 class="anchored" data-anchor-id="deployment-alternatives">Deployment alternatives</h3>
<p>Other platforms offer preview capabilities for static R outputs:</p>
<ul>
<li><strong>Posit Connect:</strong> Excellent for enterprise internal deployment, supporting both Shiny apps and static Quarto reports. Previews typically require publishing to distinct content items or managing access controls within the Connect server.</li>
<li><strong>Quarto Pub:</strong> Simple and built directly into Quarto, but all published content is public.</li>
<li><strong>Netlify:</strong> Provides native deploy previews for static sites by monitoring GitHub pull requests, but introduces an additional third-party vendor if your organisation already standardises on Google Cloud, AWS, or Azure.</li>
</ul>
</section>
</section>
<section id="pitfalls-we-hit" class="level2">
<h2 class="anchored" data-anchor-id="pitfalls-we-hit">Pitfalls we hit</h2>
<ul>
<li><strong>Channel sprawl without expiry:</strong> Forgetting the <code>--expires</code> flag leaves old preview channels active indefinitely. Setting <code>--expires 7d</code> ensures automatic garbage collection.</li>
<li><strong>Silent skips during initial setup:</strong> If repository variables (<code>GCP_WORKLOAD_IDENTITY_PROVIDER</code>, <code>GCP_SERVICE_ACCOUNT</code>, <code>FIREBASE_PROJECT_ID</code>) are absent or misspelled, <code>DEPLOY_ENABLED</code> evaluates to <code>false</code> and the deployment step skips quietly. Check the job log variables if a preview comment fails to appear.</li>
<li><strong>PR comment flooding:</strong> Running a naive <code>gh pr comment</code> without <code>--edit-last</code> leaves a new comment on every push, drowning out conversation. Always use <code>--edit-last --create-if-none</code>.</li>
<li><strong>Public URL discovery:</strong> Firebase preview URLs are unlisted, but they are accessible on the public internet. Firebase Hosting has no built-in access control for static content, so keep content generic and free of proprietary data, or use a host with access control (such as Posit Connect).</li>
</ul>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Updates
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<ul>
<li><strong>2026-09-26:</strong> Removed the end-of-post checklist.</li>
</ul>
</div>
</div>
</div>



</section>
<section id="keep-reading" class="level2 unnumbered unlisted no-anchor site-related">
<h2 class="unnumbered unlisted no-anchor" data-anchor-id="keep-reading">Keep reading</h2>
<div class="site-link-list">
<ul>
<li><a href="https://insightsurge-dev.web.app/posts/ci-github-actions/index.html" class="site-link-row" title="Run R CMD check, tests, and link validation automatically on clean GitHub Actions runners with pinned dependencies."><span class="is-card__eyebrow site-link-row__label">Read first</span><span class="site-link-row__title">CI with GitHub Actions</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/keyless-ci-auth-oidc/index.html" class="site-link-row" title="Use OpenID Connect and Google Cloud Workload Identity Federation to authenticate CI pipelines without long-lived JSON keys."><span class="is-card__eyebrow site-link-row__label">Read next</span><span class="site-link-row__title">Keyless deploys: let CI prove who it is (OIDC)</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/link-checking-rendered-sites/index.html" class="site-link-row" title="Validate internal links across rendered documentation in CI using offline link scanners to block broken references before release."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Catch broken links before your readers do</span></a></li>
</ul>
</div>
</section>


 ]]></description>
  <category>Quarto</category>
  <category>CI/CD</category>
  <category>R packages</category>
  <guid>https://insightsurge-dev.web.app/posts/quarto-firebase-previews/</guid>
  <pubDate>Fri, 25 Sep 2026 18:30:00 GMT</pubDate>
</item>
<item>
  <title>Google Analytics with cookie consent on a Quarto site</title>
  <link>https://insightsurge-dev.web.app/posts/quarto-google-analytics-consent/</link>
  <description><![CDATA[ 





<!--
  Quarto 1.8.27's title-block.html with three changes: category badges and a
  series link ("Testing series · part 2") sit above the title, as in the brand's
  blog kit; and a post or series page with `trailer: true` shows its trailer beside the title
  (_filters/trailer.lua sets trailer-path; _includes/trailers.html plays it). On a Quarto upgrade, diff this against
  share/formats/html/templates/title-block.html and carry over any changes.
-->



<section id="the-problem" class="level2">
<h2 class="anchored" data-anchor-id="the-problem">The problem</h2>
<p>Adding analytics to a documentation site or technical blog seems trivial until you consider privacy rules and development noise:</p>
<ol type="1">
<li><strong>Unconditional tracking breaches privacy standards.</strong> Injecting a standard tracking script causes the browser to fetch third-party scripts and set tracking cookies (<code>_ga</code>, <code>_ga_*</code>) the moment a page opens. Under EU GDPR/ePrivacy rules, non-essential cookies such as analytics generally need prior opt-in consent.</li>
<li><strong>Preview noise pollutes production metrics.</strong> If your analytics tag is enabled in the default site configuration, every local build, automated CI render, and pull request preview logs page views into your production dashboard.</li>
<li><strong>Confusion between public IDs and secrets.</strong> Developers often treat Google Analytics Measurement IDs (<code>G-XXXXXXXXXX</code>) as confidential secrets and attempt to hide them behind environment variables. In reality, client-side tracking IDs are embedded in plain text within page source by design.</li>
</ol>
<p>The goal is to enable Google Analytics 4 (GA4) with a clear opt-in consent mechanism, while ensuring that local previews and automated builds generate no tracking requests.</p>
</section>
<section id="the-quarto-way-profiles-and-express-consent" class="level2">
<h2 class="anchored" data-anchor-id="the-quarto-way-profiles-and-express-consent">The Quarto way: profiles and express consent</h2>
<p>Quarto provides native support for both Google Analytics 4 and cookie consent management via its site metadata. Rather than baking the tracking configuration into the primary <code>_quarto.yml</code>, we isolate it in an environment profile:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb1-1"><span class="co" style="color: #5E5E5E;"># _quarto-live.yml (merged only when QUARTO_PROFILE=live)</span></span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;">website</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-3"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">google-analytics</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-4"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">tracking-id</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="st" style="color: #20794D;">"G-XXXXXXXXXX"</span><span class="co" style="color: #5E5E5E;">   # Public GA4 measurement stream ID</span></span>
<span id="cb1-5"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">anonymize-ip</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="ch" style="color: #20794D;">true</span></span>
<span id="cb1-6"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">cookie-consent</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-7"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">type</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> express</span><span class="co" style="color: #5E5E5E;">                  # No tracking cookies until explicit opt-in</span></span>
<span id="cb1-8"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">style</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> simple</span></span>
<span id="cb1-9"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">palette</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> light</span></span></code></pre></div></div>
<section id="how-express-consent-functions" class="level3">
<h3 class="anchored" data-anchor-id="how-express-consent-functions">How express consent functions</h3>
<p>When <code>cookie-consent: type: express</code> is declared, Quarto does not inject an immediately executable analytics snippet. Instead, it rewrites the script tag roughly like this:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode html code-with-copy"><code class="sourceCode html"><span id="cb2-1"><span class="dt" style="color: #AD0000;">&lt;</span><span class="kw" style="color: #003B4F;
font-weight: bold;">script</span><span class="ot" style="color: #003B4F;"> type=</span><span class="st" style="color: #20794D;">"text/plain"</span><span class="ot" style="color: #003B4F;"> cookie-consent</span><span class="op" style="color: #5E5E5E;">=</span><span class="st" style="color: #20794D;">"tracking"</span><span class="dt" style="color: #AD0000;">&gt;</span></span>
<span id="cb2-2">  <span class="bu" style="color: null;">window</span><span class="op" style="color: #5E5E5E;">.</span><span class="at" style="color: #657422;">dataLayer</span> <span class="op" style="color: #5E5E5E;">=</span> <span class="bu" style="color: null;">window</span><span class="op" style="color: #5E5E5E;">.</span><span class="at" style="color: #657422;">dataLayer</span> <span class="op" style="color: #5E5E5E;">||</span> []<span class="op" style="color: #5E5E5E;">;</span></span>
<span id="cb2-3">  <span class="kw" style="color: #003B4F;
font-weight: bold;">function</span> <span class="fu" style="color: #4758AB;">gtag</span>(){dataLayer<span class="op" style="color: #5E5E5E;">.</span><span class="fu" style="color: #4758AB;">push</span>(<span class="kw" style="color: #003B4F;
font-weight: bold;">arguments</span>)<span class="op" style="color: #5E5E5E;">;</span>}</span>
<span id="cb2-4">  <span class="fu" style="color: #4758AB;">gtag</span>(<span class="st" style="color: #20794D;">'js'</span><span class="op" style="color: #5E5E5E;">,</span> <span class="kw" style="color: #003B4F;
font-weight: bold;">new</span> <span class="bu" style="color: null;">Date</span>())<span class="op" style="color: #5E5E5E;">;</span></span>
<span id="cb2-5">  <span class="fu" style="color: #4758AB;">gtag</span>(<span class="st" style="color: #20794D;">'config'</span><span class="op" style="color: #5E5E5E;">,</span> <span class="st" style="color: #20794D;">'G-XXXXXXXXXX'</span><span class="op" style="color: #5E5E5E;">,</span> { <span class="st" style="color: #20794D;">'anonymize_ip'</span><span class="op" style="color: #5E5E5E;">:</span> <span class="kw" style="color: #003B4F;
font-weight: bold;">true</span>})<span class="op" style="color: #5E5E5E;">;</span></span>
<span id="cb2-6"><span class="dt" style="color: #AD0000;">&lt;/</span><span class="kw" style="color: #003B4F;
font-weight: bold;">script</span><span class="dt" style="color: #AD0000;">&gt;</span></span></code></pre></div></div>
<p>Because the MIME type is <code>text/plain</code>, the browser refuses to execute the script during initial page parsing. The bundled consent library (served from <code>site_libs/cookie-consent/</code>) activates scripts marked <code>cookie-consent="tracking"</code> once the visitor opts in, and records the choice in a <code>cookie_consent_level</code> cookie.</p>
</section>
<section id="hold-back-the-loader-too" class="level3">
<h3 class="anchored" data-anchor-id="hold-back-the-loader-too">Hold back the loader too</h3>
<p>Quarto’s <code>google-analytics:</code> option holds back only the configuration snippet. It also emits the loader as an ordinary script, <code>&lt;script async src="https://www.googletagmanager.com/gtag/js?id=..."&gt;</code>, so the browser requests it from Google on every page load, before the visitor has chosen anything.</p>
<p>The consent library can hold that back as well. When a visitor accepts a category, it recreates each <code>text/plain</code> script marked with that category as a real script and copies its <code>src</code>. So we stopped using Quarto’s <code>google-analytics:</code> option and load GA4 from an include, with both scripts marked:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb3-1"><span class="co" style="color: #5E5E5E;"># _quarto-live.yml</span></span>
<span id="cb3-2"><span class="fu" style="color: #4758AB;">website</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb3-3"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">cookie-consent</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb3-4"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">type</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> express</span></span>
<span id="cb3-5"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">style</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> simple</span></span>
<span id="cb3-6"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">palette</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> light</span></span>
<span id="cb3-7"></span>
<span id="cb3-8"><span class="fu" style="color: #4758AB;">format</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb3-9"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">html</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb3-10"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">include-in-header</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> _includes/analytics.html</span></span></code></pre></div></div>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode html code-with-copy"><code class="sourceCode html"><span id="cb4-1"><span class="co" style="color: #5E5E5E;">&lt;!-- _includes/analytics.html --&gt;</span></span>
<span id="cb4-2"><span class="dt" style="color: #AD0000;">&lt;</span><span class="kw" style="color: #003B4F;
font-weight: bold;">script</span><span class="ot" style="color: #003B4F;"> type=</span><span class="st" style="color: #20794D;">"text/plain"</span><span class="ot" style="color: #003B4F;"> cookie-consent</span><span class="op" style="color: #5E5E5E;">=</span><span class="st" style="color: #20794D;">"tracking"</span><span class="ot" style="color: #003B4F;"> async</span></span>
<span id="cb4-3"><span class="ot" style="color: #003B4F;">        src</span><span class="op" style="color: #5E5E5E;">=</span><span class="st" style="color: #20794D;">"https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"</span><span class="dt" style="color: #AD0000;">&gt;&lt;/</span><span class="kw" style="color: #003B4F;
font-weight: bold;">script</span><span class="dt" style="color: #AD0000;">&gt;</span></span>
<span id="cb4-4"><span class="dt" style="color: #AD0000;">&lt;</span><span class="kw" style="color: #003B4F;
font-weight: bold;">script</span><span class="ot" style="color: #003B4F;"> type=</span><span class="st" style="color: #20794D;">"text/plain"</span><span class="ot" style="color: #003B4F;"> cookie-consent</span><span class="op" style="color: #5E5E5E;">=</span><span class="st" style="color: #20794D;">"tracking"</span><span class="dt" style="color: #AD0000;">&gt;</span></span>
<span id="cb4-5">  <span class="bu" style="color: null;">window</span><span class="op" style="color: #5E5E5E;">.</span><span class="at" style="color: #657422;">dataLayer</span> <span class="op" style="color: #5E5E5E;">=</span> <span class="bu" style="color: null;">window</span><span class="op" style="color: #5E5E5E;">.</span><span class="at" style="color: #657422;">dataLayer</span> <span class="op" style="color: #5E5E5E;">||</span> []<span class="op" style="color: #5E5E5E;">;</span></span>
<span id="cb4-6">  <span class="kw" style="color: #003B4F;
font-weight: bold;">function</span> <span class="fu" style="color: #4758AB;">gtag</span>(){dataLayer<span class="op" style="color: #5E5E5E;">.</span><span class="fu" style="color: #4758AB;">push</span>(<span class="kw" style="color: #003B4F;
font-weight: bold;">arguments</span>)<span class="op" style="color: #5E5E5E;">;</span>}</span>
<span id="cb4-7">  <span class="fu" style="color: #4758AB;">gtag</span>(<span class="st" style="color: #20794D;">'js'</span><span class="op" style="color: #5E5E5E;">,</span> <span class="kw" style="color: #003B4F;
font-weight: bold;">new</span> <span class="bu" style="color: null;">Date</span>())<span class="op" style="color: #5E5E5E;">;</span></span>
<span id="cb4-8">  <span class="fu" style="color: #4758AB;">gtag</span>(<span class="st" style="color: #20794D;">'config'</span><span class="op" style="color: #5E5E5E;">,</span> <span class="st" style="color: #20794D;">'G-XXXXXXXXXX'</span><span class="op" style="color: #5E5E5E;">,</span> { <span class="st" style="color: #20794D;">'anonymize_ip'</span><span class="op" style="color: #5E5E5E;">:</span> <span class="kw" style="color: #003B4F;
font-weight: bold;">true</span> })<span class="op" style="color: #5E5E5E;">;</span></span>
<span id="cb4-9"><span class="dt" style="color: #AD0000;">&lt;/</span><span class="kw" style="color: #003B4F;
font-weight: bold;">script</span><span class="dt" style="color: #AD0000;">&gt;</span></span></code></pre></div></div>
<p>The include sits in the <code>live</code> profile, so previews and local renders stay free of analytics as before.</p>
</section>
<section id="gating-analytics-in-github-actions" class="level3">
<h3 class="anchored" data-anchor-id="gating-analytics-in-github-actions">Gating analytics in GitHub Actions</h3>
<p>To keep pull request previews and local renders free of tracking tags, configure your CI workflow to activate the <code>live</code> profile only on merges to your primary branch:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb5-1"><span class="co" style="color: #5E5E5E;"># .github/workflows/quarto.yml</span></span>
<span id="cb5-2"><span class="fu" style="color: #4758AB;">env</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb5-3"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">QUARTO_PROFILE</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> ${{ github.event_name != 'pull_request' &amp;&amp; github.ref == 'refs/heads/main' &amp;&amp; 'live' || '' }}</span></span></code></pre></div></div>
<p>During a pull request build or local <code>quarto render</code>, <code>QUARTO_PROFILE</code> remains empty. Quarto reads only <code>_quarto.yml</code>, producing static HTML with no Google Analytics tags and no consent banner. When code merges into <code>main</code>, Quarto overlays <code>_quarto-live.yml</code> and produces the production build.</p>
</section>
</section>
<section id="what-we-observed" class="level2">
<h2 class="anchored" data-anchor-id="what-we-observed">What we observed</h2>
<p>We tested this configuration across local builds, pull requests, and live dev hosting on 2026-09-26:</p>
<ul>
<li><strong>Local and PR builds are sterile.</strong> Inspecting the rendered HTML of a PR preview showed no occurrences of <code>googletagmanager</code> or <code>G-</code>. No tracking code was present in the deployment.</li>
<li><strong>Opt-in operates as designed.</strong> On the live deployment, visiting the site presented the consent banner. Inspection of browser storage confirmed that <code>cookie_consent_level</code> was initialised with <code>tracking:false</code>. No <code>_ga</code> cookies existed in the browser before consent was clicked.</li>
<li><strong>A technical nuance on loader fetching.</strong> While Quarto blocks execution of the <code>gtag</code> configuration snippet, the external loader (<code>https://www.googletagmanager.com/gtag/js?id=...</code>) is still fetched over the network on initial page load. While no persistent cookies are set before consent, the HTTP request itself reaches Google’s servers. For teams with strict no-external-traffic requirements prior to consent, the loader tag itself must be gated. We now gate it (see <em>Hold back the loader too</em>).</li>
<li><strong>The gated loader, checked on 2026-09-27.</strong> We served a <code>live</code> render through the Firebase Hosting emulator, with the Measurement ID swapped for a test ID so no data reached the real stream. Before consent the browser made no request to <code>googletagmanager.com</code>, <code>gtag</code> was undefined and there were no <code>_ga</code> cookies. After clicking <em>I agree</em>, <code>gtag.js</code> was requested and the <code>_ga</code> cookies appeared. After <em>I decline</em> (in a fresh cookie store), the next page made no request and set no <code>_ga</code> cookies.</li>
<li><strong>Banner copy wording.</strong> Quarto’s default banner text contains boilerplate mentioning third-party advertising cookies. Because an engineering site runs no advertising networks, this wording is inaccurate. The wording cannot be changed through Quarto’s <code>cookie-consent</code> options (only <code>prefs-text</code> for the preferences link is configurable), and we are tracking a fix (a custom include or another consent tool).</li>
<li><strong>Measurement IDs are public.</strong> As shown in the HTML snippet above, the Measurement ID is visible to anyone inspecting page source. It does not require storage in a secret vault (see <a href="https://insightsurge-dev.web.app/posts/secrets-management/index.html">secrets management</a>).</li>
</ul>
</section>
<section id="the-r-way-shiny-and-pkgdown" class="level2">
<h2 class="anchored" data-anchor-id="the-r-way-shiny-and-pkgdown">The R way: Shiny and pkgdown</h2>
<p>The same principles of environment separation and consent gating apply to the wider R ecosystem.</p>
<section id="shiny-applications" class="level3">
<h3 class="anchored" data-anchor-id="shiny-applications">Shiny applications</h3>
<p>Shiny applications often track user sessions or tab navigation by inserting <code>gtag()</code> calls via <code>tags$script()</code>. Firing <code>gtag("event", ...)</code> as soon as <code>server.R</code> runs places tracking cookies on the user’s system without permission.</p>
<p>To implement equivalent express consent in Shiny: 1. Store a user consent state in a reactive value or browser cookie. 2. Render the analytics script conditionally inside an <code>observeEvent()</code> only after the user accepts a consent modal or banner. 3. Check <code>Sys.getenv("R_CONFIG_ACTIVE")</code> or configuration settings so local development runs never initialise the tracking client.</p>
</section>
<section id="pkgdown-documentation-sites" class="level3">
<h3 class="anchored" data-anchor-id="pkgdown-documentation-sites">pkgdown documentation sites</h3>
<p>R package authors frequently include analytics to measure documentation usage. In <code>pkgdown</code>, custom scripts are added to <code>_pkgdown.yml</code> using <code>template.includes</code>:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb6-1"><span class="fu" style="color: #4758AB;">template</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb6-2"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">includes</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb6-3"><span class="fu" style="color: #4758AB;">    in_header</span><span class="kw" style="color: #003B4F;
font-weight: bold;">: </span><span class="ch" style="color: #20794D;">|</span></span>
<span id="cb6-4">      &lt;!-- Google tag (gtag.js) --&gt;</span>
<span id="cb6-5">      &lt;script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"&gt;&lt;/script&gt;</span>
<span id="cb6-6">      &lt;script&gt;</span>
<span id="cb6-7">        window.dataLayer = window.dataLayer || [];</span>
<span id="cb6-8">        function gtag(){dataLayer.push(arguments);}</span>
<span id="cb6-9">        gtag('js', new Date());</span>
<span id="cb6-10">        gtag('config', 'G-XXXXXXXXXX');</span>
<span id="cb6-11">      &lt;/script&gt;</span></code></pre></div></div>
<p>Unlike Quarto, <code>pkgdown</code> does not offer an out-of-the-box <code>cookie-consent</code> engine. Adding raw <code>gtag.js</code> in <code>in_header</code> fires tracking immediately for every reader. If your package documentation must respect cookie consent, you cannot rely on a single YAML switch. You must either embed a third-party consent banner script in <code>in_header</code> or manually structure the tracking snippet to read a consent flag before invoking <code>gtag('config')</code>.</p>
</section>
</section>
<section id="pitfalls-we-hit" class="level2">
<h2 class="anchored" data-anchor-id="pitfalls-we-hit">Pitfalls we hit</h2>
<ul>
<li><strong>Expecting analytics in default local renders.</strong> Running <code>quarto preview</code> or <code>quarto render</code> without specifying <code>--profile live</code> renders the base configuration. The banner will not appear. To test consent styling locally, run <code>QUARTO_PROFILE=live quarto preview</code>.</li>
<li><strong>Assuming the loader is completely blocked.</strong> As noted in our observations, Quarto’s built-in express consent delays the <em>config script</em> but still loads the external <code>gtag.js</code> script tag on initial render. Verify whether your organisation’s interpretation of privacy guidelines allows this external script fetch.</li>
<li><strong>Default banner mentions non-existent ad trackers.</strong> Leaving default Quarto banner copy intact can suggest that technical documentation shares data with advertising partners. Because Quarto’s options do not expose banner text configuration, addressing this requires a custom include or alternative consent integration.</li>
<li><strong>Hiding Measurement IDs in CI secrets.</strong> Storing a public tracking ID in GitHub Secrets adds maintenance burden without reducing risk. Keep identifiers in repository variables or profile configuration files.</li>
</ul>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Updates
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<ul>
<li><strong>2026-09-26:</strong> Removed the end-of-post checklist.</li>
<li><strong>2026-09-27:</strong> The <code>gtag.js</code> loader is now held back until consent too (a custom include instead of Quarto’s <code>google-analytics:</code> option), with the browser check that shows it.</li>
</ul>
</div>
</div>
</div>



</section>
<section id="keep-reading" class="level2 unnumbered unlisted no-anchor site-related">
<h2 class="unnumbered unlisted no-anchor" data-anchor-id="keep-reading">Keep reading</h2>
<div class="site-link-list">
<ul>
<li><a href="https://insightsurge-dev.web.app/posts/building-this-blog/index.html" class="site-link-row" title="How we transformed a 14-part topic site into a Quarto engineering blog and portfolio using URL aliases, living-document conventions, and multi-model agentic collaboration."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Building this blog: from numbered topics to a living Quarto publication</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/quarto-firebase-previews/index.html" class="site-link-row" title="Deploy temporary Firebase Hosting preview channels on every pull request to review rendered Quarto sites before merging."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Deploy a Quarto site with a preview for every pull request</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/hosted-site-pitfalls/index.html" class="site-link-row" title="A static Quarto site passed every local link and render test, but failed in a PR preview: how trailing slashes and unconfigured MIME types break hosted assets."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">It worked locally: two hosting bugs every check missed</span></a></li>
</ul>
</div>
</section>


 ]]></description>
  <category>Quarto</category>
  <category>Shiny</category>
  <category>Best practices</category>
  <guid>https://insightsurge-dev.web.app/posts/quarto-google-analytics-consent/</guid>
  <pubDate>Fri, 25 Sep 2026 18:30:00 GMT</pubDate>
</item>
<item>
  <title>Releases &amp; changelogs</title>
  <link>https://insightsurge-dev.web.app/posts/releases-changelogs/</link>
  <description><![CDATA[ 





<!--
  Quarto 1.8.27's title-block.html with three changes: category badges and a
  series link ("Testing series · part 2") sit above the title, as in the brand's
  blog kit; and a post or series page with `trailer: true` shows its trailer beside the title
  (_filters/trailer.lua sets trailer-path; _includes/trailers.html plays it). On a Quarto upgrade, diff this against
  share/formats/html/templates/title-block.html and carry over any changes.
-->



<section id="why-bother" class="level2">
<h2 class="anchored" data-anchor-id="why-bother">Why bother</h2>
<p>A release answers three questions: <strong>what changed</strong> (NEWS/CHANGELOG), <strong>how big was the change</strong> (the version number), and <strong>what exact code is it</strong> (a git tag). In GxP work a release is also what gets assessed and deployed, so the release notes feed your change-control and validation records.</p>
</section>
<section id="semantic-versioning-in-one-table" class="level2">
<h2 class="anchored" data-anchor-id="semantic-versioning-in-one-table">Semantic versioning in one table</h2>
<div class="table-responsive">
<table class="caption-top table">
<colgroup>
<col style="width: 33%">
<col style="width: 33%">
<col style="width: 33%">
</colgroup>
<thead>
<tr class="header">
<th>Bump</th>
<th>When</th>
<th>R package example</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><strong>major</strong> <code>2.0.0</code></td>
<td>Existing code can break</td>
<td>Removed <code>km_plot(risk = )</code>; required R ≥ 4.3</td>
</tr>
<tr class="even">
<td><strong>minor</strong> <code>1.3.0</code></td>
<td>New features, nothing breaks</td>
<td>New <code>forest_plot()</code></td>
</tr>
<tr class="odd">
<td><strong>patch</strong> <code>1.2.1</code></td>
<td>Bug fixes only</td>
<td><code>read_adsl()</code> keeps labels again</td>
</tr>
</tbody>
</table>
</div>
<p>R adds a development convention: between releases the version is <code>x.y.z.9000</code> (<code>usethis::use_dev_version()</code>), so a bug report’s <code>sessionInfo()</code> shows the code wasn’t a release.</p>
<p>With <a href="https://insightsurge-dev.web.app/posts/conventional-commits-pr-titles/index.html">Conventional Commits</a>, the bump can be <strong>computed</strong>. <code>feat</code> → minor, <code>fix</code> → patch, <code>!</code> or <code>BREAKING CHANGE</code> → major.</p>
</section>
<section id="the-web-repo-way-release-please" class="level2">
<h2 class="anchored" data-anchor-id="the-web-repo-way-release-please">The web-repo way: release-please</h2>
<p>Our website uses <a href="https://github.com/googleapis/release-please">release-please</a>. On every push to <code>main</code> it reads the new Conventional Commits and keeps <strong>one release PR</strong> open. That PR bumps <code>package.json</code>, writes <code>CHANGELOG.md</code> grouped by type, and lists what’s coming. Merging it tags the release and creates a GitHub Release.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb1-1"><span class="co" style="color: #5E5E5E;"># .github/workflows/release-please.yml</span></span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;">on</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-3"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">push</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-4"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">branches</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="kw" style="color: #003B4F;
font-weight: bold;">[</span><span class="at" style="color: #657422;">main</span><span class="kw" style="color: #003B4F;
font-weight: bold;">]</span></span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;">permissions</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-6"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">contents</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> write</span></span>
<span id="cb1-7"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">pull-requests</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> write</span></span>
<span id="cb1-8"><span class="fu" style="color: #4758AB;">jobs</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-9"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">release-please</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-10"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">runs-on</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> ubuntu-latest</span></span>
<span id="cb1-11"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">steps</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-12"><span class="at" style="color: #657422;">      </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">uses</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> googleapis/release-please-action@v5</span></span>
<span id="cb1-13"><span class="at" style="color: #657422;">        </span><span class="fu" style="color: #4758AB;">with</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-14"><span class="at" style="color: #657422;">          </span><span class="fu" style="color: #4758AB;">release-type</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> node</span></span></code></pre></div></div>
<p>What we observed:</p>
<ul>
<li>A <code>chore:</code> commit opened <strong>no</strong> release PR. Only <code>feat</code>, <code>fix</code> and breaking changes trigger one.</li>
<li>The repo setting <em>Allow GitHub Actions to create and approve pull requests</em> must be on.</li>
<li>According to GitHub’s docs, PRs opened with the default <code>GITHUB_TOKEN</code> don’t trigger other workflows, so CI won’t run on the release PR unless you use a separate token.</li>
</ul>
<p><strong>For R, release-please doesn’t fit.</strong> Its documented strategies cover Node, Python, Rust, Java, Go and others, but not R. The generic <code>simple</code> strategy bumps a <code>version.txt</code>, which isn’t where R keeps its version (<code>DESCRIPTION</code>).</p>
</section>
<section id="the-r-way" class="level2">
<h2 class="anchored" data-anchor-id="the-r-way">The R way</h2>
<section id="usethis-the-manual-but-reliable-path" class="level3">
<h3 class="anchored" data-anchor-id="usethis-the-manual-but-reliable-path"><code>usethis</code>: the manual but reliable path</h3>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r norun code-with-copy"><code class="sourceCode r"><span id="cb2-1">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">use_news_md</span>()                 <span class="co" style="color: #5E5E5E;"># once: create NEWS.md</span></span>
<span id="cb2-2"><span class="co" style="color: #5E5E5E;"># ... during development, add a bullet to NEWS.md in each user-facing PR ...</span></span>
<span id="cb2-3">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">use_release_issue</span>()           <span class="co" style="color: #5E5E5E;"># a GitHub issue with a release checklist</span></span>
<span id="cb2-4">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">use_version</span>(<span class="st" style="color: #20794D;">"minor"</span>)          <span class="co" style="color: #5E5E5E;"># bump DESCRIPTION + NEWS.md heading, commit</span></span>
<span id="cb2-5">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">use_github_release</span>()          <span class="co" style="color: #5E5E5E;"># tag + GitHub release from the NEWS.md section</span></span>
<span id="cb2-6">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">use_dev_version</span>()             <span class="co" style="color: #5E5E5E;"># back to x.y.z.9000</span></span></code></pre></div></div>
</section>
<section id="fledge-news.md-from-commit-messages" class="level3">
<h3 class="anchored" data-anchor-id="fledge-news.md-from-commit-messages"><code>fledge</code>: NEWS.md from commit messages</h3>
<p><a href="https://fledge.cynkra.com"><code>fledge</code></a> (cynkra) builds <code>NEWS.md</code> from your commit history, and optionally bumps <code>DESCRIPTION</code> and tags. Its README says that commits written in <strong>Conventional Commits</strong> syntax get <em>automatically grouped</em> into changelog sections (Bug Fixes, Documentation, …). That makes it a natural partner for <a href="https://insightsurge-dev.web.app/posts/conventional-commits-pr-titles/index.html">conventional commits</a>’ squash-merge PR titles.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r norun code-with-copy"><code class="sourceCode r"><span id="cb3-1">fledge<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">update_news</span>()      <span class="co" style="color: #5E5E5E;"># light use: add NEWS.md bullets from commits since the last version</span></span>
<span id="cb3-2">fledge<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">bump_version</span>()     <span class="co" style="color: #5E5E5E;"># full use: NEWS.md + dev version bump + tag, run regularly</span></span>
<span id="cb3-3">fledge<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">finalize_version</span>() <span class="co" style="color: #5E5E5E;"># after hand-editing NEWS.md</span></span></code></pre></div></div>
<p>At release time, follow the steps in <code>vignette("fledge")</code>.</p>
</section>
<section id="what-goes-in-news.md" class="level3">
<h3 class="anchored" data-anchor-id="what-goes-in-news.md">What goes in NEWS.md</h3>
<p>Write for <strong>users</strong>, not for the git log. Say what changed in behaviour, how to migrate, and link the issue:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode markdown code-with-copy"><code class="sourceCode markdown"><span id="cb4-1"><span class="fu" style="color: #4758AB;"># clinreport 1.3.0</span></span>
<span id="cb4-2"></span>
<span id="cb4-3"><span class="fu" style="color: #4758AB;">## New features</span></span>
<span id="cb4-4"><span class="ss" style="color: #20794D;">* </span><span class="in" style="color: #5E5E5E;">`forest_plot()`</span> draws subgroup forest plots from an ARD (#57).</span>
<span id="cb4-5"></span>
<span id="cb4-6"><span class="fu" style="color: #4758AB;">## Bug fixes</span></span>
<span id="cb4-7"><span class="ss" style="color: #20794D;">* </span><span class="in" style="color: #5E5E5E;">`read_adsl()`</span> keeps variable labels when reading <span class="in" style="color: #5E5E5E;">`.xpt`</span> files (#61).</span></code></pre></div></div>
</section>
</section>
<section id="tags-and-github-releases" class="level2">
<h2 class="anchored" data-anchor-id="tags-and-github-releases">Tags and GitHub Releases</h2>
<ul>
<li><strong>Tag</strong> every release (<code>v1.3.0</code>). <code>remotes::install_github("org/pkg@v1.3.0")</code> then installs exactly that code, and <code>renv.lock</code> can record it.</li>
<li>A <strong>GitHub Release</strong> attaches notes (and optionally the built tarball) to the tag.</li>
<li>For validation-ready deployments, the tag plus release notes plus CI results for that commit are your evidence of <em>what</em> was assessed.</li>
</ul>
</section>
<section id="pitfalls" class="level2">
<h2 class="anchored" data-anchor-id="pitfalls">Pitfalls</h2>
<ul>
<li><strong>Forgetting the dev version.</strong> A released <code>1.3.0</code> and a work-in-progress <code>1.3.0</code> look identical in <code>sessionInfo()</code>. Always <code>use_dev_version()</code> after releasing.</li>
<li><strong>Changelog written from the git log.</strong> “Merge branch…” is not a release note. Curate it.</li>
<li><strong>Breaking changes hidden in a patch.</strong> If users must change code, it’s a major bump. In 0.x packages, use at least a minor bump and say so loudly.</li>
<li><strong>Retagging.</strong> Never move a published tag. Release a new version instead.</li>
</ul>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<p><strong>Standards and tools</strong></p>
<ul>
<li><strong>Semantic Versioning</strong>: <a href="https://semver.org/">semver.org</a></li>
<li><strong>release-please</strong>: <a href="https://github.com/googleapis/release-please">github.com/googleapis/release-please</a></li>
<li><strong>PRs/workflow runs from <code>GITHUB_TOKEN</code> don’t trigger other workflows</strong>: <a href="https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/trigger-a-workflow">GitHub Docs: Triggering a workflow</a></li>
<li><strong>“Allow GitHub Actions to create and approve pull requests” setting</strong>: <a href="https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository">GitHub Docs: Managing GitHub Actions settings for a repository</a></li>
</ul>
<p><strong>R package documentation</strong></p>
<ul>
<li><strong>usethis</strong> (<code>use_news_md()</code>, <code>use_release_issue()</code>, <code>use_version()</code>, <code>use_github_release()</code>, <code>use_dev_version()</code>): <a href="https://usethis.r-lib.org/">usethis.r-lib.org</a></li>
<li><strong>fledge</strong>: <a href="https://fledge.cynkra.com/">fledge.cynkra.com</a></li>
<li><strong>remotes</strong>: <a href="https://remotes.r-lib.org/">remotes.r-lib.org</a></li>
</ul>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Updates
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<ul>
<li><strong>2026-09-26:</strong> Removed the end-of-post checklist. Marked package-dependent usethis and fledge blocks as .norun.</li>
<li><strong>2026-09-27:</strong> Added a Sources section.</li>
</ul>
</div>
</div>
</div>



<div class="site-related">
<div class="site-series-nav">
<p><a href="https://insightsurge-dev.web.app/series/foundations.html" class="site-series-nav__series">Foundations series · part 9 of 16</a></p>
<div class="site-card-grid site-series-nav__links">
<div class="site-card-cell">
<a href="https://insightsurge-dev.web.app/posts/issue-forms-pr-templates/index.html" class="is-card site-related-card site-series-nav__prev"><span class="is-card__eyebrow">Previous · part 8</span><span class="site-related-card__title">Issue forms, PR templates, labels &amp; milestones</span></a>
</div>
<div class="site-card-cell">
<a href="https://insightsurge-dev.web.app/posts/dependencies-runtime-vetting/index.html" class="is-card site-related-card site-series-nav__next"><span class="is-card__eyebrow">Next · part 10</span><span class="site-related-card__title">Dependency updates, runtime pinning &amp; package vetting</span></a>
</div>
</div>
</div>
<section id="keep-reading" class="level2 unnumbered unlisted no-anchor">
<h2 class="unnumbered unlisted no-anchor" data-anchor-id="keep-reading">Keep reading</h2>
<div class="site-link-list">
<ul>
<li><a href="https://insightsurge-dev.web.app/posts/r-submissions-pkglite/index.html" class="site-link-row" title="What the R Consortium R submission pilots to the FDA tested, and how {pkglite} packs R packages into plain text that an eCTD submission can carry."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">R in regulatory submissions and {pkglite}</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/validation-ready-r-packages/index.html" class="site-link-row" title="How to evaluate open-source R packages for GxP clinical reporting using the R Validation Hub risk-based framework, riskmetric, and documented evidence."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Validation-ready R packages</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/introducing-mascot/index.html" class="site-link-row" title="The mascot package is now on CRAN: add mood-driven characters to Shiny apps and Quarto pages, with visible status text, speech bubbles, click menus and reduced-motion support."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">mascot is on CRAN: live, mood-driven mascots for Shiny and Quarto</span></a></li>
</ul>
</div>
</section>
</div>

</section>

 ]]></description>
  <category>R packages</category>
  <category>GxP</category>
  <category>Git</category>
  <guid>https://insightsurge-dev.web.app/posts/releases-changelogs/</guid>
  <pubDate>Fri, 25 Sep 2026 18:30:00 GMT</pubDate>
</item>
<item>
  <title>Repo hygiene files</title>
  <link>https://insightsurge-dev.web.app/posts/repo-hygiene-files/</link>
  <description><![CDATA[ 





<!--
  Quarto 1.8.27's title-block.html with three changes: category badges and a
  series link ("Testing series · part 2") sit above the title, as in the brand's
  blog kit; and a post or series page with `trailer: true` shows its trailer beside the title
  (_filters/trailer.lua sets trailer-path; _includes/trailers.html plays it). On a Quarto upgrade, diff this against
  share/formats/html/templates/title-block.html and carry over any changes.
-->



<section id="what-each-file-is-for" class="level2">
<h2 class="anchored" data-anchor-id="what-each-file-is-for">What each file is for</h2>
<p>GitHub recognises several files by name and surfaces them in the UI: on the repo home page, the <em>New issue</em> page, the <em>Security</em> tab, and next to the PR form. Each one answers a question that would otherwise become a message to you.</p>
<div class="table-responsive">
<table class="caption-top table">
<colgroup>
<col style="width: 25%">
<col style="width: 25%">
<col style="width: 25%">
<col style="width: 25%">
</colgroup>
<thead>
<tr class="header">
<th>File</th>
<th>Answers</th>
<th>GitHub surfaces it</th>
<th>R helper</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><code>README</code></td>
<td>What is this, how do I install and use it?</td>
<td>Repo home</td>
<td><code>usethis::use_readme_rmd()</code> / <code>use_readme_md()</code></td>
</tr>
<tr class="even">
<td><code>LICENSE</code></td>
<td>May I use this?</td>
<td>License badge / sidebar</td>
<td><code>use_mit_license()</code>, <code>use_proprietary_license(copyright_holder)</code></td>
</tr>
<tr class="odd">
<td><code>CONTRIBUTING.md</code></td>
<td>How do I set up, branch, commit and get a PR merged?</td>
<td>Link on new issue/PR</td>
<td><code>use_tidy_contributing()</code></td>
</tr>
<tr class="even">
<td><code>SECURITY.md</code></td>
<td>How do I report a vulnerability privately?</td>
<td><em>Security</em> tab</td>
<td>— (write it)</td>
</tr>
<tr class="odd">
<td><code>CODE_OF_CONDUCT.md</code></td>
<td>How do we treat each other?</td>
<td>Community profile</td>
<td><code>use_code_of_conduct(contact)</code></td>
</tr>
<tr class="even">
<td><code>SUPPORT.md</code></td>
<td>Where do I ask questions?</td>
<td>Link on new issue</td>
<td><code>use_tidy_support()</code></td>
</tr>
<tr class="odd">
<td><code>.editorconfig</code></td>
<td>Indentation, line endings, final newline</td>
<td>Editors that support EditorConfig</td>
<td>—</td>
</tr>
<tr class="even">
<td><code>.gitignore</code> / <code>.Rbuildignore</code></td>
<td>What never goes into git / the tarball</td>
<td>—</td>
<td><code>use_git_ignore()</code>, <code>use_build_ignore()</code></td>
</tr>
</tbody>
</table>
</div>
<p>GitHub looks for the community files in the repo <strong>root</strong>, <strong><code>.github/</code></strong> or <strong><code>docs/</code></strong>. In R packages, prefer <code>.github/</code>, which stays out of the build with <code>use_build_ignore(".github")</code>.</p>
</section>
<section id="what-we-wrote-for-the-website" class="level2">
<h2 class="anchored" data-anchor-id="what-we-wrote-for-the-website">What we wrote for the website</h2>
<ul>
<li><strong>CONTRIBUTING.md:</strong> setup (<code>npm install</code> also installs hooks); the branch → Conventional Commit → PR → squash workflow; a table of every check, what it does and where it runs; how releases happen; and the ground rules (no client names or data, no secrets, ADRs for decisions).</li>
<li><strong>SECURITY.md:</strong> “don’t open a public issue”, how to reach the maintainers, a response target, and a link to the secrets standard.</li>
<li><strong>LICENSE:</strong> proprietary, all rights reserved (the repo is private company code).</li>
<li><strong>.editorconfig:</strong> UTF-8, LF line endings, 2-space indent, final newline, and trailing whitespace trimmed (except in Markdown, where two trailing spaces can mean a line break).</li>
<li><strong>.env.example:</strong> every environment variable name, with no values (<a href="https://insightsurge-dev.web.app/posts/secrets-management/index.html">secrets management</a>).</li>
</ul>
</section>
<section id="the-r-version" class="level2">
<h2 class="anchored" data-anchor-id="the-r-version">The R version</h2>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r norun code-with-copy"><code class="sourceCode r"><span id="cb1-1">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">use_readme_rmd</span>()                          <span class="co" style="color: #5E5E5E;"># README.Rmd -&gt; README.md (knit to update)</span></span>
<span id="cb1-2">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">use_proprietary_license</span>(<span class="st" style="color: #20794D;">"Acme Analytics"</span>) <span class="co" style="color: #5E5E5E;"># or use_mit_license() for open source</span></span>
<span id="cb1-3">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">use_tidy_github</span>()                         <span class="co" style="color: #5E5E5E;"># CONTRIBUTING, issue template, SUPPORT, CoC in .github/</span></span>
<span id="cb1-4">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">use_build_ignore</span>(<span class="fu" style="color: #4758AB;">c</span>(<span class="st" style="color: #20794D;">".github"</span>, <span class="st" style="color: #20794D;">".editorconfig"</span>))</span></code></pre></div></div>
<p>A CONTRIBUTING.md for an internal R package should at least say:</p>
<ul>
<li>how to get a working environment (<code>renv::restore()</code>, the R version, <code>precommit::use_precommit()</code>);</li>
<li>the <a href="https://insightsurge-dev.web.app/posts/git-workflow/index.html">branch/PR workflow</a> and the <a href="https://insightsurge-dev.web.app/posts/conventional-commits-pr-titles/index.html">PR-title convention</a>;</li>
<li>what CI checks and how to reproduce it locally (<code>devtools::check()</code>, <code>lintr::lint_package()</code>);</li>
<li>when to add a <code>NEWS.md</code> bullet (<a href="https://insightsurge-dev.web.app/posts/releases-changelogs/index.html">releases &amp; changelogs</a>);</li>
<li>the data rule: <strong>synthetic or public data only</strong> in code, tests and issues.</li>
</ul>
</section>
<section id="pitfalls" class="level2">
<h2 class="anchored" data-anchor-id="pitfalls">Pitfalls</h2>
<ul>
<li><strong>README.Rmd drift.</strong> Edit the <code>.Rmd</code>, knit, and commit both. The <code>readme-rmd-rendered</code> pre-commit hook (<a href="https://insightsurge-dev.web.app/posts/hooks-formatting-linting/index.html">pre-commit hooks, formatting &amp; linting</a>) catches it if you forget.</li>
<li><strong>Copy-pasted CONTRIBUTING from an open-source template</strong> that tells internal colleagues to fork. Tailor it.</li>
<li><strong>A SECURITY.md with no working contact</strong> is worse than none. Keep it current.</li>
<li><strong>Licence ambiguity</strong> on internal code. Say “proprietary” explicitly. No LICENSE file isn’t the same as a clear statement.</li>
</ul>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<p><strong>GitHub</strong></p>
<ul>
<li><strong>Community health files (README, LICENSE, CONTRIBUTING, SECURITY, CODE_OF_CONDUCT, SUPPORT)</strong>: <a href="https://docs.github.com/en/communities/setting-up-your-project-for-healthy-contributions/creating-a-default-community-health-file">GitHub Docs: Creating a default community health file</a></li>
<li><strong>About READMEs</strong>: <a href="https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-readmes">GitHub Docs</a></li>
<li><strong>Licensing a repository</strong>: <a href="https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/licensing-a-repository">GitHub Docs</a></li>
<li><strong>Adding a security policy (<code>SECURITY.md</code>)</strong>: <a href="https://docs.github.com/en/code-security/getting-started/adding-a-security-policy-to-your-repository">GitHub Docs</a></li>
<li><strong>Adding a code of conduct</strong>: <a href="https://docs.github.com/en/communities/setting-up-your-project-for-healthy-contributions/adding-a-code-of-conduct-to-your-project">GitHub Docs</a></li>
</ul>
<p><strong>Other</strong></p>
<ul>
<li><strong>EditorConfig</strong>: <a href="https://editorconfig.org/">editorconfig.org</a></li>
</ul>
<p><strong>R package documentation</strong></p>
<ul>
<li><strong>usethis</strong> (<code>use_readme_rmd()</code>, <code>use_mit_license()</code>, <code>use_proprietary_license()</code>, <code>use_tidy_github()</code>, <code>use_code_of_conduct()</code>, <code>use_tidy_support()</code>, <code>use_git_ignore()</code>, <code>use_build_ignore()</code>): <a href="https://usethis.r-lib.org/">usethis.r-lib.org</a></li>
</ul>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Updates
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<ul>
<li><strong>2026-09-26:</strong> Removed the end-of-post checklist. Marked package-dependent usethis block as .norun.</li>
<li><strong>2026-09-27:</strong> Added a Sources section.</li>
</ul>
</div>
</div>
</div>



<div class="site-related">
<div class="site-series-nav">
<p><a href="https://insightsurge-dev.web.app/series/foundations.html" class="site-series-nav__series">Foundations series · part 13 of 16</a></p>
<div class="site-card-grid site-series-nav__links">
<div class="site-card-cell">
<a href="https://insightsurge-dev.web.app/posts/adrs-and-evidence/index.html" class="is-card site-related-card site-series-nav__prev"><span class="is-card__eyebrow">Previous · part 12</span><span class="site-related-card__title">ADRs &amp; evidence: record decisions, verify docs</span></a>
</div>
<div class="site-card-cell">
<a href="https://insightsurge-dev.web.app/posts/handoffs-agentic-context/index.html" class="is-card site-related-card site-series-nav__next"><span class="is-card__eyebrow">Next · part 14</span><span class="site-related-card__title">Handoffs &amp; agentic context</span></a>
</div>
</div>
</div>
<section id="keep-reading" class="level2 unnumbered unlisted no-anchor">
<h2 class="unnumbered unlisted no-anchor" data-anchor-id="keep-reading">Keep reading</h2>
<div class="site-link-list">
<ul>
<li><a href="https://insightsurge-dev.web.app/posts/issue-forms-pr-templates/index.html" class="site-link-row" title="Use structured issue forms, PR templates, and labels to capture reproducible examples and review criteria up front."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Issue forms, PR templates, labels &amp; milestones</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/releases-changelogs/index.html" class="site-link-row" title="Adopt semantic versioning, readable changelogs, and annotated git tags to support change control."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Releases &amp; changelogs</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/from-scripts-to-a-package/index.html" class="site-link-row" title="Move reusable analysis helpers from sourced scripts into a minimal R package, and replace workspace pollution with the devtools::load_all() loop."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">From scripts to a package</span></a></li>
</ul>
</div>
</section>
</div>

</section>

 ]]></description>
  <category>R packages</category>
  <category>Git</category>
  <category>Best practices</category>
  <guid>https://insightsurge-dev.web.app/posts/repo-hygiene-files/</guid>
  <pubDate>Fri, 25 Sep 2026 18:30:00 GMT</pubDate>
</item>
<item>
  <title>Secret scanning with gitleaks</title>
  <link>https://insightsurge-dev.web.app/posts/secret-scanning/</link>
  <description><![CDATA[ 





<!--
  Quarto 1.8.27's title-block.html with three changes: category badges and a
  series link ("Testing series · part 2") sit above the title, as in the brand's
  blog kit; and a post or series page with `trailer: true` shows its trailer beside the title
  (_filters/trailer.lua sets trailer-path; _includes/trailers.html plays it). On a Quarto upgrade, diff this against
  share/formats/html/templates/title-block.html and carry over any changes.
-->



<section id="the-problem" class="level2">
<h2 class="anchored" data-anchor-id="the-problem">The problem</h2>
<p>Secrets end up in git through ordinary days, not carelessness:</p>
<ul>
<li><code>Sys.setenv(GITHUB_PAT = "ghp_…")</code> typed in the console, saved to <strong><code>.Rhistory</code></strong>, committed;</li>
<li>a project <strong><code>.Renviron</code></strong> committed along with everything else in <code>git add -A</code>;</li>
<li>a Quarto or R Markdown report that printed <code>Sys.getenv()</code> while debugging, saved in <strong><code>_freeze/</code></strong> or the rendered HTML;</li>
<li>a database connection string pasted into a script “just for now”.</li>
</ul>
<p>Once pushed, deleting the file <strong>does not remove the secret</strong>. It stays in history, in every clone and fork, and in GitHub’s references for PRs. We saw this ourselves: after deleting a test branch, its commit was still served by the GitHub API through the closed PR.</p>
<p><strong>The first response to a leak is to rotate the secret, not to rewrite history.</strong></p>
</section>
<section id="what-secret-scanning-does" class="level2">
<h2 class="anchored" data-anchor-id="what-secret-scanning-does">What secret scanning does</h2>
<p>A scanner reads diffs (and optionally the whole history) and matches them against a large built-in set of rules for known token formats. Examples are GitHub PATs (<code>ghp_…</code>), AWS keys, Google API keys and private-key headers. It also checks entropy, which catches random-looking strings. It then fails the build and points at the file and line.</p>
<p><a href="https://github.com/gitleaks/gitleaks">gitleaks</a> is the widely used open-source scanner. It is one Go binary with a GitHub Action and a pre-commit hook.</p>
</section>
<section id="the-web-repo-way-gitleaks-in-ci" class="level2">
<h2 class="anchored" data-anchor-id="the-web-repo-way-gitleaks-in-ci">The web-repo way: gitleaks in CI</h2>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb1-1"><span class="co" style="color: #5E5E5E;"># .github/workflows/gitleaks.yml</span></span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;">on</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-3"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">pull_request</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-4"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">push</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-5"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">branches</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="kw" style="color: #003B4F;
font-weight: bold;">[</span><span class="at" style="color: #657422;">main</span><span class="kw" style="color: #003B4F;
font-weight: bold;">]</span></span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;">permissions</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-7"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">contents</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> read</span></span>
<span id="cb1-8"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">pull-requests</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> write</span><span class="co" style="color: #5E5E5E;">          # lets it comment on the offending line</span></span>
<span id="cb1-9"><span class="fu" style="color: #4758AB;">jobs</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-10"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">scan</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-11"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">runs-on</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> ubuntu-latest</span></span>
<span id="cb1-12"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">steps</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-13"><span class="at" style="color: #657422;">      </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">uses</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> actions/checkout@v7</span></span>
<span id="cb1-14"><span class="at" style="color: #657422;">        </span><span class="fu" style="color: #4758AB;">with</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-15"><span class="at" style="color: #657422;">          </span><span class="fu" style="color: #4758AB;">fetch-depth</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="dv" style="color: #AD0000;">0</span><span class="co" style="color: #5E5E5E;">        # scan the full history, not just the tip</span></span>
<span id="cb1-16"><span class="at" style="color: #657422;">      </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">uses</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> gitleaks/gitleaks-action@v3</span></span>
<span id="cb1-17"><span class="at" style="color: #657422;">        </span><span class="fu" style="color: #4758AB;">env</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb1-18"><span class="at" style="color: #657422;">          </span><span class="fu" style="color: #4758AB;">GITHUB_TOKEN</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> ${{ secrets.GITHUB_TOKEN }}</span></span>
<span id="cb1-19"><span class="co" style="color: #5E5E5E;">          # GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }}   # organisation repos only</span></span></code></pre></div></div>
<p><strong>Licensing, checked in the action’s README (v3):</strong> repos on a <em>personal</em> account need no licence. Repos owned by an <em>organisation</em> need a free licence key from gitleaks.io, stored as the <code>GITLEAKS_LICENSE</code> secret.</p>
<p><strong>Proving it works.</strong> We planted a random, never-valid <code>ghp_</code> token in a throwaway PR. gitleaks failed with rule <code>github-pat</code> and pointed at the exact file. A clean PR passed. Run the same test once in every new repo (<a href="https://insightsurge-dev.web.app/posts/test-your-guardrails/index.html">test your guardrails</a>).</p>
</section>
<section id="why-not-githubs-built-in-secret-scanning" class="level2">
<h2 class="anchored" data-anchor-id="why-not-githubs-built-in-secret-scanning">Why not GitHub’s built-in secret scanning?</h2>
<p>GitHub’s own secret scanning and push protection are <strong>free on public repositories</strong>. On <strong>private</strong> repositories they need the paid <em>GitHub Secret Protection</em> add-on, according to GitHub’s docs at the time of writing. Most internal R packages and Shiny apps are private, so gitleaks in CI is the no-cost baseline. If your organisation already pays for Secret Protection, turn on push protection <em>as well</em>: it blocks the push itself.</p>
</section>
<section id="the-r-way" class="level2">
<h2 class="anchored" data-anchor-id="the-r-way">The R way</h2>
<section id="keep-the-usual-suspects-out-of-git" class="level3">
<h3 class="anchored" data-anchor-id="keep-the-usual-suspects-out-of-git">1. Keep the usual suspects out of git</h3>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">git_vaccinate</span>()   <span class="co" style="color: #5E5E5E;"># user-level gitignore: .Rhistory, .Rdata, .httr-oauth, .Rproj.user, .DS_Store, .quarto</span></span></code></pre></div></div>
<div class="callout callout-style-default callout-warning callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Warning</span><code>git_vaccinate()</code> does not ignore <code>.Renviron</code>
</div>
</div>
<div class="callout-body-container callout-body">
<p>We checked the list it writes (<code>usethis</code> 3.1.0). <strong><code>.Renviron</code> isn’t on it</strong>, yet it’s the most likely file to hold a token (<a href="https://insightsurge-dev.web.app/posts/identity-isolation/index.html">identity and environment isolation</a>). Add it yourself, per project:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r norun code-with-copy"><code class="sourceCode r"><span id="cb3-1">usethis<span class="sc" style="color: #5E5E5E;">::</span><span class="fu" style="color: #4758AB;">use_git_ignore</span>(<span class="st" style="color: #20794D;">".Renviron"</span>)</span></code></pre></div></div>
</div>
</div>
<p>Better still, never type a secret in the console. Put it in the project <code>.Renviron</code> (<code>usethis::edit_r_environ(scope = "project")</code>, <a href="https://insightsurge-dev.web.app/posts/secrets-management/index.html">secrets management</a>) and read it with <code>Sys.getenv()</code>. Then there’s nothing for <code>.Rhistory</code> to capture.</p>
</section>
<section id="add-the-ci-scan" class="level3">
<h3 class="anchored" data-anchor-id="add-the-ci-scan">2. Add the CI scan</h3>
<p>Copy <a href="https://insightsurge-dev.web.app/templates/github/workflows/gitleaks.yml"><code>templates/github/workflows/gitleaks.yml</code></a> to <code>.github/workflows/</code>. It needs nothing from R, so it works for packages, Shiny apps, Quarto sites and analysis repos alike.</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center collapsed" data-bs-toggle="collapse" data-bs-target=".callout-2-contents" aria-controls="callout-2" aria-expanded="false" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Full template: <code>gitleaks.yml</code>
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-2" class="callout-2-contents callout-collapse collapse">
<div class="callout-body-container callout-body">
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb4-1"><span class="co" style="color: #5E5E5E;"># Drop into .github/workflows/. Scans the full git history of every PR and push.</span></span>
<span id="cb4-2"><span class="co" style="color: #5E5E5E;"># Personal-account repos need no licence. Organisation repos need a free</span></span>
<span id="cb4-3"><span class="co" style="color: #5E5E5E;"># GITLEAKS_LICENSE secret from gitleaks.io (uncomment the line below).</span></span>
<span id="cb4-4"><span class="fu" style="color: #4758AB;">name</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> gitleaks</span></span>
<span id="cb4-5"></span>
<span id="cb4-6"><span class="fu" style="color: #4758AB;">on</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-7"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">pull_request</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-8"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">push</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-9"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">branches</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="kw" style="color: #003B4F;
font-weight: bold;">[</span><span class="at" style="color: #657422;">main</span><span class="kw" style="color: #003B4F;
font-weight: bold;">]</span></span>
<span id="cb4-10"></span>
<span id="cb4-11"><span class="fu" style="color: #4758AB;">permissions</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-12"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">contents</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> read</span></span>
<span id="cb4-13"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">pull-requests</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> write</span><span class="co" style="color: #5E5E5E;">   # lets the action comment on the offending line</span></span>
<span id="cb4-14"></span>
<span id="cb4-15"><span class="fu" style="color: #4758AB;">jobs</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-16"><span class="at" style="color: #657422;">  </span><span class="fu" style="color: #4758AB;">scan</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-17"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">runs-on</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> ubuntu-latest</span></span>
<span id="cb4-18"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">steps</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-19"><span class="at" style="color: #657422;">      </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">uses</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> actions/checkout@v7</span></span>
<span id="cb4-20"><span class="at" style="color: #657422;">        </span><span class="fu" style="color: #4758AB;">with</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-21"><span class="at" style="color: #657422;">          </span><span class="fu" style="color: #4758AB;">fetch-depth</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> </span><span class="dv" style="color: #AD0000;">0</span><span class="co" style="color: #5E5E5E;">   # full history, not just the latest commit</span></span>
<span id="cb4-22"><span class="at" style="color: #657422;">      </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">uses</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> gitleaks/gitleaks-action@v3</span></span>
<span id="cb4-23"><span class="at" style="color: #657422;">        </span><span class="fu" style="color: #4758AB;">env</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb4-24"><span class="at" style="color: #657422;">          </span><span class="fu" style="color: #4758AB;">GITHUB_TOKEN</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> ${{ secrets.GITHUB_TOKEN }}</span></span>
<span id="cb4-25"><span class="co" style="color: #5E5E5E;">          # GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }}</span></span></code></pre></div></div>
</div>
</div>
</div>
</section>
<section id="scan-before-the-commit-exists" class="level3">
<h3 class="anchored" data-anchor-id="scan-before-the-commit-exists">3. Scan before the commit exists</h3>
<p>CI catches a leak <strong>after</strong> it has reached GitHub. We saw that first-hand: our initial pre-commit hook only formatted code, so a planted test token passed pre-commit and was only caught once it reached CI.</p>
<p>To close this gap before commits leave your laptop:</p>
<ul>
<li><strong>In npm/JavaScript repos:</strong> We use <strong>secretlint</strong> configured via <code>lint-staged</code> (<code>"*" : ["secretlint --maskSecrets"]</code>) with <code>@secretlint/secretlint-rule-preset-recommend</code> in <code>.secretlintrc.json</code>. In our probe, staging a fake <code>ghp_</code> token was blocked immediately before the commit existed (<code>[GITHUB_TOKEN] found GitHub Token</code>, masked).</li>
<li><strong>In R repos:</strong> gitleaks ships a hook for the <a href="https://pre-commit.com">pre-commit</a> framework, which R users often run via the <a href="https://lorenzwalthert.github.io/precommit/"><code>precommit</code></a> package:</li>
</ul>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb5-1"><span class="co" style="color: #5E5E5E;"># .pre-commit-config.yaml</span></span>
<span id="cb5-2"><span class="fu" style="color: #4758AB;">repos</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb5-3"><span class="at" style="color: #657422;">  </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">repo</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> https://github.com/gitleaks/gitleaks</span></span>
<span id="cb5-4"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">rev</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> v8.30.1</span></span>
<span id="cb5-5"><span class="at" style="color: #657422;">    </span><span class="fu" style="color: #4758AB;">hooks</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span></span>
<span id="cb5-6"><span class="at" style="color: #657422;">      </span><span class="kw" style="color: #003B4F;
font-weight: bold;">-</span><span class="at" style="color: #657422;"> </span><span class="fu" style="color: #4758AB;">id</span><span class="kw" style="color: #003B4F;
font-weight: bold;">:</span><span class="at" style="color: #657422;"> gitleaks</span><span class="co" style="color: #5E5E5E;">        # runs: gitleaks git --pre-commit --redact --staged</span></span></code></pre></div></div>
<p>The <code>gitleaks</code> hook builds gitleaks from source with Go (or <code>gitleaks-docker</code> uses a container). Whichever local hook you use, <strong>CI remains the gate</strong>.</p>
</section>
</section>
<section id="false-positives" class="level2">
<h2 class="anchored" data-anchor-id="false-positives">False positives</h2>
<p>Test fixtures sometimes contain things that <em>look</em> like secrets. Two escape hatches, both reviewable in a PR:</p>
<ul>
<li>an inline <code>#gitleaks:allow</code> comment on that line;</li>
<li>a <code>.gitleaksignore</code> file listing the finding’s fingerprint.</li>
</ul>
<p>Never “fix” a finding by disabling the workflow.</p>
</section>
<section id="if-it-fires-on-a-real-secret" class="level2">
<h2 class="anchored" data-anchor-id="if-it-fires-on-a-real-secret">If it fires on a real secret</h2>
<ol type="1">
<li><strong>Rotate or revoke it at the source now.</strong> Assume it’s compromised.</li>
<li>Replace the value wherever it’s legitimately used (<code>.Renviron</code>, Connect env vars, Secret Manager).</li>
<li>Remove it from the code in a normal PR.</li>
<li>Record what leaked, when, and what you rotated. In GxP terms this is a deviation with a CAPA.</li>
</ol>
<p>Rewriting history is optional clean-up. It doesn’t undo the exposure.</p>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<p><strong>Tools</strong></p>
<ul>
<li><strong>gitleaks</strong>: <a href="https://github.com/gitleaks/gitleaks">github.com/gitleaks/gitleaks</a></li>
<li><strong>gitleaks-action licensing (free for personal accounts, licence key for organisations)</strong>: <a href="https://github.com/gitleaks/gitleaks-action">github.com/gitleaks/gitleaks-action</a></li>
<li><strong>secretlint</strong>: <a href="https://github.com/secretlint/secretlint">github.com/secretlint/secretlint</a></li>
<li><strong>pre-commit framework</strong>: <a href="https://pre-commit.com/">pre-commit.com</a></li>
<li><strong>precommit</strong> (R): <a href="https://lorenzwalthert.github.io/precommit/">lorenzwalthert.github.io/precommit</a></li>
</ul>
<p><strong>GitHub’s built-in scanning</strong></p>
<ul>
<li><strong>About secret scanning</strong>: <a href="https://docs.github.com/en/code-security/secret-scanning/introduction/about-secret-scanning">GitHub Docs</a></li>
<li><strong>About push protection</strong>: <a href="https://docs.github.com/en/code-security/secret-scanning/introduction/about-push-protection">GitHub Docs</a></li>
<li><strong>GitHub Secret Protection pricing (free on public repos, paid add-on on private repos)</strong>: <a href="https://docs.github.com/en/code-security/securing-your-organization/understanding-your-organizations-exposure-to-leaked-secrets/choosing-github-secret-protection">GitHub Docs: Choosing GitHub Secret Protection</a></li>
</ul>
<p><strong>R package documentation</strong></p>
<ul>
<li><strong>usethis</strong> (<code>git_vaccinate()</code>, <code>use_git_ignore()</code>): <a href="https://usethis.r-lib.org/">usethis.r-lib.org</a></li>
</ul>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-3-contents" aria-controls="callout-3" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Updates
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-3" class="callout-3-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<ul>
<li><strong>2026-09-26:</strong> Closed the pre-commit gap identified during initial probe testing in our npm-based repo using <strong>secretlint</strong> (<code>secretlint --maskSecrets</code> via <code>lint-staged</code> with <code>@secretlint/secretlint-rule-preset-recommend</code>). A re-probe with a fake <code>ghp_</code> token was blocked immediately before commit creation (<code>[GITHUB_TOKEN] found GitHub Token</code>, masked), while R repos continue using the gitleaks pre-commit hook.</li>
<li><strong>2026-09-26:</strong> Removed the end-of-post checklist. Marked project-dependent usethis block as .norun.</li>
<li><strong>2026-09-27:</strong> Added a Sources section.</li>
<li><strong>2026-09-27:</strong> Linked every template file and showed it on the page.</li>
</ul>
</div>
</div>
</div>



<div class="site-related">
<div class="site-series-nav">
<p><a href="https://insightsurge-dev.web.app/series/foundations.html" class="site-series-nav__series">Foundations series · part 6 of 16</a></p>
<div class="site-card-grid site-series-nav__links">
<div class="site-card-cell">
<a href="https://insightsurge-dev.web.app/posts/ci-github-actions/index.html" class="is-card site-related-card site-series-nav__prev"><span class="is-card__eyebrow">Previous · part 5</span><span class="site-related-card__title">CI with GitHub Actions</span></a>
</div>
<div class="site-card-cell">
<a href="https://insightsurge-dev.web.app/posts/secrets-management/index.html" class="is-card site-related-card site-series-nav__next"><span class="is-card__eyebrow">Next · part 7</span><span class="site-related-card__title">Secrets management</span></a>
</div>
</div>
</div>
<section id="keep-reading" class="level2 unnumbered unlisted no-anchor">
<h2 class="unnumbered unlisted no-anchor" data-anchor-id="keep-reading">Keep reading</h2>
<div class="site-link-list">
<ul>
<li><a href="https://insightsurge-dev.web.app/posts/keyless-ci-auth-oidc/index.html" class="site-link-row" title="Use OpenID Connect and Google Cloud Workload Identity Federation to authenticate CI pipelines without long-lived JSON keys."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Keyless deploys: let CI prove who it is (OIDC)</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/shinytest2-end-to-end/index.html" class="site-link-row" title="Drive Shiny applications end to end with shinytest2 and headless Chrome, testing real browser rendering, user input sequences, and reactive outputs."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">End-to-end Shiny tests with shinytest2</span></a></li>
</ul>
</div>
</section>
</div>

</section>

 ]]></description>
  <category>Security</category>
  <category>R</category>
  <category>CI/CD</category>
  <guid>https://insightsurge-dev.web.app/posts/secret-scanning/</guid>
  <pubDate>Fri, 25 Sep 2026 18:30:00 GMT</pubDate>
</item>
<item>
  <title>Test your guardrails: probe PRs</title>
  <link>https://insightsurge-dev.web.app/posts/test-your-guardrails/</link>
  <description><![CDATA[ 





<!--
  Quarto 1.8.27's title-block.html with three changes: category badges and a
  series link ("Testing series · part 2") sit above the title, as in the brand's
  blog kit; and a post or series page with `trailer: true` shows its trailer beside the title
  (_filters/trailer.lua sets trailer-path; _includes/trailers.html plays it). On a Quarto upgrade, diff this against
  share/formats/html/templates/title-block.html and carry over any changes.
-->



<section id="the-idea" class="level2">
<h2 class="anchored" data-anchor-id="the-idea">The idea</h2>
<p>After setting up hooks and CI, it’s tempting to open one clean PR, see green ticks and move on. But green only proves the checks <em>can pass</em>. It doesn’t prove they <strong>fail when they should</strong>. A misspelled trigger, a path filter, a <code>continue-on-error</code>, a missing licence key: any of these gives you a check that is always green.</p>
<p>So we <strong>challenge</strong> each guardrail on purpose, with throwaway PRs designed to fail.</p>
</section>
<section id="the-probes-we-ran" class="level2">
<h2 class="anchored" data-anchor-id="the-probes-we-ran">The probes we ran</h2>
<p>Each probe was a branch from <code>main</code> with one deliberate defect, opened as a PR and <strong>closed unmerged</strong> afterwards:</p>
<div class="table-responsive">
<table class="caption-top table">
<colgroup>
<col style="width: 25%">
<col style="width: 25%">
<col style="width: 25%">
<col style="width: 25%">
</colgroup>
<thead>
<tr class="header">
<th>Probe</th>
<th>Defect</th>
<th>Expected</th>
<th>Observed</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Local</td>
<td>Commit message <code>initial stuff</code></td>
<td>commit-msg hook rejects</td>
<td>Rejected: <em>subject may not be empty, type may not be empty</em></td>
</tr>
<tr class="even">
<td>PR A</td>
<td>Title <code>updated the readme</code></td>
<td>PR-title check fails; others pass</td>
<td><em>No release type found in pull request title</em></td>
</tr>
<tr class="odd">
<td>PR B</td>
<td><code>const x: number = "not a number"</code></td>
<td>CI fails <strong>at the typecheck step</strong></td>
<td>Typecheck: failure; tests and build skipped; lint passed</td>
</tr>
<tr class="even">
<td>PR C</td>
<td>Random <code>ghp_…</code> token in a text file</td>
<td>Secret scan fails</td>
<td>gitleaks rule <code>github-pat</code>, pointing at the file</td>
</tr>
<tr class="odd">
<td>PR D</td>
<td>A harmless doc change</td>
<td>Everything passes</td>
<td>All green</td>
</tr>
</tbody>
</table>
</div>
<p>PR D matters as much as the others. It proves the checks aren’t simply broken and red for everything.</p>
</section>
<section id="read-the-log-not-the-colour" class="level2">
<h2 class="anchored" data-anchor-id="read-the-log-not-the-colour">Read the log, not the colour</h2>
<p>A red cross only proves <em>something</em> failed. For each probe we opened the log and confirmed it failed <strong>for the planted reason</strong>. PR B, for example, had to fail at <em>Typecheck</em>, not at lint or install. A probe that fails for the wrong reason tells you nothing about the guardrail. Track any gaps exposed by failing probes as engineering issues to resolve.</p>
</section>
<section id="what-the-probes-taught-us" class="level2">
<h2 class="anchored" data-anchor-id="what-the-probes-taught-us">What the probes taught us</h2>
<ul>
<li><strong>A gap resolved:</strong> the planted token initially passed the local pre-commit hook (which only formatted code) and was caught only in CI after being pushed. We followed up by integrating <strong>secretlint</strong> into pre-commit (<code>lint-staged</code>) and re-probed successfully: a fake <code>ghp_</code> token was blocked on the laptop before the commit could even be created (see <a href="https://insightsurge-dev.web.app/posts/secret-scanning/index.html">secret scanning</a>).</li>
<li><strong>A surprise:</strong> after deleting the probe branch, its commit was <strong>still served</strong> by the GitHub API through the closed PR. Deleting a branch doesn’t delete what was pushed. Only use <em>fake</em> secrets for probes.</li>
</ul>
</section>
<section id="the-r-version" class="level2">
<h2 class="anchored" data-anchor-id="the-r-version">The R version</h2>
<p>The same probes work for an R package or Shiny repo:</p>
<div class="table-responsive">
<table class="caption-top table">
<colgroup>
<col style="width: 50%">
<col style="width: 50%">
</colgroup>
<thead>
<tr class="header">
<th>Guardrail</th>
<th>Probe</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><code>R CMD check</code> workflow</td>
<td>A PR that adds <code>stop("probe")</code> inside a tested function, or an undeclared <code>pkg::fn()</code></td>
</tr>
<tr class="even">
<td><code>lintr</code> / Air check</td>
<td>A PR with <code>x = 1</code> and a 200-character line</td>
</tr>
<tr class="odd">
<td><code>shinytest2</code> snapshots</td>
<td>A PR that changes a UI label without updating the snapshot</td>
</tr>
<tr class="even">
<td>PR-title check</td>
<td><code>updated stuff</code></td>
</tr>
<tr class="odd">
<td>gitleaks</td>
<td>A fake <code>ghp_</code> + 36 random characters (never a real token)</td>
</tr>
<tr class="even">
<td>Coverage threshold</td>
<td>A PR that adds an untested function</td>
</tr>
</tbody>
</table>
</div>
<p>Generate a fake token that matches the pattern but has never existed:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb1-1"><span class="bu" style="color: null;">echo</span> <span class="st" style="color: #20794D;">"token=ghp_</span><span class="va" style="color: #111111;">$(LC_ALL</span><span class="op" style="color: #5E5E5E;">=</span>C <span class="fu" style="color: #4758AB;">tr</span> <span class="at" style="color: #657422;">-dc</span> <span class="st" style="color: #20794D;">'A-Za-z0-9'</span> <span class="op" style="color: #5E5E5E;">&lt;</span>/dev/urandom <span class="kw" style="color: #003B4F;
font-weight: bold;">|</span> <span class="fu" style="color: #4758AB;">head</span> <span class="at" style="color: #657422;">-c</span> 36<span class="va" style="color: #111111;">)</span><span class="st" style="color: #20794D;">"</span> <span class="op" style="color: #5E5E5E;">&gt;</span> leak-probe.txt</span></code></pre></div></div>
</section>
<section id="the-gxp-link-this-is-oq-for-your-own-quality-system" class="level2">
<h2 class="anchored" data-anchor-id="the-gxp-link-this-is-oq-for-your-own-quality-system">The GxP link: this is OQ for your own quality system</h2>
<p>Validation people will recognise this as <strong>challenge testing</strong>. In operational qualification you show an alarm trips at its limit, not just that it stays quiet in normal operation. Probe PRs are OQ for your development controls, and the closed PRs, with their logs, are the evidence. Re-run them when you change a workflow, runner or major action version.</p>
</section>
<section id="sources" class="level2">
<h2 class="anchored" data-anchor-id="sources">Sources</h2>
<p><strong>Tools used in the probes</strong></p>
<ul>
<li><strong>gitleaks</strong>: <a href="https://github.com/gitleaks/gitleaks">github.com/gitleaks/gitleaks</a></li>
<li><strong>secretlint</strong>: <a href="https://github.com/secretlint/secretlint">github.com/secretlint/secretlint</a></li>
<li><strong>shinytest2</strong>: <a href="https://rstudio.github.io/shinytest2/">rstudio.github.io/shinytest2</a></li>
</ul>
<section id="further-reading" class="level3">
<h3 class="anchored">Further reading</h3>
<ul>
<li><strong>GAMP 5 (2nd Edition)</strong>, the source of the operational-qualification (OQ) idea this post borrows: <a href="https://ispe.org/publications/guidance-documents/gamp-5-guide-2nd-edition">ispe.org</a></li>
</ul>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center" data-bs-toggle="collapse" data-bs-target=".callout-1-contents" aria-controls="callout-1" aria-expanded="true" aria-label="Toggle callout">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Updates
</div>
<div class="callout-btn-toggle d-inline-block border-0 py-1 ps-1 pe-0 float-end"><i class="callout-toggle"></i></div>
</div>
<div id="callout-1" class="callout-1-contents callout-collapse collapse show">
<div class="callout-body-container callout-body">
<ul>
<li><strong>2026-09-26:</strong> Closed the pre-commit scanning gap identified during initial probe testing. Added <strong>secretlint</strong> to the staged-files pre-commit pipeline (see <a href="https://insightsurge-dev.web.app/posts/secret-scanning/index.html">secret scanning</a>) and re-probed successfully: staged test tokens are blocked locally before commit creation.</li>
<li><strong>2026-09-26:</strong> Removed the end-of-post checklist.</li>
<li><strong>2026-09-27:</strong> Added a Sources section.</li>
</ul>
</div>
</div>
</div>



<div class="site-related">
<div class="site-series-nav">
<p><a href="https://insightsurge-dev.web.app/series/foundations.html" class="site-series-nav__series">Foundations series · part 11 of 16</a></p>
<div class="site-card-grid site-series-nav__links">
<div class="site-card-cell">
<a href="https://insightsurge-dev.web.app/posts/dependencies-runtime-vetting/index.html" class="is-card site-related-card site-series-nav__prev"><span class="is-card__eyebrow">Previous · part 10</span><span class="site-related-card__title">Dependency updates, runtime pinning &amp; package vetting</span></a>
</div>
<div class="site-card-cell">
<a href="https://insightsurge-dev.web.app/posts/adrs-and-evidence/index.html" class="is-card site-related-card site-series-nav__next"><span class="is-card__eyebrow">Next · part 12</span><span class="site-related-card__title">ADRs &amp; evidence: record decisions, verify docs</span></a>
</div>
</div>
</div>
<section id="keep-reading" class="level2 unnumbered unlisted no-anchor">
<h2 class="unnumbered unlisted no-anchor" data-anchor-id="keep-reading">Keep reading</h2>
<div class="site-link-list">
<ul>
<li><a href="https://insightsurge-dev.web.app/posts/coverage-and-test-evidence/index.html" class="site-link-row" title="Use covr to spot untested paths, export Cobertura and JUnit XML in CI, and build automated requirement traceability matrices."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Coverage and tests as evidence</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/git-workflow/index.html" class="site-link-row" title="A predictable branch-and-PR workflow for R teams with branch protection, squash merges, and signed commits."><span class="is-card__eyebrow site-link-row__label">Read first</span><span class="site-link-row__title">Git workflow: branches, squash-only merges, signed commits</span></a></li>
<li><a href="https://insightsurge-dev.web.app/posts/keyless-ci-auth-oidc/index.html" class="site-link-row" title="Use OpenID Connect and Google Cloud Workload Identity Federation to authenticate CI pipelines without long-lived JSON keys."><span class="is-card__eyebrow site-link-row__label">Related</span><span class="site-link-row__title">Keyless deploys: let CI prove who it is (OIDC)</span></a></li>
</ul>
</div>
</section>
</div>

</section>
</section>

 ]]></description>
  <category>CI/CD</category>
  <category>GxP</category>
  <category>Best practices</category>
  <guid>https://insightsurge-dev.web.app/posts/test-your-guardrails/</guid>
  <pubDate>Fri, 25 Sep 2026 18:30:00 GMT</pubDate>
</item>
</channel>
</rss>
