<?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>DEV Community: Stears</title>
    <description>The latest articles on DEV Community by Stears (@stears).</description>
    <link>https://dev.to/stears</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%2Forganization%2Fprofile_image%2F4883%2Faccb05cf-f9ab-4dea-ba01-62a5ec7292f2.jpg</url>
      <title>DEV Community: Stears</title>
      <link>https://dev.to/stears</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/stears"/>
    <language>en</language>
    <item>
      <title>Automatically notify your team when you deploy new changes in a Python project</title>
      <dc:creator>Chidiebere Ogujeiofor</dc:creator>
      <pubDate>Sun, 12 Dec 2021 15:17:52 +0000</pubDate>
      <link>https://dev.to/stears/automatically-notify-your-team-when-you-deploy-new-changes-5bf1</link>
      <guid>https://dev.to/stears/automatically-notify-your-team-when-you-deploy-new-changes-5bf1</guid>
      <description>&lt;p&gt;Photo from &lt;code&gt;ThisisEngineering&lt;/code&gt;&lt;a href="https://www.pexels.com/photo/female-software-engineer-coding-on-computer-3861972/" rel="noopener noreferrer"&gt;Pexels&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;One of the things that I love about the &lt;a href="https://en.wikipedia.org/wiki/Scrum_software_development" rel="noopener noreferrer"&gt;Agile methodology&lt;/a&gt; is how it gives you the ability to make frequent tiny improvements to your project. An essential advantage of “being” Agile is deploying small changes frequently that add value to our customers or improve some internal processes.&lt;/p&gt;

&lt;p&gt;In scrum, we would usually have a demo after every sprint in which we show new features/changes to other stakeholders(design, data, non-technical teammates etc.). However, in these demos, we rarely go into the minute details of the new changes (e.g. a column being renamed in a database table or the meaning of a column changing). These omissions could lead to problems with teams that depend on your work. &lt;/p&gt;

&lt;p&gt;Imagine that you have a web team(that adds and maintains features on your web app) and a data team(that analyses the data generated by your web app to perform different tasks). Let’s say the web team deploys a feature that replaces a boolean &lt;strong&gt;is_customer&lt;/strong&gt; field with a role field(that has enum CUSTOMER, SHOP_OWNER, ADMIN). The problem here is that during demos at the end of the sprint, the web team would often communicate the “new features” that were added and may forget to talk about the column change.  &lt;/p&gt;

&lt;p&gt;After deploying such changes, the existing queries of the data team would suddenly stop working or give incorrect results.&lt;/p&gt;

&lt;p&gt;Also, imagine that a non-technical teammate(e.g. a marketer) was to ask you when the web team deployed the “google login” feature to the website; where would you find that information?&lt;/p&gt;

&lt;p&gt;We experienced these problems in my team at &lt;a href="https://www.stearsng.com/" rel="noopener noreferrer"&gt;Stears&lt;/a&gt;, and I think our solutions to all of them are related. In this article, I would like to share a high-level view of how we solved this.&lt;/p&gt;

&lt;p&gt;Below is a summary of the problems we found:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Demos usually omits crucial minute changes to the other team members, and we need a way to notify them when we deploy automatically.&lt;/li&gt;
&lt;li&gt;There was no place to see the history of changes that we made in the past&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is how the rest of the article structured:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How we solved this&lt;/li&gt;
&lt;li&gt;Link between changelog and commit convention&lt;/li&gt;
&lt;li&gt;Choosing a commit convention&lt;/li&gt;
&lt;li&gt;Enforcing a commit convention&lt;/li&gt;
&lt;li&gt;Generating a changelog&lt;/li&gt;
&lt;li&gt;Sending the message to slack&lt;/li&gt;
&lt;li&gt;Sending different messages from the pipeline&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How we solved this &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;We deploy new changes to production in our system by creating a release &lt;a href="https://docs.gitlab.com/ee/topics/git/tags.html" rel="noopener noreferrer"&gt;tag&lt;/a&gt;. Once a release is created, a manual job in our pipeline, which when run deploys our app to production.&lt;/p&gt;

