<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Jorge Barata</title>
    <description>The latest articles on Forem by Jorge Barata (@neuralhacker).</description>
    <link>https://forem.com/neuralhacker</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F459302%2Fa2e6cc60-7e55-4bea-a90d-bbadbb34ba6d.png</url>
      <title>Forem: Jorge Barata</title>
      <link>https://forem.com/neuralhacker</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/neuralhacker"/>
    <language>en</language>
    <item>
      <title>Stateful Action: keep the state between runs</title>
      <dc:creator>Jorge Barata</dc:creator>
      <pubDate>Thu, 27 Aug 2020 17:58:02 +0000</pubDate>
      <link>https://forem.com/neuralhacker/stateful-action-4iga</link>
      <guid>https://forem.com/neuralhacker/stateful-action-4iga</guid>
      <description>&lt;p&gt;This is my entry for the &lt;a href="https://dev.to/devteam/announcing-the-github-actions-hackathon-on-dev-3ljn"&gt;GitHub Actions Hackathon on DEV&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/marketplace/actions/stateful-action"&gt;💾 Stateful Action&lt;/a&gt;&lt;/strong&gt; persists the data into a &lt;strong&gt;branch&lt;/strong&gt; after every run, letting the actions &lt;strong&gt;keep a state between runs&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I use this utility to periodically run &lt;strong&gt;reports&lt;/strong&gt;, &lt;strong&gt;crawlers&lt;/strong&gt;, and &lt;strong&gt;bots&lt;/strong&gt; that live entirely as a GitHub repository. They keep the state of the progress in a branch. Some of them store the information in a SQLite database file. I also the action for publishing the results in the GitHub pages branch.&lt;/p&gt;

&lt;p&gt;The action squashes the oldest commits, so the repository size doesn't grow wildly.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does it work?
&lt;/h2&gt;

&lt;p&gt;The action stores the information in a folder that is also a branch, using a git &lt;a href="https://git-scm.com/docs/git-worktree"&gt;worktree&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;It wraps the run like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;state&lt;/code&gt; branch is checked out as a &lt;a href="https://git-scm.com/docs/git-worktree"&gt;worktree&lt;/a&gt; under a folder named &lt;code&gt;.state&lt;/code&gt; (which must be ignored by &lt;code&gt;.gitignore&lt;/code&gt;). Please check &lt;a href="//scripts/main.sh"&gt;&lt;code&gt;scripts/main.sh&lt;/code&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;The application writes its state into the &lt;code&gt;.state&lt;/code&gt; folder.&lt;/li&gt;
&lt;li&gt;Changes in &lt;code&gt;state&lt;/code&gt; branch are commited and pushed to origin. Please check &lt;a href="//scripts/post.sh"&gt;&lt;code&gt;scripts/post.sh&lt;/code&gt;&lt;/a&gt;:

&lt;ul&gt;
&lt;li&gt;Changes are commited and pushed.&lt;/li&gt;
&lt;li&gt;Old commits on &lt;code&gt;state&lt;/code&gt; branch are squashed and force-pushed.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.state&lt;/code&gt; worktree is removed.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For more details, please check the &lt;a href="https://github.com/jorgebg/stateful-action"&gt;repository&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>actionshackathon</category>
      <category>github</category>
    </item>
  </channel>
</rss>
