-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Action: Require Changelog Entry (#31)
* update remote repo ref in deploy-helm * build workflow * add example changelogs * gen readme * add changelog entry * add test scenario * update example usage in README * remove ingressRoute from repo-example * comment out workflow step that breaks * add changelog_version_exists output * change version in no-changes-changelog to match new tag * fix condition for has_new_version output
- Loading branch information
Showing
7 changed files
with
266 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Test require-changelog-entry | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
paths: | ||
- 'require-changelog-entry/**/*' | ||
- '.github/workflows/test-require-changelog-entry.yaml' | ||
|
||
jobs: | ||
test-require-changelog-entry: | ||
name: Test require changelog entry | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Run on CHANGELOG.md | ||
id: changelog | ||
uses: ./require-changelog-entry | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
tag_prefix: require-changelog-entry@ | ||
changelog_path: require-changelog-entry/docs/CHANGELOG.md | ||
|
||
- name: Print CHANGELOG.md Outputs | ||
run: echo "$OUTPUTS" | ||
env: | ||
OUTPUTS: ${{ toJSON(steps.changelog.outputs) }} | ||
|
||
- name: Run on no-changes-changelog.md | ||
id: no_changes_changelog | ||
uses: ./require-changelog-entry | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
tag_prefix: require-changelog-entry@ | ||
changelog_path: require-changelog-entry/docs/no-changes-changelog.md | ||
|
||
- name: Print no-changes-changelog.md Outputs | ||
run: echo "$OUTPUTS" | ||
env: | ||
OUTPUTS: ${{ toJSON(steps.no_changes_changelog.outputs) }} | ||
|
||
# This causes the workflow to error because a CHANGELOG with no base entry is not valid. | ||
# - name: Run on no-versions-changelog.md | ||
# id: no_versions_changelog | ||
# uses: ./require-changelog-entry | ||
# with: | ||
# token: ${{ secrets.GITHUB_TOKEN }} | ||
# tag_prefix: require-changelog-entry@ | ||
# changelog_path: require-changelog-entry/docs/no-versions-changelog.md | ||
|
||
# - name: Print no-versions-changelog.md Outputs | ||
# run: echo "$OUTPUTS" | ||
# env: | ||
# OUTPUTS: ${{ toJSON(steps.no_versions_changelog.outputs) }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,76 @@ | ||
<!-- action-docs-description --> | ||
<!-- action-docs-description --> | ||
## Description | ||
|
||
Checks the CHANGELOG for either new version entry or an updated entry to the "Unreleased" section. | ||
|
||
Logic path: | ||
- Retrieve latest changelog entry via https://github.com/mindsers/changelog-reader-action (set validation_depth to 1, and leave version blank) | ||
- Check tags of repo for matching version, if no matching version is found, all is good and return cleanly | ||
- if matching version is found, this means that this is not a new version | ||
- Checkout the default branch of the repo and use https://github.com/mindsers/changelog-reader-action to pull the "Unreleased" entry of both | ||
- If the description is the different, all is good and return cleanly | ||
- If the description is the same as the default branch version, then no changes have been made and return with an error | ||
|
||
<!-- action-docs-description --> | ||
|
||
## Example Usage | ||
|
||
```yaml | ||
name: Require Changelog Entry | ||
on: | ||
- pull_request | ||
|
||
jobs: | ||
require-changelog-entry: | ||
name: Require Changelog Entry | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Require Changelog Entry | ||
id: changelog | ||
uses: lockerstock/github-actions/require-changelog-entry@main | ||
with: | ||
token: ${{ secret.GITHUB_TOKEN }} | ||
changelog_path: CHANGELOG.md | ||
|
||
- name: 'Error if no Changelog entry' | ||
if: steps.changelog.outputs.has_new_version == 'false' && steps.changelog.outputs.has_unreleased == 'false' | ||
run: | | ||
echo "::error file=CHANGELOG.md::No Changelog entry created." | ||
error 1 | ||
``` | ||
<!-- action-docs-inputs --> | ||
## Inputs | ||
| parameter | description | required | default | | ||
| - | - | - | - | | ||
| token | GITHUB_TOKEN to access the GitHub API if the repository is private | `false` | | | ||
| default_branch | Default branch to compare the "Unreleased" section of the CHANGELOG to. | `false` | ${{ github.event.repository.default_branch }} | | ||
| tag_prefix | Optional prefix string to apply to tag search | `false` | | | ||
| tag_suffix | Optional suffix string to apply to tag search | `false` | | | ||
| changelog_path | Path to CHANGELOG file within repository | `false` | CHANGELOG.md | | ||
|
||
|
||
|
||
<!-- action-docs-inputs --> | ||
|
||
<!-- action-docs-outputs --> | ||
## Outputs | ||
|
||
| parameter | description | | ||
| - | - | | ||
| has_changed | Boolean output indicating whether the CHANGELOG file has changed | | ||
| has_new_version | Boolean output indicating whether a new, untagged version was found in the CHANGELOG | | ||
| changelog_version_exists | Boolean flag indicating whether the latest CHANGELOG version exists as a git tag. | | ||
| has_unreleased | Boolean output indicating whether the "Unreleased" section of the CHANGELOG has changed | | ||
| changelog_latest_version | Latest as-is CHANGELOG version entry. | | ||
| prepared_latest_version | Latest prefix/suffix prepared CHANGELOG version entry. | | ||
| latest_version_entry | The contents of the latest CHANGELOG version entry | | ||
| current_unreleased_entry | The contents of the current "Unreleased" section in the CHANGELOG | | ||
| default_unreleased_entry | The contents of the default branch "Unreleased" section in the CHANGELOG | | ||
|
||
|
||
|
||
<!-- action-docs-outputs --> | ||
|
||
<!-- action-docs-runs --> | ||
## Runs | ||
|
||
This action is a `composite` action. | ||
|
||
|
||
<!-- action-docs-runs --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
name: 'Require Changelog Entry' | ||
description: 'Checks the CHANGELOG for either new version entry or an updated entry to the "Unreleased" section.' | ||
|
||
inputs: | ||
token: | ||
description: GITHUB_TOKEN to access the GitHub API if the repository is private | ||
required: false | ||
|
||
default_branch: | ||
description: Default branch to compare the "Unreleased" section of the CHANGELOG to. | ||
default: ${{ github.event.repository.default_branch }} | ||
required: false | ||
|
||
tag_prefix: | ||
description: Optional prefix string to apply to tag search | ||
required: false | ||
default: '' | ||
|
||
tag_suffix: | ||
description: Optional suffix string to apply to tag search | ||
required: false | ||
default: '' | ||
|
||
changelog_path: | ||
description: Path to CHANGELOG file within repository | ||
required: false | ||
default: 'CHANGELOG.md' | ||
|
||
outputs: | ||
has_changed: | ||
description: 'Boolean output indicating whether the CHANGELOG file has changed' | ||
value: ${{ steps.changes.outputs.changelog }} | ||
|
||
has_new_version: | ||
description: 'Boolean output indicating whether a new, untagged version was found in the CHANGELOG' | ||
value: ${{ steps.tag.outputs.exists == 'false' }} | ||
|
||
changelog_version_exists: | ||
description: 'Boolean flag indicating whether the latest CHANGELOG version exists as a git tag.' | ||
value: ${{ steps.tag.outputs.exists }} | ||
|
||
has_unreleased: | ||
description: 'Boolean output indicating whether the "Unreleased" section of the CHANGELOG has changed' | ||
value: ${{ steps.unreleased.outputs.changed }} | ||
|
||
changelog_latest_version: | ||
description: 'Latest as-is CHANGELOG version entry.' | ||
value: ${{ steps.current_latest.outputs.version }} | ||
|
||
prepared_latest_version: | ||
description: 'Latest prefix/suffix prepared CHANGELOG version entry.' | ||
value: ${{ steps.prepared_latest.outputs.version }} | ||
|
||
latest_version_entry: | ||
description: 'The contents of the latest CHANGELOG version entry' | ||
value: ${{ steps.current_latest.outputs.changes }} | ||
|
||
current_unreleased_entry: | ||
description: 'The contents of the current "Unreleased" section in the CHANGELOG' | ||
value: ${{ steps.current_unreleased.outputs.changes }} | ||
|
||
default_unreleased_entry: | ||
description: 'The contents of the default branch "Unreleased" section in the CHANGELOG' | ||
value: ${{ steps.default_unreleased.outputs.changes }} | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- uses: dorny/paths-filter@v2 | ||
id: changes | ||
with: | ||
filters: | | ||
changelog: | ||
- '${{ inputs.changelog_path }}' | ||
###### Checkout Repository Refs to action_path ###### | ||
|
||
- name: Checkout Repository at current ref | ||
uses: actions/checkout@v3 | ||
with: | ||
token: ${{ inputs.token }} | ||
path: ${{ github.action_path }}/current | ||
|
||
- name: Checkout Repository at default branch | ||
uses: actions/checkout@v3 | ||
with: | ||
token: ${{ inputs.token }} | ||
ref: ${{ inputs.default_branch }} | ||
path: ${{ github.action_path }}/default | ||
|
||
###### Retrieve latest and Unreleased entries from CHANGELOGs ###### | ||
|
||
- name: Get Current Latest Changelog Entry | ||
id: current_latest | ||
uses: mindsers/changelog-reader-action@v2 | ||
with: | ||
validation_level: none | ||
path: ${{ github.action_path }}/current/${{ inputs.changelog_path }} | ||
|
||
- name: Get Current Unreleased Changelog Entry | ||
id: current_unreleased | ||
uses: mindsers/changelog-reader-action@v2 | ||
with: | ||
validation_level: none | ||
path: ${{ github.action_path }}/current/${{ inputs.changelog_path }} | ||
version: Unreleased | ||
|
||
- name: Get Default Unreleased Changelog Entry | ||
id: default_unreleased | ||
uses: mindsers/changelog-reader-action@v2 | ||
with: | ||
validation_level: none | ||
path: ${{ github.action_path }}/default/${{ inputs.changelog_path }} | ||
version: Unreleased | ||
|
||
###### Prepare Latest Tag ###### | ||
|
||
- name: Prepare Latest Tag | ||
id: prepared_latest | ||
run: echo "version=${{ inputs.tag_prefix }}${{ steps.current_latest.outputs.version }}${{ inputs.tag_suffix }}" >> $GITHUB_OUTPUT | ||
shell: bash | ||
|
||
###### Check for Existing Tag ###### | ||
|
||
- name: Check if tag already exists | ||
uses: lockerstock/github-actions/git-tag-exists@main | ||
id: tag | ||
with: | ||
token: ${{ inputs.token }} | ||
tag: ${{ steps.prepared_latest.outputs.version }} | ||
|
||
###### Output Unreleased Changes ###### | ||
|
||
- name: Check for "Unreleased" Changes | ||
id: unreleased | ||
run: | | ||
if [ "${{ steps.current_unreleased.outputs.changes }}" = "${{ steps.default_unreleased.outputs.changes }}" ]; then | ||
echo "changed=false" >> $GITHUB_OUTPUT | ||
else | ||
echo "changed=true" >> $GITHUB_OUTPUT | ||
fi | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters