Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/reusable_trigger_prerelease.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
fetch-depth: 0
ref: ${{ github.event.repository.default_branch }}
token: "${{ secrets.bot_token }}"
- uses: newrelic/release-toolkit/contrib/ohi-release-notes@v1
- uses: ./actions/ohi-release-notes
id: release-data
with:
excluded-dirs: "${{ inputs.rt-excluded-dirs }}"
Expand Down
256 changes: 256 additions & 0 deletions .github/workflows/self_test_actions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
name: Self-test
on:
pull_request:
push:
branches:
- main
jobs:
contrib-ohi-release-notes:
name: validate ohi-release-notes (contrib action)
runs-on: ubuntu-latest
env:
MOCK_REPO_ACTION: ./mock_repo_action
MOCK_REPO_SCRIPT: ./mock_repo_script
ACTION_OUTPUTS: ./action_outputs
steps:
- uses: actions/checkout@v4
- name: Configure test repo
shell: bash
run: |
# MOCK_REPO_SCRIPT is not needed as it is copied from ACTION one.
mkdir -pv "${MOCK_REPO_ACTION}" "${ACTION_OUTPUTS}"
cd "${MOCK_REPO_ACTION}"

git config --global user.email "[email protected]"
git config --global user.name "Your Name"

git init
cat > CHANGELOG.md <<EOF
# Changelog
This is based on blah blah blah

## v1.2.3 - 20YY-DD-MM

### Enhancements
- This is in the past and should be preserved
EOF

git add CHANGELOG.md
for i in 1 2 3; do
touch file$i
git add file$i
git commit -m commit_$i
done
git tag 1.2.3

touch dependencies
git add dependencies
git commit -m "chore(deps): bump newrelic/infrastructure from 0.0.0 to 0.0.1 (#1)" --author="dependabot[bot] <[email protected]>"

touch dependencies1
git add dependencies1
git commit -m "chore(deps): bump github.com/stretchr/testify from 1.7.0 to 1.8.0" --author="dependabot[bot] <[email protected]>"

touch dependencies-skip1
git add dependencies-skip1
git commit -m "chore(deps): bump newrelic/infrastructure from 0.0.1 to 0.0.2 (#2)" --author="dependabot[bot] <[email protected]>"

mkdir dependencies-repo-skip
touch dependencies-repo-skip/dependencies-skip2
git add dependencies-repo-skip/dependencies-skip2
git commit -m "chore(deps): bump newrelic/infrastructure from 0.0.2 to 0.0.3 (#3)" --author="dependabot[bot] <[email protected]>"

mkdir dependencies-repo
touch dependencies-repo/dependencies
git add dependencies-repo/dependencies
git commit -m "chore(deps): bump newrelic/nri-docker from 0.0.3 to 1.8.26 (#4)" --author="dependabot[bot] <[email protected]>"

cat > CHANGELOG.md <<EOF
# Changelog
This is based on blah blah blah

## Unreleased
### Enhancement
- test

## v1.2.3 - 20YY-DD-MM

### Enhancements
- This is in the past and should be preserved
EOF

cd $OLDPWD
cp -r "${MOCK_REPO_ACTION}" "${MOCK_REPO_SCRIPT}"
- name: Expected CHANGELOG
shell: bash
run: |
cat > expected-changelog.md <<EOF
# Changelog
This is based on blah blah blah

## Unreleased

## v2.0.0 - $(date +%Y-%m-%d)

### 🚀 Enhancements
- test

