Code Monkey home page Code Monkey logo

releasenotesaction's Introduction

ReleaseNotesAction

This Action uses the GitHub API and a Handlebars based template to generate a release notes file. This file can be used in a variety of ways, such as being attached to a release, or uploaded to an external store such as a WIKI

Usage

- uses: rfennell/ReleaseNotesAction@v1
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided automatically, you do not need to create your own token
  with:
    templateFile: '${{ github.workspace }}//template.md'
    outputfile: '${{ github.workspace }}//releasenotes.md'
    extensionsFile: '${{ github.workspace }}//customextensions.js'
    writeToJobSummary: true

Parameters

The task needs the GITHUB_TOKEN environment variable set with a valid GitHub token, either the one auto-generated for each workflow run, or a personal one created with sufficient permissions to access the API.

As well as the GITHUB_TOKEN the action also takes the following parameters

  • templateFile: The path to the Handlebar template file. (Required)
  • outputFile: The path for the file that will be created. (Required)
  • extensionsFile: The path to the an optional module of custom Handlebars functions. (Optional)
  • writeToJobSummary: If true the output will be written to the Action Job Summary as well as generating a file.

Template File

The template allows you to create your own document layout using Handlebars syntax. A template written in this format is as follows

# Release Notes 
## Run Details
- Workflow: {{runDetails.name}} 
- Head Branch: {{runDetails.head_branch}} 
- Head SHA: {{runDetails.head_sha}} 

## Pull Requests
{{#forEach runDetails.pull_requests}}
**{{this.number}}** {{this.title}}
### Commits
  {{#forEach this.commits}}
  - **{{this.sha}}** {{this.commit.message}}
  {{/forEach}}
### Comments
 {{#forEach this.comments}}
 - {{this.body}}
 {{/forEach}}

### linkedIssues
 {{#forEach this.linkedIssues}}
 - **{{this.number}}** {{this.title}}
 {{/forEach}}
    
{{/forEach}}

What is done behind the scenes is that each {{properties}} block in the template is expanded by the Handlebars engine. The property object structure available to get data from at runtime are:

  • runDetails โ€“ the details of the current workflow run
    • pull_requests - the array of pull requests associated with the run
      • commits - the array of commits associated with the PR
      • comments - the array of comment associated with the PR
      • linkedIssues - the array of linked issues with the PR

Note: To dump all possible properties of an object there are two options:

  • Via the template, using the custom Handlebars extension {{json propertyToDump}}. This will include a dump of the object properties in the generated release notes file.
  • If you enable the Actions debug log the API returned data and the generated release notes text will be dumped into the action log (note this can make for a very large an unresponsive log file)

Note: If a field contains escaped HTML encoded data this can be returned its original format with the Handlebars triple brackets format {{{sample.field}}}

Handlebar Extensions

The Handlebars Helpers extension library is also pre-load, this provides over 120 useful extensions to aid in data manipulation when templating. They are used the form

## To confirm the Handlebars-helpers is work
The year is {{year}} 
We can capitalize "foo bar baz" {{capitalizeAll "foo bar baz"}}

In addition to the Handlebars Helpers extension library, there is also custom Helpers pre-loaded specific to the needs of this Action

  • json that will dump the contents of any object. This is useful when working out what can be displayed in a template, though there are other ways to dump objects to files (see above)
## The contents of the run object
{{json runDetails}}

Finally there is also support for your own custom extension libraries. These are provided via an optional JavaScript file which is loaded into the Handlebars templating engine. The file can contain one or more functions, within the module.exports block, in the following format

module.exports = {
  foo() {
    return 'Returns foo';
  }
};

and can be consumed in a template as shown below

## To confirm our custom extension works
We can call our custom extension {{foo}}

Local Test Runner

Within the repo for this action a local runner is provided that can provide an easier means to develop templates and custom extensions. It allows all the parameters usually passed in by a GitHub workflow to be provided via the command line.

To build the action locally, from the root of the repo

npm install
npm run build

The action can then be run as follows

node .\lib\LocalRun.js --pat <GitHub-PAT> --owner <Repo owner> --repo <Repo> --runid <Number> --templatefile <File path> --outputfile <File path> --extensionsfile <Optional Full File path>f
        

Note: The --extensionsfile parameter requires a full, and not a relative, file path else a load error will occur. The other file parameters can be relative or full path.

Note: A sample template and custom extension can be found in the __tests__ folder.

Notes on Building the Extension

The extension repo is based on basic pattern that is meant to package all the npm dependencies using ncc.

Unfortunately there is an issue with Handlebars that stops it being used with ncc. Until this is addressed the node-modules folder needs to be committed to the repo containing the production dependencies for use at runtime

Hence, to build the product and remove the development dependencies run

npm install
npm run build
npm run format 
npm run lint
npm test
npm run package

or

npm install
npm run all

releasenotesaction's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar rfennell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

releasenotesaction's Issues

Generate release notes for the other repos

Hi there,

Thanks for this awesome extension.
Btw, we have the scenario of having multiple repos and using the multi stage yaml pipeline in separate repo for building the latest artifacts from the above said different repos.

The problem is that the release notes generator extention is not fetching the related work items from all these multiple repos but it is only retrieving the work items from the current release management repo where the multi stage yaml pipeline is running.

Would it be possible to pass the repo names list to the release generator extension, that will list all the work items related to that repo and that branch rather only retrieving from the current working branch?

Appreciate your appropriate response and much appreciated.

Thanks,
Rishi

test

Action Version

No response

Describe the bug

try github issue form template, from: https://blogs.blackmarble.co.uk/rfennell/2021/04/06/a-first-look-at-the-beta-of-github-issue-forms/

Repo Steps

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
...

Expected Behavior

No response

Logging Information

No response

Have to commit the node_module folder

Unfortunately, there is an issue with Handlebars that stops it from being used with ncc.

Until this is addressed the node-modules folder needs to be committed to the repo containing the production dependencies for use at runtime.

There error is

Processing template
Error: Invalid left-hand side in assignment
##[debug]Node Action run completed with exit code 1
##[debug]Finishing: Run /./

This has been logged with Handlebars as #375

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.