Skip to content

Commit

Permalink
Allow specifying release title and tag templates
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmus-saks committed Feb 23, 2024
1 parent 7d928fc commit 1281e44
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [v1.2.0] - 2024-02-23

### Added

* Added the ability to define the format of the release title and tag.

## [v1.1.1] - 2024-02-23

### Fixed
Expand Down
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,53 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Release a Changelog
uses: rasmus-saks/release-a-changelog-action@v1.1.0
uses: rasmus-saks/release-a-changelog-action@v1.2.0
with:
github-token: '${{ secrets.GITHUB_TOKEN }}'
# Optional - path to your changelog file. Defaults to 'CHANGELOG.md'
path: 'path/to/my/CHANGELOG.md'
# Optional - format of the release title. Defaults to '{version}'
title-template: 'My Project {version}'
# Optional - format of the release tag. Defaults to '{version}'
tag-template: 'my-project-{version}'
```
> :warning: Make sure you have a `checkout` action before `release-a-changelog`, otherwise it won't be able to read your `CHANGELOG.md` file

## Multi-project setup

Use the `title-template` and `tag-template` inputs to define the format of the release title and tag for each separate project in your repository.
Use `{version}` as a placeholder for the version number.

> :warning: Make sure the `tag-template` is unique for each project in the repository, otherwise releases may clash with each other.

```yaml
name: Release a Changelog
on:
push:
branches:
- master
jobs:
release_a_changelog:
name: Release a Changelog
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Release a Changelog
uses: rasmus-saks/[email protected]
with:
github-token: '${{ secrets.GITHUB_TOKEN }}'
path: 'my-sub-project/CHANGELOG.md'
title-template: 'My Sub Project {version}'
tag-template: 'my-sub-project-{version}'
```


# Usage
1. Add a new version to `CHANGELOG.md` according to [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
2. Push/merge to master
Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ inputs:
description: "Path to the changelog file"
required: false
default: "CHANGELOG.md"
title-template:
description: "Template for the release title. {version} is replaced with the version from the changelog"
required: false
default: "{version}"
tag-template:
description: "Template for the release tag. {version} is replaced with the version from the changelog"
required: false
default: "{version}"
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ async function run() {
const octokit = github.getOctokit(core.getInput("github-token", { required: true }));
const changelogFile = core.getInput("path")
const entry = getLatestChangelogEntry(changelogFile)
const releaseTitle = core.getInput("title-template").replaceAll("{version}", entry.version)
const releaseTag = core.getInput("tag-template").replaceAll("{version}", entry.version)
if (!entry) {
console.log(`Could not find the latest release from ${changelogFile}`)
return
Expand All @@ -16,15 +18,15 @@ async function run() {
try {
await octokit.rest.repos.getReleaseByTag({
...github.context.repo,
tag: entry.version
tag: releaseTag
})
console.log(`A release already exists for ${entry.version}, skipping`)
console.log(`A release already exists for ${releaseTag}, skipping`)
} catch (error) {
console.log(`Could not find a GitHub release for ${entry.version}, creating one`)
console.log(`Could not find a GitHub release for ${releaseTag}, creating one`)
octokit.rest.repos.createRelease({
...github.context.repo,
tag_name: entry.version,
name: entry.version,
tag_name: releaseTag,
name: releaseTitle,
target_commitish: github.context.sha,
body: entry.changelog,
draft: false,
Expand Down
2 changes: 1 addition & 1 deletion node_modules/.package-lock.json

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

4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "release-a-changelog-action",
"version": "1.1.0",
"version": "1.2.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 1281e44

Please sign in to comment.