<?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: Lenra Developers</title>
    <description>The latest articles on DEV Community by Lenra Developers (@lenradevelopers).</description>
    <link>https://dev.to/lenradevelopers</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%2F769922%2F2a277e76-3635-4f57-9275-db9a79cc53f8.jpg</url>
      <title>DEV Community: Lenra Developers</title>
      <link>https://dev.to/lenradevelopers</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lenradevelopers"/>
    <language>en</language>
    <item>
      <title>Lenra's automatic management of dependencies</title>
      <dc:creator>Lenra Developers</dc:creator>
      <pubDate>Wed, 08 Dec 2021 14:37:32 +0000</pubDate>
      <link>https://dev.to/lenradevelopers/lenras-automatic-management-of-dependencies-i28</link>
      <guid>https://dev.to/lenradevelopers/lenras-automatic-management-of-dependencies-i28</guid>
      <description>&lt;h3&gt;
  
  
  My Workflow
&lt;/h3&gt;

&lt;p&gt;How do you manage with all versions of your dependencies between your huge projects?&lt;/p&gt;

&lt;p&gt;My answer here.&lt;/p&gt;

&lt;h3&gt;
  
  
  What really is the issue?
&lt;/h3&gt;

&lt;p&gt;At Lenra, we have several Git projects that often require modifying the link versions in the dependency files. But doing it manually slows down the release process and wastes too much time for our development teams who can't focus on the features.&lt;/p&gt;

&lt;p&gt;The solution was to develop some GitHub &lt;code&gt;Actions&lt;/code&gt; in a &lt;code&gt;workflow&lt;/code&gt; executed at each release of a new version of a dependency to modify the file that links to it in each project using it.&lt;/p&gt;

&lt;h3&gt;
  
  
  How it works ?
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. Define the shape of your projects
&lt;/h4&gt;

&lt;p&gt;We will start by presenting our Git projects in the following form for some evident purposes of dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Repo-A -&amp;gt; Repo-B, Repo-C
Repo-B -&amp;gt; Repo-C
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;As you can see in the example directory, we have 3 Git repositories that depend on each other. In our example, repository "B" needs repository "A" to compile. And as it is quite tedious to always have to manually edit the right dependency files, this action will take care of it, if it is well configured.&lt;br&gt;
If we continue our exploration, the "C" repository also requires the "A" repository in addition to the "B" repository. Projects of a certain size can have pretty complex mesh links which can be a source of errors.&lt;/p&gt;
&lt;h4&gt;
  
  
  2. Understanding links between each workflow
&lt;/h4&gt;

&lt;p&gt;When you publish a new release on the repository "A", this action will automatically create a Pull Request on the repository "B" and "C" to update the correct files and change its own link in dependancy file(s).&lt;br&gt;
And now, when you merge the PR on the repository "B", and create a new release, it will update the PR on the repository "C" to add this changes.&lt;/p&gt;

&lt;p&gt;Now we can accept changes on the repository "C" to update its version of "A" and "B".&lt;/p&gt;
&lt;h3&gt;
  
  
  How to use it ?
&lt;/h3&gt;

&lt;p&gt;Using the previous example, you need to trigger the action on the source repository. I'll name it &lt;code&gt;.github/workflows/on_release.yml&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This file must call the &lt;code&gt;Action&lt;/code&gt; that will populate the release on the requested repositories. To do it we need to define this &lt;code&gt;step&lt;/code&gt; in your &lt;code&gt;job&lt;/code&gt; :&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;create_pr&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;lenra-io/create-or-update-pr-action/utils/trigger_workflow@v1&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;target_ref&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ steps.extract_tag.outputs.target_ref }}&lt;/span&gt;
          &lt;span class="na"&gt;target_repository&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;${{&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;github.repository_owner&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;}}/repo-B"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;${{&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;github.repository_owner&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;}}/repo-C"&lt;/span&gt;
          &lt;span class="na"&gt;target_workflow&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;create_or_update_pr.yml&lt;/span&gt;
          &lt;span class="na"&gt;params&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
            &lt;span class="s"&gt;{&lt;/span&gt;
              &lt;span class="s"&gt;"version": "${{ steps.get_version.outputs.tag }}",&lt;/span&gt;
              &lt;span class="s"&gt;"origin": "repo_a",&lt;/span&gt;
              &lt;span class="s"&gt;"release_notes": "${{ steps.get_version.outputs.release-notes }}"&lt;/span&gt;
            &lt;span class="s"&gt;}&lt;/span&gt;
          &lt;span class="na"&gt;token&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.WORKFLOW_GITHUB_TOKEN }}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;I use a custom GitHub Token because action running the default GitHub secret &lt;code&gt;${{ secrets.GITHUB_TOKEN }}&lt;/code&gt; can't trigger any other workflow so that won't make things appends.&lt;/p&gt;

