Skip to content

Commit

Permalink
Improve the readability of the action
Browse files Browse the repository at this point in the history
Rename some outputs and combine some into one
  • Loading branch information
mvantellingen committed Apr 22, 2023
1 parent 97a7153 commit cb38dcd
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,67 +21,77 @@ runs:
using: "composite"
steps:

# When changelog is update, notes are added and unreleased drafts are
# deleted we can safely assume that we need to do a release
- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
changelog:
- CHANGELOG.md
- added|modified: CHANGELOG.md
notes:
- added: .changes/*.md
templates:
- added: .changes/*.tpl.md
unreleased:
- deleted: .changes/unreleased/*.yaml
# Define two output variables:
# - create_release: true if there are open changes, false otherwise
# - is_release: true if this push is the result of a release. Combines
# the status of the changelog, notes and unreleased checks for ease
- name: Check for changelog items
id: drafts
id: status
shell: bash
run: |
if find .changes/unreleased/ -name '*.yaml' | grep .; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "create_release=true" >> $GITHUB_OUTPUT
echo "is_release=false" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "create_release=false" >> $GITHUB_OUTPUT
echo "is_release=${IS_RELEASE}" >> $GITHUB_OUTPUT
fi
shell: bash
env:
IS_RELEASE: ${{ steps.changes.outputs.changelog == 'true' && steps.changes.outputs.notes == 'true' && steps.changes.outputs.unreleased == 'true' }}

- name: Output changes
if: steps.drafts.outputs.exists == 'true'
uses: miniscruff/changie-action@b6d52c80deb236a5b548f8774cd5a18b87da9e9a # v1.0.1
if: steps.status.outputs.create_release == 'true'
uses: miniscruff/changie-action@5c210bdd35a94db41b37513e3e7c2b4dc1e7a4e9 # v1.0.1
id: changelog
with:
version: latest
args: batch --dry-run auto

- name: Batch changes
if: steps.drafts.outputs.exists == 'true'
uses: miniscruff/changie-action@b6d52c80deb236a5b548f8774cd5a18b87da9e9a # v1.0.1
if: steps.status.outputs.create_release == 'true'
uses: miniscruff/changie-action@5c210bdd35a94db41b37513e3e7c2b4dc1e7a4e9 # v1.0.1
with:
version: latest
args: batch auto

- name: Merge changes
if: steps.drafts.outputs.exists == 'true'
uses: miniscruff/changie-action@b6d52c80deb236a5b548f8774cd5a18b87da9e9a # v1.0.1
if: steps.status.outputs.create_release == 'true'
uses: miniscruff/changie-action@5c210bdd35a94db41b37513e3e7c2b4dc1e7a4e9 # v1.0.1
with:
version: latest
args: merge

- name: Get the latest version
id: latest
if: steps.drafts.outputs.exists == 'true' || (steps.changes.outputs.changelog == 'true' && steps.changes.outputs.notes == 'true')
uses: miniscruff/changie-action@b6d52c80deb236a5b548f8774cd5a18b87da9e9a # v1.0.1
if: steps.status.outputs.create_release == 'true' || steps.status.outputs.is_release == 'true'
uses: miniscruff/changie-action@5c210bdd35a94db41b37513e3e7c2b4dc1e7a4e9 # v1.0.1
with:
version: latest
args: latest

- name: Set the version in the package
if: inputs.version-command && steps.drafts.outputs.exists == 'true' || (steps.changes.outputs.changelog == 'true' && steps.changes.outputs.notes == 'true')
if: inputs.version-command && steps.status.outputs.create_release == 'true'
run: ${{ inputs.version-command }}
shell: bash
env:
PACKAGE_VERSION: ${{ steps.latest.outputs.output }}

- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
if: steps.drafts.outputs.exists == 'true'
if: steps.status.outputs.create_release == 'true'
with:
title: Release ${{ steps.latest.outputs.output }}
branch: release/${{ steps.latest.outputs.output }}
Expand All @@ -94,7 +104,7 @@ runs:
${{ steps.changelog.outputs.output }}
- name: Create tag
if: steps.changes.outputs.changelog == 'true' && steps.changes.outputs.notes == 'true' && steps.changes.outputs.templates == 'false'
if: steps.status.outputs.is_release == 'true'
uses: actions/github-script@v6
env:
version: ${{ steps.latest.outputs.output }}
Expand All @@ -109,7 +119,7 @@ runs:
})
- name: Create release notes
if: steps.changes.outputs.changelog == 'true' && steps.changes.outputs.notes == 'true' && steps.changes.outputs.templates == 'false'
if: steps.status.outputs.is_release == 'true'
shell: bash
id: release-notes
run: |
Expand All @@ -121,7 +131,7 @@ runs:
echo "$EOF" >> $GITHUB_OUTPUT
- name: Create GitHub release
if: steps.changes.outputs.changelog == 'true' && steps.changes.outputs.notes == 'true' && steps.changes.outputs.templates == 'false'
if: steps.status.outputs.is_release == 'true'
uses: actions/github-script@v6
env:
version: ${{ steps.latest.outputs.output }}
Expand All @@ -141,7 +151,7 @@ runs:
# We need to manually trigger a release workflow since GitHub actions cannot
# automatically trigger other GitHub actions.
- name: Trigger release
if: steps.changes.outputs.changelog == 'true' && steps.changes.outputs.notes == 'true' && steps.changes.outputs.templates == 'false' && inputs.release-workflow != ''
if: steps.status.outputs.is_release == 'true' && inputs.release-workflow != ''
shell: bash
run: gh workflow run ${{ inputs.release-workflow }} --ref ${{ steps.latest.outputs.output }}
env:
Expand Down

0 comments on commit cb38dcd

Please sign in to comment.