Skip to content

Commit

Permalink
Merge pull request #1229 from mikepenz/develop
Browse files Browse the repository at this point in the history
dev -> main
  • Loading branch information
mikepenz authored Aug 25, 2023
2 parents 342972d + af326da commit f363eac
Show file tree
Hide file tree
Showing 46 changed files with 24,686 additions and 21,963 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"image": "mcr.microsoft.com/devcontainers/typescript-node:16-bullseye",
"features": {
"ghcr.io/devcontainers/features/node:1": {},
"ghcr.io/devcontainers-contrib/features/typescript:1": {}
"ghcr.io/devcontainers-contrib/features/typescript:2.0.9": {}
},

// Features to add to the dev container. More info: https://containers.dev/features.
Expand All @@ -15,7 +15,7 @@
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "npm install",
"postCreateCommand": "./.devcontainer/postCreateCommand.sh",

// Configure tool-specific properties.
// "customizations": {},
Expand Down
10 changes: 10 additions & 0 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

npm install

# also install dependencies for `pr-collector`
cd pr-collector
npm install
npm run build && npm run package

cd ..
13 changes: 9 additions & 4 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,24 @@ jobs:
with:
node-version: 16.x

- name: Install dependencies
run: npm ci
- name: Build PR-Collector
run: |
cd pr-collector
npm ci
npm run build
npm run package
- name: Rebuild the dist/ directory
- name: Build Action
run: |
npm ci
npm run build
npm run package
- name: Compare the expected and actual dist/ directories
run: |
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff
git diff -a
exit 1
fi
id: diff
Expand Down
56 changes: 50 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ jobs:

- name: Install NPM
run: |
cd pr-collector
npm install
cd ..
npm install
- name: Run NPM
run: |
cd pr-collector
npm run all
cd ..
npm run all
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -113,21 +121,57 @@ jobs:
run: echo "CHANGELOG"

# Showcases the capability to generate the changelog for an external repository provided
- name: "External Repo Configuration"
id: external_changelog
# Showcase ability to only fetch data first, and then continue with exported data later
- name: "External Repo Configuration Collect Report"
id: external_changelog_collect
uses: ./
with:
configuration: "configs/configuration_complex.json"
owner: "mikepenz"
repo: "MaterialDrawer"
fromTag: "v8.1.0"
toTag: "v8.1.6"
token: ${{ secrets.PERSONAL_TOKEN }}
exportCache: true
exportOnly: true

- name: "External Repo Configuration"
id: external_changelog
uses: ./
with:
configuration: "configs/configuration_complex.json"
owner: "mikepenz"
repo: "MaterialDrawer"
cache: ${{ steps.external_changelog_collect.outputs.cache }}

- name: "External Repo Configuration Second"
id: external_changelog_second
uses: ./
with:
configurationJson: |
{
"template": "#{{CHANGELOG}}",
"pr_template": "PR: ##{{NUMBER}}",
"categories": [
{
"title": "## Everything",
"labels": []
}
]
}
owner: "mikepenz"
repo: "MaterialDrawer"
cache: ${{ steps.external_changelog_collect.outputs.cache }}

- name: Echo External Repo Configuration Changelog
env:
CHANGELOG: ${{ steps.external_changelog.outputs.changelog }}
run: echo "$CHANGELOG"
CHANGELOG_SECOND: ${{ steps.external_changelog_second.outputs.changelog }}
run: |
echo "First:"
echo "$CHANGELOG"
echo "Second:"
echo "$CHANGELOG_SECOND"
release:
if: startsWith(github.ref, 'refs/tags/')
Expand All @@ -138,14 +182,14 @@ jobs:

- name: "Build Changelog"
id: github_release
uses: mikepenz/release-changelog-builder-action@v2
uses: mikepenz/release-changelog-builder-action@v4
with:
configuration: "configs/configuration_repo.json"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create Release
uses: softprops/action-gh-release@6034af24fba4e5a8e975aaa6056554efe4c794d0
uses: mikepenz/action-gh-release@v1
with:
body: ${{steps.github_release.outputs.changelog}}
prerelease: ${{ contains(github.ref, '-rc') || contains(github.ref, '-b') || contains(github.ref, '-a') }}
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,7 @@ Thumbs.db

# Ignore built ts files
__tests__/runner/*
lib/**/*
lib/**/*

lib
pr-collector/dist
50 changes: 39 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ A full set list of possible output values for this action.
| `outputs.deletions` | Count of code deletions in this release (lines). |
| `outputs.changes` | Total count of changes in this release (lines). |
| `outputs.commits` | Count of commits which have been added in this release. |

| `outputs.categorized` | The categorized pull requests used to build the changelog as serialized JSON. |
| `outputs.cache` | The file pointing to the cache for the current fetched data. Can be provided to another action step. |

## Full Sample 🖥️