&lt;p&gt;Since our deployment strategy involved creating tags and changelogs contain information about the changes that have been deployed in each release, we decided to solve the problems stated above by maintaining a changelog in our project.&lt;br&gt;
Adding a changelog led us to choose a commit convention, enforce it, and add commands that extract the most recent changes from our changelog and send it to slack whenever we deploy.&lt;/p&gt;
&lt;h3&gt;
  
  
  Link between changelog and commit convention &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Maintaining a CHANGELOG lets us know the releases(and the changes within each release) that have been made historically and allows us to extract the most recent updates easily. &lt;/p&gt;

&lt;p&gt;For us, we also wanted our changelog to have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a link to the ticket so we can see more details about each change&lt;/li&gt;
&lt;li&gt;a link  that shows us the file changes that were made while implementing that feature&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below is an example of how our changelog looks:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn786vchfhsj355qnjwsl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn786vchfhsj355qnjwsl.png" alt="Changelog"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I have used dummy messages here. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Notice how the changelog shows the date the web team deployed each release and how it groups the changes based on their type(bug fixes, features, automation, etc.)&lt;/p&gt;

&lt;p&gt;Manually updating this information to your changelog is going to be painful. &lt;/p&gt;

&lt;p&gt;Since we usually add a description of changes made in our commit messages, it makes sense to use these messages to automate the way we generate our changelog. To do this, however, we needed to have a consistent commit message format(a commit convention) so as to easily extract the data we want to be in our changelog. &lt;/p&gt;

&lt;p&gt;Next, let’s talk about how we chose our commit convention.&lt;/p&gt;
&lt;h4&gt;
  
  
  Choosing a commit convention &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;When choosing a commit convention, you have to decide what data you want your commit to have. There is a standard called &lt;a href="https://www.conventionalcommits.org/en/v1.0.0/" rel="noopener noreferrer"&gt;conventional commit&lt;/a&gt; which has the following structure&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;type&amp;gt;[optional scope]: &amp;lt;description&amp;gt;
&amp;lt;new-line&amp;gt;
[optional body]
&amp;lt;new-line&amp;gt;
[optional footer(s)]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The “type” section is used to state whether the commit is a feature(feat), refactor, ci change, etc.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;scope&lt;/code&gt; is one or two words that give a general context of the task. This is usually the name of the epic the commit is part of. E.g. authentication, notification, subscription etc&lt;/li&gt;
&lt;li&gt;The “description” is one sentence or phrase that describes the task&lt;/li&gt;
&lt;li&gt;The “body” is where you add more details of the task&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Footers&lt;/code&gt; are where you specify extra details like whether the task is a breaking change, ticket number etc. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For us in my team, however, we decided to make slight changes to this by &lt;br&gt;
replacing the ‘footer’ part with a required issue_number and &lt;br&gt;
ensuring that the optional body is in bullet points(when provided). &lt;/p&gt;

&lt;p&gt;We did this because we wanted to ensure that the issue number was always in the message we sent to our teammates on deployment. &lt;/p&gt;

&lt;p&gt;Below is the structure of the commit convention we chose&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
&amp;lt;type&amp;gt;[optional scope]: &amp;lt;description&amp;gt;
&amp;lt;required blank-line&amp;gt;
[optional bullet point body]
&amp;lt;required blank-line&amp;gt;
closes docs#&amp;lt;required issue_number&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6825saroyxfc0sp1c8s5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6825saroyxfc0sp1c8s5.png" alt="Commit structure and example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Examples of valid commits are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1&lt;/strong&gt;: &lt;em&gt;scope and body is present&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;feat(auth): Adds signup page to the app

- adds signup.html file to the app 

closes docs#101
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example 2:&lt;/strong&gt;: &lt;em&gt;body and scope not provided&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chore: Refactors auth folder 

closes docs#121
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example 3:&lt;/strong&gt;: &lt;em&gt;scope provided but body omitted&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ci(deploy): Improve deploy changes

