Add release notes actions #2
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
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 "you@example.com" | |
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] <db@users.noreply.github.com>" | |
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] <db@users.noreply.github.com>" | |
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] <db@users.noreply.github.com>" | |
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] <db@users.noreply.github.com>" | |
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] <db@users.noreply.github.com>" | |
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 |