&lt;p&gt;As you can see, this &lt;code&gt;step&lt;/code&gt; will trigger a custom workflow defined in another repository chooses from &lt;code&gt;target_repository&lt;/code&gt;, &lt;code&gt;target_ref&lt;/code&gt; and &lt;code&gt;target_workflow&lt;/code&gt;. And you can customize some information during this execution as parameters using the &lt;code&gt;params&lt;/code&gt; field, you can add everything you need on the remote execution but that need to fit the input declaration.&lt;/p&gt;

&lt;p&gt;This workflow must be run on each release, so be sure that you'll use the following declaration at the top of the file :&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;release&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;types&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;published&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now this first step is defined, you need to create the remote workflow to receive this event and update the file you need.&lt;br&gt;
So I'll call this new file &lt;code&gt;.github/workflows/create_or_update_pr.yml&lt;/code&gt; on the remote repository.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;create_pr&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;lenra-io/create-or-update-pr-action@v1&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Update&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;dependencies'&lt;/span&gt;
          &lt;span class="na"&gt;token&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.WORKFLOW_GITHUB_TOKEN }}&lt;/span&gt;
          &lt;span class="na"&gt;script&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
            &lt;span class="s"&gt;${{ steps.setup-yq.outputs.yq-binary }} eval ".dependencies.${{ github.event.inputs.origin }}.git.ref = \"${{  github.event.inputs.version }}\"" -i project.yaml&lt;/span&gt;
            &lt;span class="s"&gt;git add project.yaml&lt;/span&gt;

            &lt;span class="s"&gt;RELEASE_NOTES="${{ github.event.inputs.release_notes }}"&lt;/span&gt;
            &lt;span class="s"&gt;RELEASE_TYPE="${RELEASE_NOTES/:*}"&lt;/span&gt;

            &lt;span class="s"&gt;git commit -m "${RELEASE_TYPE}: Upgrade ${{ github.event.inputs.origin }} to ${{ github.event.inputs.version }}&lt;/span&gt;
            &lt;span class="s"&gt;${RELEASE_NOTES}"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;On this step you need to use the &lt;code&gt;create-or-update-pr&lt;/code&gt; GitHub Action we've already defined and make the change you want on the &lt;code&gt;script&lt;/code&gt; field. Don't forget to commit it, but you didn't need to push it, the action will do anything else for you.&lt;/p&gt;

&lt;p&gt;Here I update the yaml file and change the dependency version using the yq command.&lt;/p&gt;

&lt;p&gt;And that all, you can now focus on your work.&lt;/p&gt;
&lt;h3&gt;
  
  
  Go deeper
&lt;/h3&gt;

&lt;p&gt;This can be awesome to use in your projects with sementic-release to make releases even faster and erase errors of dependency managements.&lt;/p&gt;

&lt;p&gt;Of course you can ask for new features on the GitHub Action repository or contribute yourself by submitting a new pull request.&lt;/p&gt;

