Automatic Tagging of Releases
Tags are a simple aspect of version control, they allow you to identify specific release versions of your code. You can think of a tag as a functionality that doesn't change.
In the previous post, I pushed the docker image with a hardcoded "latest" tag. I will follow the standard semantic versioning flow to release new changes:
Given a version number Major.Minor.Patch
, increment the:
Major
version when you make incompatible API changes,Minor
version when you add functionality in a backwards compatible manner, andPatch
version when you make backwards compatible bug fixes.
Define helper script for tagging
- Create a build directory in the root application folder
- Create a git_update.sh file in the build folder, below are the contents of the shell script:
Add new step for tagging
- In the main.yml file, I will add another GitHub action. Every time there's a new commit to the main branch we will increment a specific version (major, minor, or patch):
2. I will then reference the output variable tag for our docker image, we get this from the previous step with the help of the shell script we defined.
IMAGE_TAG: ${{ steps.increment-git-tag.outputs.git-tag }}
See it in action
Commit latest changes to the main branch to see the workflow run the configuration.
Summary
In general you can increment your version (major, minor, or patch), just replace the specific version on the step that you pass the input:
- name: Automatic Tagging of Releases
id: increment-git-tag
run: |
bash ./build/git_update.sh -v patch
Each time you commit your code will be versioned accordingly, thanks for reading along. In the meantime checkout the repo create-a-ci-pipeline.