closes docs#121
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we get to the practical section of this series, you will see that you could use any format you want as long as it is consistent and has all the information you want. To ensure consistency, you would have to enforce it.&lt;/p&gt;

&lt;h4&gt;
  
  
  Enforcing commit convention &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;It is one thing for everybody to agree on a commit convention, but it is very easy for mistakes and typos to be made when writing commits. Thus, it would be best to enforce the convention you choose on your local machine and on a CI pipeline to ensure that everyone obeys/follows it. &lt;/p&gt;

&lt;p&gt;We achieved this by adding a command to our pre-commit hook that validates that our commit messages followed our convention and added the same check to our CI pipeline.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1swvpvoyqhee82j0yav4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1swvpvoyqhee82j0yav4.png" alt="Stears Commit convention"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To enforce the agreed commit convention, we used a tool called &lt;a href="https://commitizen-tools.github.io/commitizen/" rel="noopener noreferrer"&gt;commitizen&lt;/a&gt; which reads a regex specified in a &lt;code&gt;cz.toml&lt;/code&gt; configuration file to test each commit message that is created. You will see how we did this when we get to the implementation detail section.&lt;/p&gt;

&lt;p&gt;Once we have enforced our commit conventions, the next thing we do is to generate a changelog. &lt;/p&gt;

&lt;h4&gt;
  
  
  Generating the changelog &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;a href="https://commitizen-tools.github.io/commitizen/" rel="noopener noreferrer"&gt;commitizen&lt;/a&gt; package also allows you to generate a changelog from your commit messages.&lt;/p&gt;

&lt;p&gt;To achieve this, we had to determine how we wanted each bullet point that highlights a change to look, create a grouped regex that extracts the parts of our commit message and use a class-based configuration from the commitizen package.&lt;/p&gt;

&lt;p&gt;I will show you how I did this in a subsequent article.&lt;/p&gt;

&lt;p&gt;So now we have the valid commits, and we have a changelog its time to talk about slack.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sending the message to slack &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;After generating the changelog, the final step is to add code that automatically extracts the most recent release from the changelog and add it to the slack message. &lt;/p&gt;

&lt;p&gt;We achieved this by creating a &lt;a href="https://api.slack.com/bot-users" rel="noopener noreferrer"&gt;slack bot&lt;/a&gt; in our slack workspace and programmatically sending messages to a channel via a slack client. &lt;/p&gt;

&lt;p&gt;While doing this, however, we quickly realised that slack does not recognise markdown but has its own rules for achieving  &lt;a href="https://api.slack.com/messaging/composing/layouts" rel="noopener noreferrer"&gt;rich text formatting&lt;/a&gt; via its API. Let’s call this slack technique of formatting messages “slackdown” (a fancy name invented by my manager)&lt;/p&gt;

&lt;p&gt;As a result, we created a parser that converts markdown to “slackdown” alongside building a slack client. Once this parser has been completed, sending the slack message becomes easy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl1e0zsxzm7uvm9mzpy76.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl1e0zsxzm7uvm9mzpy76.png" alt="Difference between  markdown and slack rich text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Sending different messages from the pipeline &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;Once the slack bot has been created and is working, the next step is to develop different commands that would run on different scenarios(or events) in the pipeline. In our case, we needed a CLI command that would send a message on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;QA-deploy-success&lt;/li&gt;
&lt;li&gt;QA-deploy-failure&lt;/li&gt;
&lt;li&gt;prod-deploy-success&lt;/li&gt;
&lt;li&gt;prod-deploy-failure&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Hurray! If you got here, then you are fantastic! This article discussed a lot, and I explained the steps we took to maintain a changelog and notify our teammates when we deploy new features.&lt;/p&gt;

&lt;p&gt;In asubsequent article, I will take you through each step with code examples. &lt;/p&gt;

&lt;p&gt;You can follow &lt;a href="https://dev.to/stears"&gt;StearsBusiness&lt;/a&gt; to get notified once it is created.&lt;/p&gt;

</description>
      <category>git</category>
      <category>changelog</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
