

In Software Development keeping up to date with technology updates is crucial. This is true both for developers as they learn and renew their skills, and also for the projects they work on and maintain.
When you start a project, you normally set it up with the latest stable versions of all libraries and tools.
Then time goes by, the project grows, and new features and libraries are added. But the versions of the libraries and packages remains the same the team never updates them.
After all, why would you update them if the project works perfectly with the current versions?
Why you should keep projects up to date
Here are some reasons why you should keep your dependencies updated:
- Solving problems from old versions.
- Adding vulnerability fixes.
- Increasing the overall performance.
- Adding new features.
- ...
When you keep your dependencies updated you are solving problems from older versions and improving performance with new optimizations. You are also able to use new features that other developers have added.
All of these improvements contribute to the maintainability of the code, and the overall project health.
We all have worked on projects where the dependencies have never (or rarely) been updated. And it's no fun.
So how, then, do we keep our projects up to date?
First of all, you can run npm outdated
to see the latest releases of the packages you are currently using.
You can then run npm update
to update them (it will not update them to the major versions). But how do you know which updates will break the project and which ones won't?
Then you have to think about when you should update everything. When should you check for updates – every day? every week? ...month?
What you'll learn in this tutorial
This is why I did this project: to learn about GitHub Actions and use it to have a safe way to automatically update dependencies without making the project fail.
In this tutorial you'll learn how to use the Renovate app to check for dependency updates and then submit Pull Requests to update them. This lets you abstract yourself away from checking for updates, so you can focus on more important things.
The point of using GitHub Actions is to set up a workflow and trigger it with every Pull Request. It will check that the build and tests pass with the updated dependencies before adding them to the project.
Table of Contents
- Getting Started
- Set up GitHub Actions Workflow
- Add Renovate
- Conclusion
- Useful Resources
Getting started
Although this approach can be applied to any project we will use a React project made with Create React App. This will give us a basic project with everything ready to work on.
By the way, if you do not have Node.js installed here is the link to do so.
If you want to check out the final result before you get started, here it is.
So let's begin by running
npx create-react-app my-appcd my-appnpm start
If you use npm 5.1 or earlier, you can't use npx
. Instead, install create-react-app
globally:
npm install -g create-react-app
And then run:
create-react-app my-app
Set up Github Actions Workflow
Now we will proceed to define a GitHub Actions Workflow in our repository to automate the process.
GitHub Actions is a Github Feature that helps you automate your software development workflows. It can handle everything from simple tasks to custom end-to-end continuous integration (CI) and continuous deployment (CD) capabilities in your repositories.
In our root folder, we will create a new folder and name it .github
. Inside that we'll create a workflows
folder. This is how your project should look after these steps:
📁 my-app├── 📁 .github│ └── 📁 workflows├── ......
Here is where we will create and add our Workflows. Github Actions Workflows are the Continuous Integration automated processes we want to run in our project.
Workflows are composed of jobs that contain a set of steps. To explain them in a clearer way let's create our own workflow and go through it step by step.
In the .github/workflows
directory, add a .yml
or .yaml
file and name it main.yml
. I chose that name to keep things simple, but you can give it any other name like build-test.yml
or continuous-integration-workflow.yml
.
📁 my-app├── 📁 .github│ └── 📁 workflows│ └── 📄 main.yml├── ......
Here is how the workflow will look in the end in case you just want to copy it and add it directly before the explanation.
name: Build and Teston: push: branches: [master] pull_request: branches: [master]jobs: build_and_test: runs-on: ubuntu-latest strategy: matrix: node: [10, 12] steps: - name: Checkout uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - name: Install project run: npm install - name: Build the project run: npm run build --if-present - name: Run tests run: npm test
The first param of our workflow will be its name.
name: Build and Test
The second param is the trigger.
We can choose if the workflow is triggered by an event like a push or pull request to a specific branch, or we can even schedule a cron to automatically trigger it every defined amount of time!.
In our project we will want to trigger it when pushing to the master branch, and when the Renovate app submits a Pull Request to update a dependency:
on: push: branches: [master] pull_request: branches: [master]
Next, we define the jobs.
In this example, there will only be one job: build and test the project, and chose the virtual machine where the job will be run.
jobs: build_and_test: runs-on: ubuntu-latest
Now comes the matrix where we will configure the combination of versions and systems we want to run our Workflow. In our case, we will run it on Node.js 10 and 12.
strategy: matrix: node-version: [10, 12]
Finally, the Workflow's steps. First is the checkout action which is a standard action that you must include in your workflow when you need a copy of your repository to run the workflow.
Then you can run other actions and processes. In our app, we will use the setup-node action with the matrix we defined before. Then we will add steps to install the project, build it, and run the tests.
steps: - name: Checkout uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - name: Install project run: npm install - name: Build the project run: npm run build --if-present - name: Run tests run: npm test
Now Create a GitHub Repository for the project, commit the local changes made, and push them to it.
Quick tip: if you want to create it faster, go to repo.new or github.new. You can use gist.new for gists too!
Once you push your changes the Workflow will run. Then you will be able to see how it went in the Actions
tab from the GitHub Project.
Add Renovate
Renovate is a free, open-source, customizable app that helps you automatically update your dependencies in software projects by receiving pull requests.
It is used by software companies like Google, Mozilla, and Uber, and you can use it on GitHub, Gitlab, Bitbucket, Azure DevOps, and Gitea.
We will add a bot that will submit pull requests to our repository when there are updates in our project dependencies.
The cool thing, and the whole point of our project, is that we have previously defined in our workflow to run the tests with the pull requests. So when Renovate submits one, we will automatically check if the updates proposed will break the project or not before merging them to the master branch.
To add Renovate to our project we have to install its app into the project's repository.
Be careful when selecting the repository you want to add Renovate to and choose the one created before. If you made a mistake you want to reconfigure it, you can do it in the Personal Settings' Applications tab from your account.
After a few minutes you will have to accept and merge the onboarding Pull Request that you receive.
Once you have it integrated, you need to configure it by updating the renovate.json
file on the project root. Remember to pull the changes after merging the Pull Request for it to appear.
You can use the default configuration where renovate will submit the pull requests whenever it finds updates and waits for you to merge them:
{ "extends": ["config:base"]}
Or you can adapt it to the requirements of your project like the one used by Renovate itself.
To avoid any issues, and to learn a little more about the tool, we will use a configuration with some of its most useful features.
If you want to learn more about its configuration here are the docs for it.
This will be our renovate.json
file. Have a look at it, and I will explain it after.
{ "extends": [ "config:base" ], "packageRules": [ { "updateTypes": [ "minor", "patch" ], "automerge": true } ], "timezone": "Europe/Madrid", "schedule": [ "after 10pm every weekday", "before 5am every weekday", "every weekend" ]}
In the first part, we are telling renovate that our configuration will be an extension from the default one.
{ "extends": [ "config:base" ],
Then we have the packageRules
. After some months using it I realized that going through checking the pull requests (from time to time) and accepting them if the tests passed was a major waste of time.
This is why the automerge
is set to true, so Renovate automatically merges the pull request if the workflow passed successfully.
To restrict Renovate's freedom a bit, we define that it can only perform automerge
when it is a minor
or patch
update.
This way, if it is a major
or another kind of update, we will be the ones to check whether that update should be added or not.
Here you can find more information about the types of updates available.
"packageRules": [ { "updateTypes": [ "minor", "patch" ], "automerge": true } ],
Lastly, we have the time schedule. If you work alone or in a team at certain hours it is nice to have updates done when you are not working to avoid unnecessary distractions.
We select our timezone and add a custom schedule for it. You can find the valid timezone names here.
"timezone": "Europe/Madrid", "schedule": [ "after 10pm every weekday", "before 5am every weekday", "every weekend" ],
Anyway, if you do not care about the time the pull requests will be submitted, or the people that contribute to the code are in different timezones, then you can remove this part.
Once we have updated the configuration we push the changes to GitHub to have the Renovate app adapted to the new configuration.
Now you finally have the project dependencies safely up-to-date without having to check for them. Here is the resulting project after following all the steps mentioned above.
Remember that if you added the time schedule part you will not get the pull request merged automatically until it complies with that configuration.
Conclusion
There are other ways to keep the dependencies updated in an automated way. But if you use GitHub to host your code, you should take advantage and make the most of its awesome free features.
If you are wondering what else you can do and automate with the GitHub apps and actions, just have a look at its Marketplace.
In addition, you can have a look at a project I made that I work on from time to time. It was the basis of this tutorial. It is a bit more complex and has more features than the one from this tutorial.
I hope you enjoyed this article and learned about GitHub Actions and its Apps. If you've got any questions, suggestions, or feedback in general, don't hesitate to reach out on any of the social networks from my site or by mail.
Useful Resources
Here is a collection of links and resources which I think can be useful to improve and learn more about GitHub Actions and Apps.
- Tutorial project. - The resulting project from this tutorial.
- GitHub Marketplace. - The place to find all GitHub Actions and Apps.
- GitHub Actions Workflow Configuration - The full documentation on how to set up a workflow on Github Actions.
- Renovate GitHub app - The Renovate App main page on the GitHub Marketplace.
- GitHub Actions project Workflow. - The Workflow used in this tutorial.
- Renovate App's configuration file. - Renovate App's custom configuration file from the tutorial.
- Up to Date React Template. - A Personal project that uses the approach described in this tutorial.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

DRY http://ramonmorcillo.com/about
If you read this far, tweet to the author to show them you care.
Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started
ADVERTISEMENT
FAQs
How do you update dependencies safely? ›
- Use npm outdated to discover dependencies that are out of date.
- Use npm update to perform safe dependency upgrades.
- Use npm install <packagename>@latest to upgrade to the latest major version of a package.
- Use npx npm-check-updates -u and npm install to upgrade all dependencies to their latest major versions.
Go to the "Updater" page. Under the "Updater" section, select the "Check for updates using Advanced Updater" option. Select the "GitHub integration" option. In the "Updates Configuration file URL" field, input the URL to the "configuration file".
Should you always update dependencies? ›The good news is that once a security vulnerability is patched, a newer, less vulnerable version of the dependency is usually released. Regularly updating your dependencies is a best practice to avoid vulnerabilities and the accumulation of technical debt, even (and some would say, even more so) when updates are minor.
How do I add dependencies to GitHub? ›Under your repository name, click Settings. In the "Security" section of the sidebar, click Code security and analysis. Read the message about granting GitHub read-only access to the repository data to enable the dependency graph, then next to "Dependency Graph", click Enable.
How often should you update your dependencies? ›Once a month or two, you should try updating all your dependencies. Most of them won't have changed at all, or will have only point releases, so this update will be low risk.
What is the correct command to update a dependency to the latest version? ›Simply change every dependency's version to * , then run npm update --save .
How do I update multiple files in GitHub? ›- Press . (period) on your keyboard when viewing your repository. ...
- Make your changes across multiple files, just as you would do locally.
- Use the sidebar on the left to select the Git menu, and commit/push through the GUI as normal.
If you're running Git on Linux, Git will automatically update whenever you apply a system update.
How do I turn on auto merge in GitHub? ›- On GitHub.com, navigate to the main page of the repository.
- Under your repository name, click Pull requests.
- In the "Pull Requests" list, click the pull request you'd like to auto-merge.
- Optionally, to choose a merge method, select the Enable auto-merge drop-down menu, then click a merge method.
Automatic updates are best for: Essential security fixes that address system vulnerabilities. Operating system updates that have been thoroughly tested/vetted by vendors. Updates that can easily be reverted back if anything goes wrong.
How many dependencies is too many? ›
The fact your class has so many dependencies indicates there are more than one responsibilities within the class. Often there is an implicit domain concept waiting to be made explicit by identifying it and making it into its own service. Generally speaking, most classes should never need more than 4-5 dependencies.
What is the importance of updating dependencies? ›By keeping dependencies up to date, developers can take advantage of new features, bug fixes, and security patches, and they can reduce their exposure to security vulnerabilities. Use a dependency management library: Dependency management libraries are tools that are used to manage dependencies in software.
How do I manually add dependencies? ›Click the dependency you want to add to your application. You can use Ctrl+click to select multiple non adjacent dependencies, or Shift+click to select multiple adjacent dependencies. Drop the dependencies to the Manual Dependencies folder of the application.
How do I add dependencies to an existing project? ›- In Solution Explorer, select a project.
- On the Project menu, choose Project Dependencies. ...
- On the Dependencies tab, select a project from the Project drop-down menu.
- In the Depends on field, select the check box of any other project that must build before this project does.
Pip relies on package authors to stipulate the dependencies for their code in order to successfully download and install the package plus all required dependencies from the Python Package Index (PyPI). But if packages are installed one at a time, it may lead to dependency conflicts.
What are the three main types of dependencies? ›- Causal relationships. In a causal dependency, one element always depends on another. ...
- Resource constraint relationships. ...
- Preferential relationships.
The four types are as follows – Finish to Start, Finish to Finish, Start to Start, and Start to Finish.
How to update all dependencies in package json to latest? ›- npm install installs a package and any packages that it depends on. ...
- npm update updates all the packages listed to the latest specified version.
- Install NPM Check Updates. It's often best to just install NPM check updates globally. ...
- Run NPM Check Updates. cd to a directory with your project and run the following command. ...
- Update Patches. ...
- Update Minor Versions. ...
- Update Major Versions.
To remove a dev dependency, you need to attach the -D or --save-dev flag to the npm uninstall, and then specify the name of the package. You must run the command in the directory (folder) where the dependency is located.
Does GitHub automatically update file? ›
GitHub Desktop automatically downloads updates and installs them when you restart. You can also manually check for updates.
How do I update my repositories? ›Update your local repo from the central repo ( git pull upstream master ). Make edits, save, git add , and git commit all in your local repo. Push changes from local repo to your fork on github.com ( git push origin master ) Update the central repo from your fork ( Pull Request )
How do I get my updates to automatically update? ›- Open the Google Play Store app .
- At the top right, tap the profile icon.
- Tap Settings Network Preferences. Auto-update apps.
- Select an option: Over any network to update apps using either Wi-Fi or mobile data. Over Wi-Fi only to update apps only when connected to Wi-Fi.
It's generally safer to keep the apps on your device up to date—so that you get the security fixes to any potential vulnerability in the apps you're using. But whether you want to get these updates automatically or not is more of a personal choice than a hard-and-fast rule.
How do I update my software automatically? ›Android: Open Settings > System > Advanced > System Update and make sure it's turned on. iOS: Open Settings > General > Software Update and turn on Automatic Updates.
How do I turn on auto merge? ›To use auto-merge, first have an administrator allow auto-merge in the repository settings. Then to enable auto-merge, navigate to the pull request on GitHub.com or GitHub Mobile and tap the button to enable.
What is Automerge? ›Automerge is a Conflict-Free Replicated Data Type (CRDT), which allows concurrent changes on different devices to be merged automatically without requiring any central server.
How do I merge changes without committing? ›- Step 1: Open Git Terminal. ...
- Step 2: Move to Git Repository. ...
- Step 3: Create New Branch. ...
- Step 4: Move to New Branch. ...
- Step 5: Create New File. ...
- Step 6: Add File to Tracking Index.
The Pitfalls of Automatic Updates
They have downsides: They may not keep all of the software on your system up-to-date. Even if they patch most of your applications, some applications may be managed by other update tools. Some may not have any auto-update facility at all.
Users can install updates manually or elect for their software programs to update automatically. Manual updates require the user or administrator to visit the vendor's website to download and install software files. Automatic updates require user or administrator consent when installing or configuring the software.
What are the advantages of automatic updates? ›
- Convenience. Automatic updates eliminate the need to manually check for and install updates. ...
- Improved Security. Developers push updates to patch vulnerabilities found within an app, software or operating system. ...
- Bug Fixes.
- Enable all repositories.
- Update the software.
- Upgrade the software.
- Clean the package dependencies.
- Clean cached packages.
- Remove "on-hold" or "held" packages.
- Use the -f flag with the install subcommand.
- Use the build-dep command.
The most common dependency relationship is a finish-to-start relationship. Task P (predecessor) must be finished before task S (successor) can start. The least common relationship is the start-to-finish relationship.
What are the two types of dependency? ›The dependence classification has two main categories — physical and psychological dependency. Physical dependency means the body has developed a physical reliance on a substance because it alters the body's natural state. Alcohol and nicotine commonly cause physical dependence.
How do you explain dependencies? ›A dependency describes the relationship among activities and specifies the particular order in which they need to be performed. Dependencies arise in every decision making, planning and developing process and are ideally predetermined.
What is dependency and why it is used? ›In object-oriented programming (OOP) software design, dependency injection (DI) is the process of supplying a resource that a given piece of code requires. The required resource, which is often a component of the application itself, is called a dependency.
Does npm install automatically install dependencies? ›The 'npm install' command should add all the dependencies and devDependencies automatically during installation. If you need to add specific devDependencies to your project, you can use this command- 'npm install --save-dev'. This will add your desired npm library to the package. json file.
What are different ways to inject the dependencies? ›- Constructor Injection: Dependency is passed to the object via its constructor that accepts an interface as an argument. ...
- Method Injection: A.k.a. interface-based injection. ...
- Property Injection: A.k.a. setter injection.
To add a dependency to your project, specify a dependency configuration such as implementation in the dependencies block of your module's build. gradle file. This declares a dependency on an Android library module named "mylibrary" (this name must match the library name defined with an include: in your settings.
How do you update all dependencies at once? ›- The first step is to go to your project's directory and run: npx npm-check-updates. The above command displays all the outdated dependencies from your project. ...
- The next step is to update the dependencies by running: npx npm-check-updates -u. ...
- Install the new versions.
Does pip resolve dependencies? ›
Unfortunately, pip makes no attempt to resolve dependency conflicts. For example, if you install two packages, package A may require a different version of a dependency than package B requires. Pip can install from either Source Distributions (sdist) or Wheel (. whl) files.
What is the difference between pip install and pip download? ›Overview. pip download does the same resolution and downloading as pip install , but instead of installing the dependencies, it collects the downloaded distributions into the directory provided (defaulting to the current directory).
What is the alternative of pip install? ›There are a number of alternatives to pip that you may want to try. Conda is the package and environment manager that comes bundled with Anaconda. Conda has its own package repository that can be used to install Python packages into a Conda virtual environment.
How to update package json dependencies? ›You can find the latest version of the npm added in package. json file. If you want to add the latest version either you can run npm install or npm install @latest .
How to update npm dependencies to latest version? ›- Navigate to the root directory of your project and ensure it contains a package.json file: cd /path/to/project.
- In your project root directory, run the update command: npm update.
- To test the update, run the outdated command. There should not be any output.
Library dependencies are constantly evolving, with newly added features and patches that fix bugs in older versions. To take full advantage of third-party reuse, developers should always keep up to date with the latest versions of their library dependencies.
Does npm update packages automatically? ›Run npm update to automatically update my packages to the latest versions From docs: > This command will update all the packages listed to the latest version (specified by the tag config), respecting the semver constraints of both your package and its dependencies (if they also require the same package).
How to fix npm dependencies? ›The easy fix is to use the npm audit fix which will look for updates that can be updated to fix those automatically. This way you'll be able to update the dependency to the latest version that is not a breaking change, run the tests, build and compile if you are using typescript and make sure everything is still ok.
How often should you update npm packages? ›If you want to keep your project secure, fast and enjoy the latest features of all your dependencies, it's important to keep them regularly up-to-date. I suggest you to update them once every month or at least once every 2 months.
How do I update project dependencies? ›- The first step is to go to your project's directory and run: npx npm-check-updates. The above command displays all the outdated dependencies from your project. ...
- The next step is to update the dependencies by running: npx npm-check-updates -u. ...
- Install the new versions.
How do you get the latest version of the dependencies as per the JSON file installed? ›
- Use bower update.
- Execute "bower update all"
- Execute "bower update"
- Create a new. task.
- In. Definition. tab, select. Update. as the task operation.
- Follow the same procedure of creating a JSON Target file using Insert task operation to update the existing JSON file.
NPM installs devDependencies within the package. json file. The 'npm install' command should add all the dependencies and devDependencies automatically during installation. If you need to add specific devDependencies to your project, you can use this command- 'npm install --save-dev'.
How do I update multiple npm packages? ›If you still want to update everything to the latest version, you can use the tool npm-update-all . It's as easy as running this command in your project folder. As you can see, npm-update-all will update all your packages to the latest version.
Why should I update dependencies? ›- Your product can malfunction.
- You will not be able to use new features added in the latest versions.
- You may miss out on performance improvements provided by updates.
- Security issue fixes can be missed or delayed.
- Maintenance overheads of old versions could be reduced.
- Read Blogs and Newsletters. ...
- Read Books. ...
- Take Online Courses and Pick New Things to Learn. ...
- Attend Events/Conferences/Meetups.
- Enable all repositories.
- Update the software.
- Upgrade the software.
- Clean the package dependencies.
- Clean cached packages.
- Remove "on-hold" or "held" packages.
- Use the -f flag with the install subcommand.
- Use the build-dep command.