A Simple Way to Confirm Your Code is Live

Deployments
Documentation

There are times where code changes aren't directly visible, so how do we confirm that they're live?

Some code changes, such as search indexing, might not be readily noticeable on the front-end. When these changes are deployed to a server controlled by a third party there may not be a simple way to confirm that the server is running the code expected. In these cases, we can use a simple API controller to return details about the current build.

Status Data

To allow for varying implementations we can start by defining the IStatus interface

  • Application: used to return the name of the current program
  • Build Version: used to return the current version of the deployed code
  • Build Date: the build date of the deployed code
  • Current Date: the date of the response, used to confirm that the response is current
  • Environment: return the current environment, such as development or production

Implementation

Two of these fields are very simple expression bodies:

The build version can be incremented automatically via various build processes or incremented manually as needed.

Two more pull from IHostEnvironment, which can be injected into our constructor. (Note that this is different than IHostingEnvironment, which is obsolete)

Build Date

Last is the build date data. There are a few common ways of obtaining this data, including PE header data (now obsolete due to deterministic builds) or using a build script to write the date to resource file. In our case we're going to use a naive but simple method to look at the most recent time the current assembly was written.

This approach does have one or two shortcomings, namely that the LastWriteTime could change when files move around. For our purposes of easy confirmation that the deployed code has changed this is acceptable but this may be a problem in other situations.

The other concern is around reading the file system unnecessarily. This can be alleviated by setting the Status implementation as a singleton.

Checking the Build

Finally the status object can be injected to our controller and returned as an ObjectResult.

Put all together this returns the following JSON:

When integrated with advanced build pipeline processes, even more data can be exposed via this process as well.

Now we can easily check if the latest version of code is running, which can help save considerable time for troubleshooting and bug reports.

This is some text inside of a div block.
This is some text inside of a div block.
Why Writing a GOOD Bug Report is Important