-
Notifications
You must be signed in to change notification settings - Fork 3
124 lines (110 loc) · 4.53 KB
/
changelog-existence.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# **what?**
# Checks that a file has been committed under the /.changes directory,
# within the 'unreleased' directory or `unreleased_dir`,
# as a new or modified 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
# on:
# pull_request_target:
# types: [opened, reopened, labeled, unlabeled, synchronize]
#
# 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).'
# skip_label: 'Skip Changelog'
# unreleased_dir: 'unreleased'
# 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
unreleased_dir:
description: The subdirectory unreleased changelogs are expected to be found. By default, this is 'unreleased'.
type: string
required: false
default: 'unreleased'
permissions:
contents: read
pull-requests: write
jobs:
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 "inputs.changelog_comment: ${{ inputs.changelog_comment }}"
echo "inputs.skip_label: ${{ inputs.skip_label }}"
echo "inputs.unreleased_dir: ${{ inputs.unreleased_dir }}"
- 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@v3
id: changelog_check
with:
token: ${{ secrets.GITHUB_TOKEN }}
filters: |
exists:
- added|modified: '.changes/${{ inputs.unreleased_dir }}/**.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@v3
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
if: steps.changelog_check.outputs.exists == 'false'
shell: bash
id: comment_check
run: |
if [ '${{ steps.changelog_comment.outputs.comment-body }}' = '' ]; then
echo "exists=false" >> $GITHUB_OUTPUT
echo "Comment does not exist for this PR"
else
echo "exists=true" >> $GITHUB_OUTPUT
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'
run: |
gh issue comment ${{ github.event.pull_request.number }} --repo ${{ github.repository }} --body "${{ inputs.changelog_comment }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Fail job if changelog entry is missing and required
if: steps.changelog_check.outputs.exists == 'false'
uses: actions/github-script@v7
with:
script: core.setFailed('Changelog entry required to merge.')