Expand All @@ -99,7 +100,7 @@ Below is a complete example showcasing how to define a build, which is executed
- Build changelog, given the tag
- Create release on GitHub - specifying body with constructed changelog

> Note: PRs will only show up in the changelog if assigned one of the default label categories "feature", "fix" or "test"
> Note: Pre v4 PRs will only show up in the changelog if assigned one of the default label categories "feature", "fix" or "test". Starting with v4 these PRs will be in the `Uncategorized` section.

<details><summary><b>Example</b></summary>
<p>
Expand Down Expand Up @@ -211,6 +212,7 @@ This configuration is a `JSON` in the following format. (The below showcases *ex
"labels": ["fix"]
},
{
"key": "tests",
"title": "## 🧪 Tests",
"labels": ["test"]
},
Expand Down Expand Up @@ -257,6 +259,12 @@ This configuration is a `JSON` in the following format. (The below showcases *ex
"on_property": "title",
"method": "match"
},
"reference": {
"pattern": ".*\\ \\#(.).*",
"on_property": "body",
"method": "replace",
"target": "$1"
},
"transformers": [
{
"pattern": "[\\-\\*] (\\[(...|TEST|CI|SKIP)\\])( )?(.+?)\n(.+?[\\-\\*] )(.+)",
Expand Down Expand Up @@ -325,10 +333,14 @@ For advanced use cases additional settings can be provided to the action
| `includeOpen` | Enables to also fetch currently open PRs. Default: false |
| `ignorePreReleases` | Allows to ignore pre-releases for changelog generation (E.g. for 1.0.1... 1.0.0-rc02 <- ignore, 1.0.0 <- pick). Only used if `fromTag` was not specified. Default: false |
| `failOnError` | Defines if the action will result in a build failure if problems occurred. Default: false |
| `fetchViaCommits` | Enables PRs to get fetched via the commits identified between from->to tag. This will do 1 API request per commit -> Best for scenarios with squash merges | Or shorter from->to diffs (< 10 commits) | Also effective for shorters diffs for very old PRs. Default: false |
| `fetchReviewers` | Will enable fetching the users/reviewers who approved the PR. Default: false |
| `fetchReleaseInformation` | Will enable fetching additional release information from tags. Default: false |
| `fetchReviews` | Will enable fetching the reviews on of the PR. Default: false |
| `commitMode` | Special configuration for projects which work without PRs. Uses commit messages as changelog. This mode looses access to information only available for PRs. Default: false |
| `exportCache` | Will enable exporting the fetched PR information to a cache, which can be re-used by later runs. Default: false |
| `exportOnly` | When enabled, will result in only exporting the cache, without genearting a changelog. Default: false (Requires `exportCache` to be enabled) |
| `cache` | The file path to write/read the cache to/from. |

> **Warning**: `${{ secrets.GITHUB_TOKEN }}` only grants rights to the current repository, for other repositories please use a PAT (Personal Access Token).

Expand Down Expand Up @@ -368,8 +380,10 @@ When using `*` values are joined by `,`.
| `${{REVIEWERS[*]}}` | GitHub Login names of specified reviewers. Requires `fetchReviewers` to be enabled. |
| `${{APPROVERS[*]}}` | GitHub Login names of users who approved the PR. |

Additionally there is a special array placeholder `REVIEWS` which allows access to it's properties:
`(KEY)[(*/index)].(property)` for example: `REVIEWS[*].author` or `REVIEWS[*].body`
Additionally there are special array placeholders like `REVIEWS` which allows access to it's properties via
`(KEY)[(*/index)].(property)`.

For example: `REVIEWS[*].author` or `REVIEWS[*].body`

| **Placeholder** | **Description** |
|-------------------------------|--------------------------------------------|
Expand All @@ -379,6 +393,14 @@ Additionally there is a special array placeholder `REVIEWS` which allows access
| `${{REVIEWS[*].submittedAt}}` | The date whent he review was submitted. |
| `${{REVIEWS[*].state}}` | The state of the given review. |

Similar to `REVIEWS`, `REFERENCED` PRs also offer special placeholders.

| **Placeholder** | **Description** |
|-------------------------------|---------------------------------------------------------------------------|
| `${{REFERENCED[*].number}}` | The PR number of the referenced PR. |
| `${{REFERENCED[*].title}}` | The title of the referenced PR. |
| `${{REFERENCED[*]."..."}}` | Allows to use most other PR properties as placeholder. |

</p>
</details>

Expand Down Expand Up @@ -419,6 +441,7 @@ Table of descriptions for the `configuration.json` options to configure the resu
| **Input** | **Description** |
|-----------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| categories | An array of `category` specifications, offering a flexible way to group changes into categories. |
| category.key | Optional key used for the `categorized` json output. |
| category.title | The display name of a category in the changelog. |
| category.labels | An array of labels, to match pull request labels against. If any PR label matches any category label, the pull request will show up under this category. (See `exhaustive` to change this) |
| category.exclude_labels | Similar to `labels`, an array of labels to match PRs against, but if a match occurs the PR is excluded from this category. |
Expand All @@ -444,6 +467,7 @@ Table of descriptions for the `configuration.json` options to configure the resu
| label_extractor.flags | Defines the regex flags specified for the pattern. Default: `gu`. |
| label_extractor.on_empty | Defines the placeholder to be filled in, if the regex does not lead to a result. |
| duplicate_filter | Defines the `Extractor` to use for retrieving the identifier for a PR. In case of duplicates will keep the last matching pull request (depends on `sort`). See `label_extractor` for details on `Extractor` properties. |
| reference | Defines the `Extractor` to use for resolving the "PR-number" for a parent PR. In case of a match, the child PR will not be included in the release notes. See `label_extractor` for details on `Extractor` properties. |
| transformers | An array of `transform` specifications, offering a flexible API to modify the text per pull request. This is applied on the change text created with `pr_template`. `transformers` are executed per change, in the order specified |
| transformer.pattern | A `regex` pattern, extracting values of the change message. |
| transformer.target | The result pattern, the regex groups will be filled into. Allows for full transformation of a pull request message. Including potentially specified texts |
Expand Down Expand Up @@ -548,16 +572,16 @@ npm test -- custom.test.ts
<p>

```typescript
import {resolveConfiguration} from '../src/utils'
import {mergeConfiguration, resolveConfiguration} from '../src/utils'
import {ReleaseNotesBuilder} from '../src/releaseNotesBuilder'

jest.setTimeout(180000)

it('Test custom changelog builder', async () => {
const configuration = resolveConfiguration(
const configuration = mergeConfiguration(undefined, resolveConfiguration(
'',
'configs_test/configuration_approvers.json'
)
))
const releaseNotesBuilder = new ReleaseNotesBuilder(
null, // baseUrl
null, // token
Expand All @@ -566,19 +590,23 @@ it('Test custom changelog builder', async () => {
'release-changelog-builder-action-playground', // repo
'1.5.0', // fromTag
'2.0.0', // toTag
true, // includeOpen
false, // includeOpen
false, // failOnError
false, // ignorePrePrelease
true, // enable to fetch reviewers
false, // enable to fetch via commits
false, // enable to fetch reviewers
false, // enable to fetch release information
false, // enable to fetch reviews
false, // commitMode
false, // enable commitMode
false, // enable exportCache
false, // enable exportOnly
null, // path to the cache
configuration // configuration
)

const changeLog = await releaseNotesBuilder.build()
console.log(changeLog)
expect(changeLog).toStrictEqual(``)
expect(changeLog).toStrictEqual(`define-expected-output`)
})
```

Expand Down
4 changes: 3 additions & 1 deletion __tests__/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ it('Configurations are merged correctly', async () => {
const mergedConfiguration = mergeConfiguration(configurationJson, configurationFile)

console.log(mergedConfiguration)
expect(JSON.stringify(mergedConfiguration)).toEqual(`{\"max_tags_to_fetch\":200,\"max_pull_requests\":1000,\"max_back_track_time_days\":1000,\"exclude_merge_branches\":[],\"sort\":\"DESC\",\"template\":\"$\{\{CHANGELOG}}\",\"pr_template\":\"- $\{\{TITLE}}\\n - PR: #$\{\{NUMBER}}\",\"empty_template\":\"- no magic changes\",\"categories\":[{\"title\":\"## 🚀 Features\",\"labels\":[\"feature\"]},{\"title\":\"## 🐛 Fixes\",\"labels\":[\"fix\"]},{\"title\":\"## 🧪 Tests\",\"labels\":[\"test\"]}],\"ignore_labels\":[\"ignore\"],\"label_extractor\":[],\"transformers\":[],\"tag_resolver\":{\"method\":\"semver\"},\"base_branches\":[],\"custom_placeholders\":[],\"trim_values\":true}`)
expect(JSON.stringify(mergedConfiguration)).toEqual(
`{\"max_tags_to_fetch\":200,\"max_pull_requests\":1000,\"max_back_track_time_days\":1000,\"exclude_merge_branches\":[],\"sort\":\"DESC\",\"template\":\"$\{\{CHANGELOG}}\",\"pr_template\":\"- $\{\{TITLE}}\\n - PR: #$\{\{NUMBER}}\",\"empty_template\":\"- no magic changes\",\"categories\":[{\"title\":\"## 🚀 Features\",\"labels\":[\"feature\"]},{\"title\":\"## 🐛 Fixes\",\"labels\":[\"fix\"]},{\"title\":\"## 🧪 Tests\",\"labels\":[\"test\"]}],\"ignore_labels\":[\"ignore\"],\"label_extractor\":[],\"transformers\":[],\"tag_resolver\":{\"method\":\"semver\"},\"base_branches\":[],\"custom_placeholders\":[],\"trim_values\":true}`
)
})
Loading

0 comments on commit f363eac

Please sign in to comment.