Merge pull request #833 from mikepenz/feature/config_json_in_yml
Provide configuration as string in `ci.yml`
This commit is contained in:
@@ -16,6 +16,10 @@ on:
|
|||||||
- '**.md'
|
- '**.md'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.event.pull_request.number }}-check
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check-dist:
|
check-dist:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ on:
|
|||||||
- '*'
|
- '*'
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.event.pull_request.number }}-ci
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
if: github.event_name == 'pull_request'
|
if: github.event_name == 'pull_request'
|
||||||
@@ -34,12 +38,38 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
# the below actions use the local state of the action. please replace `./` with `mikepenz/release-changelog-builder-action@{latest-release}`
|
# 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
|
# 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"
|
- name: "Configuration without Checkout"
|
||||||
id: without_checkout
|
id: without_checkout
|
||||||
uses: mikepenz/release-changelog-builder-action@develop
|
uses: mikepenz/release-changelog-builder-action@develop
|
||||||
with:
|
with:
|
||||||
toTag: "v0.0.3"
|
toTag: "v3.1.1"
|
||||||
|
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:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ on:
|
|||||||
schedule:
|
schedule:
|
||||||
- cron: '41 22 * * 4'
|
- cron: '41 22 * * 4'
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.event.pull_request.number }}-codeql
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
analyze:
|
analyze:
|
||||||
name: Analyze
|
name: Analyze
|
||||||
|
|||||||
@@ -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"
|
> 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
|
```yml
|
||||||
name: 'CI'
|
name: 'CI'
|
||||||
on:
|
on:
|
||||||
@@ -122,11 +125,47 @@ jobs:
|
|||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Create Release
|
- 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:
|
with:
|
||||||
body: ${{steps.github_release.outputs.changelog}}
|
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 🖍️
|
## Customization 🖍️
|
||||||
|
|
||||||
### Note
|
### Note
|
||||||
@@ -152,7 +191,7 @@ The action supports flexible configuration options to modify vast areas of its b
|
|||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
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.
|
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** |
|
| **Input** | **Description** |
|
||||||
|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `configurationJson` | Provide the configuration directly via the build `yml` file. Please note that `${{}}` has to be written as `#{{}}` within the `yml` file. |
|
||||||
| `configuration` | Relative path, to the `configuration.json` file, providing additional configurations |
|
| `configuration` | Relative path, to the `configuration.json` file, providing additional configurations |
|
||||||
| `outputFile` | Optional relative path to a file to store the resulting changelog in. |
|
| `outputFile` | Optional relative path to a file to store the resulting changelog in. |
|
||||||
| `owner` | The owner of the repository to generate the changelog for |
|
| `owner` | The owner of the repository to generate the changelog for |
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ branding:
|
|||||||
icon: 'award'
|
icon: 'award'
|
||||||
color: 'green'
|
color: 'green'
|
||||||
inputs:
|
inputs:
|
||||||
|
configurationJson:
|
||||||
|
description: 'Defines the configuration json. If provided, will be prefered over `configuration`.'
|
||||||
configuration:
|
configuration:
|
||||||
description: 'Defines the relative path to the configuration file.'
|
description: 'Defines the relative path to the configuration file.'
|
||||||
path:
|
path:
|
||||||
|
|||||||
+27
-8
@@ -412,8 +412,17 @@ function run() {
|
|||||||
const inputPath = core.getInput('path');
|
const inputPath = core.getInput('path');
|
||||||
const repositoryPath = (0, utils_1.retrieveRepositoryPath)(inputPath);
|
const repositoryPath = (0, utils_1.retrieveRepositoryPath)(inputPath);
|
||||||
// read in configuration file if possible
|
// read in configuration file if possible
|
||||||
|
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');
|
const configurationFile = core.getInput('configuration');
|
||||||
const configuration = (0, utils_1.resolveConfiguration)(repositoryPath, configurationFile);
|
configuration = (0, utils_1.resolveConfiguration)(repositoryPath, configurationFile);
|
||||||
|
}
|
||||||
// read in repository inputs
|
// read in repository inputs
|
||||||
const baseUrl = core.getInput('baseUrl');
|
const baseUrl = core.getInput('baseUrl');
|
||||||
const token = core.getInput('token');
|
const token = core.getInput('token');
|
||||||
@@ -1840,7 +1849,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
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 core = __importStar(__nccwpck_require__(2186));
|
||||||
const fs = __importStar(__nccwpck_require__(7147));
|
const fs = __importStar(__nccwpck_require__(7147));
|
||||||
const path = __importStar(__nccwpck_require__(1017));
|
const path = __importStar(__nccwpck_require__(1017));
|
||||||
@@ -1902,23 +1911,33 @@ exports.resolveConfiguration = resolveConfiguration;
|
|||||||
* Reads in the configuration from the JSON file
|
* Reads in the configuration from the JSON file
|
||||||
*/
|
*/
|
||||||
function readConfiguration(filename) {
|
function readConfiguration(filename) {
|
||||||
let rawdata;
|
|
||||||
try {
|
try {
|
||||||
rawdata = fs.readFileSync(filename, 'utf8');
|
const rawdata = fs.readFileSync(filename, 'utf8');
|
||||||
|
if (rawdata) {
|
||||||
|
return parseConfiguration(rawdata);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.info(`⚠️ Configuration provided, but it couldn't be found. Fallback to Defaults.`);
|
core.debug(`Failed to load configuration due to: ${error}`);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
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 {
|
try {
|
||||||
const configurationJSON = JSON.parse(rawdata);
|
// for compatiblity with the `yml` file we require to use `#{{}}` instead of `${{}}` - replace it here.
|
||||||
|
const configurationJSON = JSON.parse(config.replace(/#{{/g, '${{'));
|
||||||
return configurationJSON;
|
return configurationJSON;
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.info(`⚠️ Configuration provided, but it couldn't be parsed. Fallback to Defaults.`);
|
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
|
* Checks if a given directory exists
|
||||||
*/
|
*/
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
+12
-4
@@ -1,11 +1,13 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as github from '@actions/github'
|
import * as github from '@actions/github'
|
||||||
import {
|
import {
|
||||||
|
parseConfiguration,
|
||||||
resolveConfiguration,
|
resolveConfiguration,
|
||||||
retrieveRepositoryPath,
|
retrieveRepositoryPath,
|
||||||
writeOutput
|
writeOutput
|
||||||
} from './utils'
|
} from './utils'
|
||||||
import {ReleaseNotesBuilder} from './releaseNotesBuilder'
|
import {ReleaseNotesBuilder} from './releaseNotesBuilder'
|
||||||
|
import {Configuration} from './configuration'
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
core.setOutput('failed', false) // mark the action not failed by default
|
core.setOutput('failed', false) // mark the action not failed by default
|
||||||
@@ -17,11 +19,17 @@ async function run(): Promise<void> {
|
|||||||
const repositoryPath = retrieveRepositoryPath(inputPath)
|
const repositoryPath = retrieveRepositoryPath(inputPath)
|
||||||
|
|
||||||
// read in configuration file if possible
|
// read in configuration file if possible
|
||||||
|
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')
|
const configurationFile: string = core.getInput('configuration')
|
||||||
const configuration = resolveConfiguration(
|
configuration = resolveConfiguration(repositoryPath, configurationFile)
|
||||||
repositoryPath,
|
}
|
||||||
configurationFile
|
|
||||||
)
|
|
||||||
|
|
||||||
// read in repository inputs
|
// read in repository inputs
|
||||||
const baseUrl = core.getInput('baseUrl')
|
const baseUrl = core.getInput('baseUrl')
|
||||||
|
|||||||
+18
-7
@@ -67,24 +67,35 @@ export function resolveConfiguration(
|
|||||||
/**
|
/**
|
||||||
* Reads in the configuration from the JSON file
|
* Reads in the configuration from the JSON file
|
||||||
*/
|
*/
|
||||||
function readConfiguration(filename: string): Configuration | null {
|
function readConfiguration(filename: string): Configuration | undefined {
|
||||||
let rawdata: string
|
|
||||||
try {
|
try {
|
||||||
rawdata = fs.readFileSync(filename, 'utf8')
|
const rawdata = fs.readFileSync(filename, 'utf8')
|
||||||
|
if (rawdata) {
|
||||||
|
return parseConfiguration(rawdata)
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
core.debug(`Failed to load configuration due to: ${error}`)
|
||||||
|
}
|
||||||
core.info(
|
core.info(
|
||||||
`⚠️ Configuration provided, but it couldn't be found. Fallback to Defaults.`
|
`⚠️ Configuration provided, but it couldn't be found. Fallback to Defaults.`
|
||||||
)
|
)
|
||||||
return null
|
return undefined
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Parses the configuration from the JSON file
|
||||||
|
*/
|
||||||
|
export function parseConfiguration(config: string): Configuration | undefined {
|
||||||
try {
|
try {
|
||||||
const configurationJSON: Configuration = JSON.parse(rawdata)
|
// for compatiblity with the `yml` file we require to use `#{{}}` instead of `${{}}` - replace it here.
|
||||||
|
const configurationJSON: Configuration = JSON.parse(
|
||||||
|
config.replace(/#{{/g, '${{')
|
||||||
|
)
|
||||||
return configurationJSON
|
return configurationJSON
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.info(
|
core.info(
|
||||||
`⚠️ Configuration provided, but it couldn't be parsed. Fallback to Defaults.`
|
`⚠️ Configuration provided, but it couldn't be parsed. Fallback to Defaults.`
|
||||||
)
|
)
|
||||||
return null
|
return undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user