<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Github Actions on foosel.net</title><link>https://foosel.net/tags/github-actions/</link><description>Recent content in Github Actions on foosel.net</description><generator>Hugo</generator><language>en-us</language><copyright>Gina Häußge (foosel)</copyright><lastBuildDate>Tue, 31 Jan 2023 00:00:00 +0000</lastBuildDate><atom:link href="https://foosel.net/tags/github-actions/feed.xml" rel="self" type="application/rss+xml"/><item><title>How to run Playwright on GitHub Actions</title><link>https://foosel.net/til/how-to-run-playwright-on-github-actions/</link><pubDate>Tue, 31 Jan 2023 00:00:00 +0000</pubDate><guid>https://foosel.net/til/how-to-run-playwright-on-github-actions/</guid><description>&lt;p&gt;Running Playwright on GitHub Actions is fairly straightforward at first glance, however it becomes a bit more tricky when you don&amp;rsquo;t want to download the whole browser binary zoo on every single CI build.&lt;/p&gt;
&lt;p&gt;Looking around a bit on how to go about caching these, I came across various approaches listed in &lt;a href="https://github.com/microsoft/playwright/issues/7249"&gt;this GitHub issue on the Playwright repo&lt;/a&gt;. Below is the result of reading through most of them and figuring out what works best for me and my use case (OctoPrint&amp;rsquo;s E2E tests, &lt;code&gt;npm&lt;/code&gt; based test project).&lt;/p&gt;</description><content:encoded><![CDATA[<p>Running Playwright on GitHub Actions is fairly straightforward at first glance, however it becomes a bit more tricky when you don&rsquo;t want to download the whole browser binary zoo on every single CI build.</p>
<p>Looking around a bit on how to go about caching these, I came across various approaches listed in <a href="https://github.com/microsoft/playwright/issues/7249">this GitHub issue on the Playwright repo</a>. Below is the result of reading through most of them and figuring out what works best for me and my use case (OctoPrint&rsquo;s E2E tests, <code>npm</code> based test project).</p>
<p>These steps make sure to install Playwright, fetching the browser binaries from cache if possible, in any case installing the OS depencies, running the tests (replace <code>./path/to/tests</code> accordingly for your setup) and finally upload the generated report as artifact, regardless of whether the tests succeeded or not:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#75715e"># Run npm ci and get Playwright version</span>
</span></span><span style="display:flex;"><span>- <span style="color:#f92672">name</span>: <span style="color:#ae81ff">🏗 Prepare Playwright env</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">working-directory</span>: <span style="color:#ae81ff">./path/to/tests</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">run</span>: |<span style="color:#e6db74">
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">    npm ci
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">    PLAYWRIGHT_VERSION=$(npm ls --json @playwright/test | jq --raw-output &#39;.dependencies[&#34;@playwright/test&#34;].version&#39;)
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">    echo &#34;PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION&#34; &gt;&gt; $GITHUB_ENV</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Cache browser binaries, cache key is based on Playwright version and OS</span>
</span></span><span style="display:flex;"><span>- <span style="color:#f92672">name</span>: <span style="color:#ae81ff">🧰 Cache Playwright browser binaries</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">actions/cache@v3</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">id</span>: <span style="color:#ae81ff">playwright-cache</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">with</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">path</span>: <span style="color:#e6db74">&#34;~/.cache/ms-playwright&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">key</span>: <span style="color:#e6db74">&#34;${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">restore-keys</span>: |<span style="color:#e6db74">
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">      ${{ runner.os }}-playwright-</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Install browser binaries &amp; OS dependencies if cache missed</span>
</span></span><span style="display:flex;"><span>- <span style="color:#f92672">name</span>: <span style="color:#ae81ff">🏗 Install Playwright browser binaries &amp; OS dependencies</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">if</span>: <span style="color:#ae81ff">steps.playwright-cache.outputs.cache-hit != &#39;true&#39;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">working-directory</span>: <span style="color:#ae81ff">./path/to/tests</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">run</span>: |<span style="color:#e6db74">
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">    npx playwright install --with-deps</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Install only the OS dependencies if cache hit</span>
</span></span><span style="display:flex;"><span>- <span style="color:#f92672">name</span>: <span style="color:#ae81ff">🏗 Install Playwright OS dependencies</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">if</span>: <span style="color:#ae81ff">steps.playwright-cache.outputs.cache-hit == &#39;true&#39;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">working-directory</span>: <span style="color:#ae81ff">./path/to/tests</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">run</span>: |<span style="color:#e6db74">
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">    npx playwright install-deps</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>- <span style="color:#f92672">name</span>: <span style="color:#ae81ff">🚀 Run Playwright</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">working-directory</span>: <span style="color:#ae81ff">./path/to/tests</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">run</span>: |<span style="color:#e6db74">
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">    npx playwright test</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>- <span style="color:#f92672">name</span>: <span style="color:#ae81ff">⬆ Upload report</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">actions/upload-artifact@v3</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">if</span>: <span style="color:#ae81ff">always()</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">with</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">name</span>: <span style="color:#ae81ff">playwright-report</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">path</span>: <span style="color:#ae81ff">tests/playwright/playwright-report</span>
</span></span></code></pre></div>]]></content:encoded></item></channel></rss>