- introduce capability to define the Configuration via the build yml without the requirement of a file

- this also allows to generate changelogs without the need to chech-out
This commit is contained in:
Mike Penz
2022-07-29 09:21:44 +00:00
committed by GitHub
parent ffcbb8e311
commit 02b79cb00a
7 changed files with 130 additions and 28 deletions
+28 -2
View File
@@ -34,12 +34,38 @@ jobs:
steps:
# the below actions use the local state of the action. please replace `./` with `mikepenz/release-changelog-builder-action@{latest-release}`
# Showcases how to use the action without a prior checkout
# Won't support providing a configuration file, as no checkout was done
# Since 3.2.0 the configuration can be provided within the `yml` file
- name: "Configuration without Checkout"
id: without_checkout
uses: mikepenz/release-changelog-builder-action@develop
uses: ./
with:
toTag: "v0.0.3"
configurationJson: |
{
"template": "${{CHANGELOG}}\n\n<details>\n<summary>Uncategorized</summary>\n\n${{UNCATEGORIZED}}\n</details>",
"categories": [
{
"title": "## 🚀 Features",
"labels": ["feature"]
},
{
"title": "## 🐛 Fixes",
"labels": ["fix"]
},
{
"title": "## 🧪 Tests",
"labels": ["test"]
},
{
"title": "## 💬 Other",
"labels": ["other"]
},
{
"title": "## 📦 Dependencies",
"labels": ["dependencies"]
}
],
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+42 -2
View File
@@ -103,6 +103,9 @@ Below is a complete example showcasing how to define a build, which is executed
> Note: PRs will only show up in the changelog if assigned one of the default label categories "feature", "fix" or "test"
<details><summary><b>Example</b></summary>
<p>
```yml
name: 'CI'
on:
@@ -122,11 +125,47 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
uses: softprops/action-gh-release@v0.1.14
uses: mikepenz/action-gh-release@v0.2.0-a02 #softprops/action-gh-release
with:
body: ${{steps.github_release.outputs.changelog}}
```
</p>
</details>
<details><summary><b>Example w/ Configuration</b></summary>
<p>
```yml
jobs:
release:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Build Changelog
uses: mikepenz/release-changelog-builder-action@v3
with:
configurationJson: |
{
"template": "${{CHANGELOG}}\n\n<details>\n<summary>Uncategorized</summary>\n\n${{UNCATEGORIZED}}\n</details>",
"categories": [
{
"title": "## 💬 Other",
"labels": ["other"]
},
{
"title": "## 📦 Dependencies",
"labels": ["dependencies"]
}
],
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
</p>
</details>
## Customization 🖍️
### Note
@@ -152,7 +191,7 @@ The action supports flexible configuration options to modify vast areas of its b
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
> **Warning** It is required to have a `checkout` step prior to the changelog step, to allow the action to discover the configuration file.
> **Warning** It is required to have a `checkout` step prior to the changelog step if `configuration` is used, to allow the action to discover the configuration file. Use `configurationJson` as alternative.
This configuration is a `.json` file in the following format.
@@ -262,6 +301,7 @@ For advanced use cases additional settings can be provided to the action
| **Input** | **Description** |
|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `configurationJson` | Provide the configuration directly via the build `yml` file. |
| `configuration` | Relative path, to the `configuration.json` file, providing additional configurations |
| `outputFile` | Optional relative path to a file to store the resulting changelog in. |
| `owner` | The owner of the repository to generate the changelog for |
+2
View File
@@ -5,6 +5,8 @@ branding:
icon: 'award'
color: 'green'
inputs:
configurationJson:
description: 'Defines the configuration json. If provided, will be prefered over `configuration`.'
configuration:
description: 'Defines the relative path to the configuration file.'
path:
Generated Vendored
+27 -9
View File
@@ -412,8 +412,17 @@ function run() {
const inputPath = core.getInput('path');
const repositoryPath = (0, utils_1.retrieveRepositoryPath)(inputPath);
// read in configuration file if possible
const configurationFile = core.getInput('configuration');
const configuration = (0, utils_1.resolveConfiguration)(repositoryPath, configurationFile);
let configuration = undefined;
const configurationJson = core.getInput('configurationJson', {
trimWhitespace: true
});
if (configurationJson) {
configuration = (0, utils_1.parseConfiguration)(configurationJson);
}
if (!configuration) {
const configurationFile = core.getInput('configuration');
configuration = (0, utils_1.resolveConfiguration)(repositoryPath, configurationFile);
}
// read in repository inputs
const baseUrl = core.getInput('baseUrl');
const token = core.getInput('token');
@@ -1840,7 +1849,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.writeOutput = exports.directoryExistsSync = exports.resolveConfiguration = exports.failOrError = exports.retrieveRepositoryPath = void 0;
exports.writeOutput = exports.directoryExistsSync = exports.parseConfiguration = exports.resolveConfiguration = exports.failOrError = exports.retrieveRepositoryPath = void 0;
const core = __importStar(__nccwpck_require__(2186));
const fs = __importStar(__nccwpck_require__(7147));
const path = __importStar(__nccwpck_require__(1017));
@@ -1902,23 +1911,32 @@ exports.resolveConfiguration = resolveConfiguration;
* Reads in the configuration from the JSON file
*/
function readConfiguration(filename) {
let rawdata;
try {
rawdata = fs.readFileSync(filename, 'utf8');
const rawdata = fs.readFileSync(filename, 'utf8');
if (rawdata) {
return parseConfiguration(rawdata);
}
}
catch (error) {
core.info(`⚠️ Configuration provided, but it couldn't be found. Fallback to Defaults.`);
return null;
core.debug(`Failed to load configuration due to: ${error}`);
}
core.info(`⚠️ Configuration provided, but it couldn't be found. Fallback to Defaults.`);
return undefined;
}
/**
* Parses the configuration from the JSON file
*/
function parseConfiguration(config) {
try {
const configurationJSON = JSON.parse(rawdata);
const configurationJSON = JSON.parse(config);
return configurationJSON;
}
catch (error) {
core.info(`⚠️ Configuration provided, but it couldn't be parsed. Fallback to Defaults.`);
return null;
return undefined;
}
}
exports.parseConfiguration = parseConfiguration;
/**
* Checks if a given directory exists
*/
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+13 -5
View File
@@ -1,11 +1,13 @@
import * as core from '@actions/core'
import * as github from '@actions/github'
import {
parseConfiguration,
resolveConfiguration,
retrieveRepositoryPath,
writeOutput
} from './utils'
import {ReleaseNotesBuilder} from './releaseNotesBuilder'
import {Configuration} from './configuration'
async function run(): Promise<void> {
core.setOutput('failed', false) // mark the action not failed by default
@@ -17,11 +19,17 @@ async function run(): Promise<void> {
const repositoryPath = retrieveRepositoryPath(inputPath)
// read in configuration file if possible
const configurationFile: string = core.getInput('configuration')
const configuration = resolveConfiguration(
repositoryPath,
configurationFile
)
let configuration: Configuration | undefined = undefined
const configurationJson: string = core.getInput('configurationJson', {
trimWhitespace: true
})
if (configurationJson) {
configuration = parseConfiguration(configurationJson)
}
if (!configuration) {
const configurationFile: string = core.getInput('configuration')
configuration = resolveConfiguration(repositoryPath, configurationFile)
}
// read in repository inputs
const baseUrl = core.getInput('baseUrl')
+17 -9
View File
@@ -67,24 +67,32 @@ export function resolveConfiguration(
/**
* Reads in the configuration from the JSON file
*/
function readConfiguration(filename: string): Configuration | null {
let rawdata: string
function readConfiguration(filename: string): Configuration | undefined {
try {
rawdata = fs.readFileSync(filename, 'utf8')
const rawdata = fs.readFileSync(filename, 'utf8')
if (rawdata) {
return parseConfiguration(rawdata)
}
} catch (error) {
core.info(
`⚠️ Configuration provided, but it couldn't be found. Fallback to Defaults.`
)
return null
core.debug(`Failed to load configuration due to: ${error}`)
}
core.info(
`⚠️ Configuration provided, but it couldn't be found. Fallback to Defaults.`
)
return undefined
}
/**
* Parses the configuration from the JSON file
*/
export function parseConfiguration(config: string): Configuration | undefined {
try {
const configurationJSON: Configuration = JSON.parse(rawdata)
const configurationJSON: Configuration = JSON.parse(config)
return configurationJSON
} catch (error) {
core.info(
`⚠️ Configuration provided, but it couldn't be parsed. Fallback to Defaults.`
)
return null
return undefined
}
}