Search code examples
githubgithub-actions

Automatically Generate a GitHub Release Using a Property in appsettings.json for the Tag


I have a file appsettings.json in my repository that looks like this:

{
  "Version": {
    "VersionNumber": "6.67.1"
  },
  ...
}

I manually update VersionNumber whenever I have a new version that I want to go out. I would like to:

  • Create a tag using VersionNumber
  • Generate a release with that tag, using the auto-generated release notes in GitHub (which generate based on pull requests)

I've found this action but it depends on a particularly-formatted Changelog file, which is more extra work than I'd like to do when I'm content with the release notes that GitHub generates.


Solution

  • I figured this one out, it works like so:

    - name: Read VersionNumber from appsettings.json
      id: get_version
      run: |
        APP_VERSION=$(jq -r '.Version.VersionNumber' PROJECT_HERE/appsettings.json)
        echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV
    - name: Create Release
      run: |
        gh release create "${{ env.APP_VERSION }}" --generate-notes
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    

    This depends on the structure of the appsettings.json matching what I have in my original question above, as well as setting up the GITHUB_TOKEN in the action secrets in GitHub.