### ⛓️ Dependencies
- Upgraded newrelic/infrastructure from 0.0.0 to 0.0.1 - [Changelog 🔗](https://github.com/newrelic/infrastructure-agent/releases/tag/0.0.1)
- Upgraded newrelic/nri-docker from 0.0.3 to 1.8.26 - [Changelog 🔗](https://github.com/newrelic/nri-docker/releases/tag/v1.8.26)

## v1.2.3 - 20YY-DD-MM

### Enhancements
- This is in the past and should be preserved
EOF
- name: Expected partial CHANGELOG
shell: bash
run: |
cat > expected-partial.md <<EOF
## v2.0.0 - $(date +%Y-%m-%d)

### 🚀 Enhancements
- test

### ⛓️ Dependencies
- Upgraded newrelic/infrastructure from 0.0.0 to 0.0.1 - [Changelog 🔗](https://github.com/newrelic/infrastructure-agent/releases/tag/0.0.1)
- Upgraded newrelic/nri-docker from 0.0.3 to 1.8.26 - [Changelog 🔗](https://github.com/newrelic/nri-docker/releases/tag/v1.8.26)
EOF

- name: Run action
uses: ./actions/ohi-release-notes
id: ohi-release-notes
with:
git-root: ${{ env.MOCK_REPO_ACTION }}
excluded-files: dependencies-skip1
excluded-dirs: dependencies-repo-skip
included-dirs: dependencies-repo
included-files: dependencies,dependencies1
- name: Run script
run: |
cd "${{ env.MOCK_REPO_SCRIPT }}"
# CLI autodetects whether it is running on GHA or not. If we let GHA set this to true, as it normally does,
# tests cases where GITHUB_ACTIONS is expected to be unset would fail.
GITHUB_ACTIONS=false "${GITHUB_WORKSPACE}/actions/ohi-release-notes/run.sh" --included-dirs dependencies-repo --included-files dependencies,dependencies1 --excluded-files dependencies-skip1 --excluded-dirs dependencies-repo-skip
- name: Action outputs
working-directory: ${{ env.ACTION_OUTPUTS }}
run: |
echo -ne "${{ steps.ohi-release-notes.outputs.changelog }}" > CHANGELOG.md
echo -ne "${{ steps.ohi-release-notes.outputs.changelog-partial }}" > CHANGELOG.partial.md

- name: Asserts
run: |
exit_status=0

echo "Action's CHANGELOG.md should be equal"
echo RESULT:
cat "${{ env.MOCK_REPO_ACTION }}/CHANGELOG.md"
echo EXPECTED:
cat expected-changelog.md
echo TEST:
if cmp --silent expected-changelog.md ${{ env.MOCK_REPO_ACTION }}/CHANGELOG.md; then
echo PASS
else
echo FAIL - diff between expected and the output:
diff expected-changelog.md ${{ env.MOCK_REPO_ACTION }}/CHANGELOG.md
((exit_status++))
fi
echo =================================================================
echo "script's CHANGELOG.md should be equal"
echo RESULT:
cat "${{ env.MOCK_REPO_SCRIPT }}/CHANGELOG.md"
echo EXPECTED:
cat expected-changelog.md
echo TEST:
if cmp --silent expected-changelog.md ${{ env.MOCK_REPO_SCRIPT }}/CHANGELOG.md; then
echo PASS
else
echo FAIL - diff between expected and the output:
diff expected-changelog.md ${{ env.MOCK_REPO_SCRIPT }}/CHANGELOG.md
((exit_status++))
fi
echo =================================================================
echo "script's CHANGELOG.md should be equal"
echo RESULT:
cat "${{ env.MOCK_REPO_SCRIPT }}/CHANGELOG.md"
echo EXPECTED:
cat expected-changelog.md
echo TEST:
if cmp --silent expected-changelog.md ${{ env.MOCK_REPO_SCRIPT }}/CHANGELOG.md; then
echo PASS
else
echo FAIL - diff between expected and the output:
diff expected-changelog.md ${{ env.ACTION_OUTPUTS }}/CHANGELOG.md
((exit_status++))
fi
echo =================================================================
echo "Action's CHANGELOG.partial.md should be equal"
echo RESULT:
cat "${{ env.MOCK_REPO_ACTION }}/CHANGELOG.partial.md"
echo EXPECTED:
cat expected-partial.md
echo TEST:
if cmp --silent expected-partial.md ${{ env.MOCK_REPO_ACTION }}/CHANGELOG.partial.md; then
echo PASS
else
echo FAIL - diff between expected and the output:
diff expected-partial.md ${{ env.MOCK_REPO_ACTION }}/CHANGELOG.partial.md
((exit_status++))
fi
echo =================================================================
echo "script's CHANGELOG.partial.md should be equal"
echo RESULT:
cat "${{ env.MOCK_REPO_SCRIPT }}/CHANGELOG.partial.md"
echo EXPECTED:
cat expected-partial.md
echo TEST:
if cmp --silent expected-partial.md ${{ env.MOCK_REPO_SCRIPT }}/CHANGELOG.partial.md; then
echo PASS
else
echo FAIL - diff between expected and the output:
diff expected-partial.md ${{ env.MOCK_REPO_SCRIPT }}/CHANGELOG.partial.md
((exit_status++))
fi
echo =================================================================
echo "script's CHANGELOG.partial.md should be equal"
echo RESULT:
cat "${{ env.MOCK_REPO_SCRIPT }}/CHANGELOG.partial.md"
echo EXPECTED:
cat expected-partial.md
echo TEST:
if cmp --silent expected-partial.md ${{ env.MOCK_REPO_SCRIPT }}/CHANGELOG.partial.md; then
echo PASS
else
echo FAIL - diff between expected and the output:
diff expected-partial.md ${{ env.ACTION_OUTPUTS }}/CHANGELOG.partial.md
((exit_status++))
fi
echo =================================================================
echo "action output 'next-version' return the expected value"
echo EXPECTED:
echo "v2.0.0"
echo RESULT:
echo "${{ steps.ohi-release-notes.outputs.next-version }}"
echo TEST:
if [ "${{ steps.ohi-release-notes.outputs.next-version }}" = "v2.0.0" ] ; then
echo PASS
else
echo FAIL - action output 'next-version' does not return the expected value
((exit_status++))
fi
echo =================================================================
echo "action output 'release-title' return the expected value"
echo EXPECTED:
echo "v2.0.0 - $(date +%Y-%m-%d)"
echo RESULT:
echo "${{ steps.ohi-release-notes.outputs.release-title }}"
echo TEST:
if [ "${{ steps.ohi-release-notes.outputs.release-title }}" = "v2.0.0 - $(date +%Y-%m-%d)" ] ; then
echo PASS
else
echo FAIL - action output 'release-title' does not return the expected value
((exit_status++))
fi

exit $exit_status
48 changes: 48 additions & 0 deletions actions/ohi-release-notes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 🛠️ `ohi-release-notes`

This is a wrapper of all the steps needed to update the changelog and render a snippet to be ready to be used as a release message. This contribution also includes a script that allow to replicate what this action does locally.

## Example Usage

```yaml
- uses: newrelic/coreint-automation/actions/ohi-release-notes@v3
id: release
- name: Commit updated changelog
run: |
git add CHANGELOG.md
git commit -m "Update changelog with changes from ${{ steps.release.outputs.next-version }}"
git push -u origin main
gh release create ${{ steps.release.outputs.release-title }} --target $(git rev-parse HEAD) --notes-file CHANGELOG.partial.md
```

## Parameters

All parameters are optional:
* `excluded-dirs` exclude commits whose changes only impact files in specified dirs relative to repository root. Defaults to ".github".
* `excluded-files` Exclude commits whose changes only impact files in specified files relative to repository root. Defaults to "".
* `included-dirs` Only scan commits scoping at least one file in any of the following comma-separated directories
* `included-files` Only scan commits scoping at least one file in the following comma-separated list
* `fail-if-held` fails if the held toggle is active
* `dictionary` sets the link dependency dictionary file path. Defaults to ".github/rt-dictionary.yml".
* `excluded-dependencies-manifest` sets the excluded dependencies manifest. Defaults to ".github/excluded-dependencies.yml".

## Outputs

* `next-version` contains the calculated version for this.
* `release-title` is the title of the release that includes `next-version` and the date it was done.
* `release-changelog` contains the complete changelog of this release. Alias of the file `CHANGELOG.md`
* `release-changelog-partial` contains the changelog for only this release. Alias of the file `CHANGELOG.partial.md`

This action also leaves the files `CHANGELOG.md` and `CHANGELOG.partial.md` at the working directory so they are also ready to be committed.

## Use script locally
There is a `run.sh` script that should do the same as this action: Leaves the files `CHANGELOG.md` and `CHANGELOG.partial.md` at the working directory and prints the title of the release with the next version and the date.

You can run it by bashpipeing this script:
```shell
curl "https://raw.githubusercontent.com/newrelic/release-toolkit/v1/contrib/ohi-release-notes/run.sh" | bash
```

## Contributing

Standard policy and procedure across the New Relic GitHub organization.
Loading