Useful Github Actions for release management

27 Jan 2022

Hello! Today I would like to review Github Actions for repository management and release automation.

I had a task to automate existing manual release preparation process(create branch, update version file etc.). There were 2 main steps: pre-release and post-release. Another task was to automate some post release steps(create tag/release, merge branches, remove release branch etc.).

Existing release process was similar to gitflow, but had some custom specific. Then there were no option to use existing opensource workflows, for example github-action-gitflow-release-workflow).

Now I would like to share some useful Github Actions and some other approaches.

Approaches

  • Workflow can be triggered manually using workflow_dispatch. Branch is also selected manually in this case.

  • For manual triggered workflows input parameters can be specified.

  • Marketplace is useful for searching Actions for specific task.

  • Some tasks can be solved with bash console command. There is also possible to use several commands in one step. However, it might be better to implement custom action in such cases.

  • There is an exit 1 command for early fail workflow. This approach can be used for advanced input parameters validation.

Standard Github Actions

Self-created action (bash console commands)

- name: Retrieve tag exists flag
  uses: mukunku/tag-exists-action@v1.0.0
  id: checkTag
  with:
    tag: ${{ github.event.inputs.version }}
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Verify tag not exists
  run: |
    if [ ${{ steps.checkTag.outputs.exists }} == true ]; then exit 1; else exit 0; fi
  • Verify that branch doesn't exist.
- name: Verify release branch not exists
  run: |
    git fetch --all
    if git branch -a | grep -q release-${{ steps.dashed_version.outputs.result }}; then exit 1; else exit 0; fi
  • Update file content:
- name: Update version
  run: |
    echo ${{ github.event.inputs.version }} > .version
  • Validate branch name
- name: Verify branch name
  if: "!contains(github.ref, 'refs/heads/release-')"
  run: |
      echo "Wrong branch name: ${{ github.ref }}, should be release branch"
      exit 1

Finally, I implemented pre-release and post-release workflows using actions above and automated boring manual efforts for preparation releases.

That's all for today. Thank you for your attention!