&lt;p&gt;Now you can test it by publishing theses 3 repositories on your own account/organization to see how it works. (Don't forget to create the WORKFLOW_GITHUB_TOKEN secret in the settings of each repository.)&lt;/p&gt;
&lt;h3&gt;
  
  
  Submission Category:
&lt;/h3&gt;

&lt;p&gt;Maintainer Must-Haves&lt;/p&gt;
&lt;h3&gt;
  
  
  Yaml File or Link to Code
&lt;/h3&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--566lAguM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/lenra-io"&gt;
        lenra-io
      &lt;/a&gt; / &lt;a href="https://github.com/lenra-io/create-or-update-pr-action"&gt;
        create-or-update-pr-action
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A simple but powerful GitHub Action to link workflows and manage dependencies between projects. #actionshackathon21
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;h1&gt;
Create or update PR Action&lt;/h1&gt;
&lt;p&gt;A simple but powerful GitHub Action to link workflows and manage dependencies between projects.&lt;/p&gt;
&lt;h2&gt;
Usage:&lt;/h2&gt;
&lt;p&gt;To learn accurately how to use it, you must see the &lt;a href="https://github.com/lenra-io/create-or-update-pr-action/examples"&gt;guide here&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
Quick Example:&lt;/h2&gt;
&lt;div class="highlight highlight-source-yaml position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;      &lt;span class="pl-c"&gt;&lt;span class="pl-c"&gt;#&lt;/span&gt; Call `Create or update PR` GitHub action&lt;/span&gt;
      - &lt;span class="pl-ent"&gt;name&lt;/span&gt;: &lt;span class="pl-s"&gt;create_pr&lt;/span&gt;
        &lt;span class="pl-ent"&gt;uses&lt;/span&gt;: &lt;span class="pl-s"&gt;lenra-io/create-or-update-pr-action@v1&lt;/span&gt;
        &lt;span class="pl-ent"&gt;with&lt;/span&gt;
          &lt;span class="pl-c"&gt;&lt;span class="pl-c"&gt;#&lt;/span&gt; The name of the PR to be created.&lt;/span&gt;
          &lt;span class="pl-ent"&gt;name&lt;/span&gt;: &lt;span class="pl-s"&gt;&lt;span class="pl-pds"&gt;'&lt;/span&gt;Update dependecies&lt;span class="pl-pds"&gt;'&lt;/span&gt;&lt;/span&gt;
          &lt;span class="pl-c"&gt;&lt;span class="pl-c"&gt;#&lt;/span&gt; The token used to create the PR. &lt;/span&gt;
          &lt;span class="pl-c"&gt;&lt;span class="pl-c"&gt;#&lt;/span&gt; I didn't use the `secrets.GITHUB_TOKEN` here because this token can't trigger workflow event if we push something or create a PR.&lt;/span&gt;
          &lt;span class="pl-ent"&gt;token&lt;/span&gt;: &lt;span class="pl-s"&gt;${{ secrets.WORKFLOW_GITHUB_TOKEN }}&lt;/span&gt;
          &lt;span class="pl-c"&gt;&lt;span class="pl-c"&gt;#&lt;/span&gt; Write a little script called just before the PR creation or update.&lt;/span&gt;
          &lt;span class="pl-c"&gt;&lt;span class="pl-c"&gt;#&lt;/span&gt; This example will upgrade the version inside of the pubspec.yaml and publish it in a new PR&lt;/span&gt;
          &lt;span class="pl-ent"&gt;script&lt;/span&gt;: &lt;span class="pl-s"&gt;|&lt;/span&gt;
&lt;span class="pl-s"&gt;            # Update the requested dependency version in the pubspec.yaml file&lt;/span&gt;
&lt;span class="pl-s"&gt;            ${{ steps.setup-yq.outputs.yq-binary }} eval&lt;/span&gt;&lt;/pre&gt;…
&lt;/div&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/lenra-io/create-or-update-pr-action"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;



&lt;h3&gt;
  
  
  Additional Resources / Info
&lt;/h3&gt;

&lt;p&gt;Any needed resources is in the GitHub repository of the action, you can use it from the GitHub Marketplace and any contribution are welcome.&lt;/p&gt;

&lt;p&gt;This project is under MIT Licence.&lt;/p&gt;

&lt;p&gt;Collaborators: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/orgs/lenra-io/teams/lenra"&gt;Lenra team&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>actionshackathon21</category>
      <category>opensource</category>
      <category>githubactions</category>
      <category>dependencymanagement</category>
    </item>
  </channel>
</rss>
