Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add changelog-existence workflow #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
106 changes: 106 additions & 0 deletions .github/workflows/changelog-existence.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# **what?**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go into a README

# Checks that a file has been committed under the /.changes directory
# as a new CHANGELOG entry. Cannot check for a specific filename as
# it is dynamically generated by change type and timestamp.
#

# **why?**
# Ensure code change gets reflected in the CHANGELOG.

# **when?**
# This will run when called in a workflow.

# Example Usage including required permissions

# permissions:
# contents: read
# pull-requests: write
#
# name: Check Changelog Entry
# jobs:
# changelog:
# uses: dbt-labs/actions/.github/workflows/changelog-check.yml@main
# with:
# changelog_comment: 'Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see [the contributing guide](https://github.com/dbt-labs/dbt-core/blob/main/CONTRIBUTING.md#adding-changelog-entry).'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this requires installing yet another program. This increases the learning curve for new contributors. There should at least be a setting to make this optional and not fail the pipeline.

Are there alternatives? Github can automatically generate a change log when creating a new release: https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes Can you see how it compares to changie?

# skip_label: 'Skip Changelog'
# secrets: inherit # this is only acceptable because we own the action we're calling
#

name: Check Changelog Entry Exists

on:
workflow_call:
inputs:
changelog_comment:
description: The comment text when no changelog is found
type: string
required: true
skip_label:
description: Label on the PR that indicates CHANGELOGs are not required.
type: string
required: true

jobs:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a composite action instead of a workflow? Can you show an example how it would be used, or open a PR in another repo showing that?

changelog_existence:
name: Check if Changelog Exists
if: "!contains(github.event.pull_request.labels.*.name, inputs.skip_label)"
runs-on: ubuntu-latest

steps:

- name: "[DEBUG] - Print Inputs"
shell: bash
id: echo_inputs
run: |
echo "all variables defined as inputs"
echo "Input Comment Text: ${{ inputs.changelog_comment }}"
echo "Input Label for Skipping: ${{ inputs.skip_label }}"
- name: Check if changelog file was added
# https://github.com/marketplace/actions/paths-changes-filter
# For each filter, it sets output variable named by the filter to the text:
# 'true' - if any of changed files matches any of filter rules
# 'false' - if none of changed files matches any of filter rules
uses: dorny/paths-filter@v2
id: changelog_check
with:
token: ${{ secrets.GITHUB_TOKEN }}
filters: |
exists:
- added: '.changes/unreleased/**.yaml'
# this step uses the read permission from the GITHUB_TOKEN it inherits
- name: Check for comment
if: steps.changelog_check.outputs.exists == 'false'
uses: peter-evans/find-comment@v1
id: changelog_comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: ${{ inputs.changelog_comment }}

- name: Set if comment already exists
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this step necessary? Looks like it maps the output of the previous step into a different name.

if: steps.changelog_check.outputs.exists == 'false'
shell: bash
id: comment_check
run: |
if [ '${{ steps.changelog_comment.outputs.comment-body }}' = '' ]; then
echo "::set-output name=exists::false"
echo "Comment does not exist for this PR"
else
echo "::set-output name=exists::true"
echo "Comment already exists for this PR"
fi
# this step uses the write permission on the PR from the GITHUB_TOKEN it inherits
- name: Create PR comment if changelog entry is missing, required, and does not exist
if: |
steps.changelog_check.outputs.exists == 'false' &&
steps.comment_check.outputs.exists == 'false'
uses: peter-evans/create-or-update-comment@v1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work on PRs from forks?

with:
issue-number: ${{ github.event.pull_request.number }}
body: ${{ inputs.changelog_comment }}

- name: Fail job if changelog entry is missing and required
if: steps.changelog_check.outputs.exists == 'false'
uses: actions/github-script@v6
with:
script: core.setFailed('Changelog entry required to merge.')