Most developers savor the opportunity to create projects from scratch. Instead, we are often tasked with changing or maintaining existing applications. A recent maintenance and development project for a website had a particularly convoluted legacy. The project had changed hands through several developers along the way. Operational entropy had reduced the stakeholder’s confidence in the product. We addressed this confidence issue by improving the project’s deployment operations using task automation.
What is Task Automation?
Task automation is surging in popularity among scripting developers. Simply defined, it is the use of tools and/or saved scripts to (often repeatedly) execute a series of actions. Turning script-based or compilable code into a finished product requires many repetitive steps. Automation combines these steps into logical tasks, allowing the developer to focus on programming problems instead of deployment problems.
How Segue Used Task Automation for A Client
Task automation is often enabled through the use of a task runner. Some popular task runners include Grunt, Gulp, and NPM. Task runners can copy files, minify code, optimize images, and do just about anything else a developer can do on a computer. Electing to start simply, we decided to improve how files are copied for deployment.
Focusing on Files
File management for the project was more complex than it needed to be. The development, testing, and production environments each had their own methods for handling files. The update process for files ranged from direct modification to FTP and even included full restore from backup. We chose FTP as the standard method to transfer files to the different environments.
Finding the Delta
A simple way to update the server was to update all the files that could have changed. However, updating files this way is far from efficient. A better approach involves tracking which files have changed and only updating those files. We chose Git for tracking the changes to the files because of its versatility and portability. With Git, we could tell which files were added, removed, and changed.
Script Magic with Gulp
It would be magical if Git would just tell FTP what files need to move to the server all on its own. Unfortunately, we have to create our own magic using Gulp. Our Gulp scripts talk to Git to find out what files have changed, and then the scripts send those files to the server over FTP. We wrote the scripts to handle the differences that may come up in this process to improve standardization. The same set of scripts performs the file transfer no matter what developers, changes, or servers are involved.
The Benefits of Tasks Automation
The previous manual, memory-based process for transferring files did little to enhance completeness or correctness. Did the developer remember the right files? Did the right files get transferred? Were the files transferred to the right server? With all transfer operations run from a single script, the opportunities for error have been reduced. The developer can be confident in the completeness of the final product. Once a correct and complete set of files is established, any subsequent code issues can be more easily identified (and corrected!).
There are many other ways to improve the deployment process through automation. Some options include automated unit testing, code linting, and file optimization. Automating tasks increases confidence in the product and makes the developer’s job easier.