Skip to content

Commit

Permalink
Add variables support in header and footer
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome committed Mar 16, 2023
1 parent 3f1928f commit e1aa7cb
Show file tree
Hide file tree
Showing 8 changed files with 15,217 additions and 6,736 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ jobs:
id: draft-release
with:
notes-header: |
## Welcome to the %TAG% release of Draft Release
This is some text to welcome you to the release %TAG_STRIPPED%.
## Welcome to the {{version}} release of Draft Release
This is some text to welcome you to the release {{version-number}}.
notes-footer: |
## Upgrade
- For Docker, use the %TAG% image from Docker Hub.
- For Binaries use the %TAG_STRIPPED% release from GitHub.
- For Docker, use the {{version}} image from Docker Hub.
- For Binaries use the {{version-number}} release from GitHub.
- run: |
echo "Version: ${{ steps.draft-release.outputs.version }}"
Expand Down
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
draft-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: lucacome/draft-release@v0.1.0
with:
minor-label: 'enhancement'
Expand All @@ -47,6 +47,12 @@ jobs:
| `release-notes` | `string` | The release notes of the next release. |
| `release-url` | `string` | The URL of the next release. |

## Header and Footer

The header and footer have two special placeholders that will be replaced with the version number of the next release:
- `{{version}}` will be replaced with the version number of the next release.
- `{{version-number}}` will be replaced with the version number of the next release without the `v` prefix.

## Examples

### Add Footer
Expand All @@ -63,12 +69,14 @@ jobs:
draft-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: lucacome/draft-release@v0.1.0
with:
minor-label: 'enhancement'
major-label: 'change'
notes-footer: 'This is a footer.'
notes-footer: |
This is a footer.
It can be multiline.
```

### Get Version Number of Next Release
Expand All @@ -85,7 +93,7 @@ jobs:
draft-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: lucacome/draft-release@v0.1.0
id: draft-release
with:
Expand Down
21,808 changes: 15,091 additions & 6,717 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions dist/licenses.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 43 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1",
"@types/semver": "^7.3.13",
"handlebars": "^4.7.7",
"semver": "^7.3.8"
},
"devDependencies": {
Expand Down
18 changes: 10 additions & 8 deletions src/notes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as github from '@actions/github'
import * as semver from 'semver'
import * as handlebars from 'handlebars'
import {Inputs} from './context'

export async function generateReleaseNotes(
Expand All @@ -17,14 +18,19 @@ export async function generateReleaseNotes(
})

let body = notes.data.body

// variables to replace in header and footer
const data = {
version: nextRelease,
'version-number': nextRelease.replace('v', ''),
}

if (inputs.header) {
let header = replaceAll(inputs.header, '%TAG%', nextRelease)
header = replaceAll(header, '%TAG_STRIPPED%', nextRelease.replace('v', ''))
const header = handlebars.compile(inputs.header)(data)
body = `${header}\n\n${body}`
}
if (inputs.footer) {
let footer = replaceAll(inputs.footer, '%TAG%', nextRelease)
footer = replaceAll(footer, '%TAG_STRIPPED%', nextRelease.replace('v', ''))
const footer = handlebars.compile(inputs.footer)(data)
body = `${body}\n\n${footer}`
}

Expand All @@ -42,7 +48,3 @@ export function parseNotes(notes: string, major: string, minor: string): string

return notesType
}

function replaceAll(str: string, find: string, replace: string): string {
return str.replace(new RegExp(find, 'g'), replace)
}

0 comments on commit e1aa7cb

Please sign in to comment.