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

Fix changelog checker #4387

Merged
merged 3 commits into from
Nov 23, 2021
Merged
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
23 changes: 13 additions & 10 deletions .github/scripts/changelog.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#! /usr/bin/ruby
# Check if a .changes file is added/modified in a pull request *or* the "No
# changelog needed" box in the pull request description is ticked. If neither of
# these are true, exit 1 to fail the check.
#
# List of added/modified in the pull request is stored in ARGV
require 'json'

# if true we exit with 0, so the test is sucessefull. otherwise the test fail.
def check_changelog?(pr_body, files)
return true if pr_body.match(/\[x\]\s+No\s+changelog\s+needed/i)

puts 'Looking for a .changes file...'
files.any? { |f| f.include? '.changes' }
def not_needed?(pr_body)
pr_body.match(/\[x\]\s+No\s+changelog\s+needed/i)
end

github_event = JSON.parse(File.read(ENV['GITHUB_EVENT_PATH']))
files = ARGV[0].split(' ')
puts "-" * 20, "PR Description: #{github_event['pull_request']['body']}"
puts "-" * 20, "Files modified: #{files}"
check_changelog?(github_event['pull_request']['body'], files) ? exit(0) : exit(1)
pr_body = github_event['pull_request']['body']
puts '-' * 20, "PR Description: #{github_event['pull_request']['body']}"
puts '-' * 20, "Added or modified .changes files: #{ARGV}"

exit(0) unless ARGV.empty?
not_needed?(pr_body) ? exit(0) : exit(1)
11 changes: 7 additions & 4 deletions .github/workflows/changelog_checker.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: changelog_test

on:
pull_request:
pull_request_target:
types: [opened, edited, synchronize, reopened, closed]

jobs:
Expand All @@ -14,10 +14,13 @@ jobs:
with:
fetch-depth: 1
- uses: actions/setup-ruby@v1
- name: Run a changelog checker
- id: files
uses: Ana06/[email protected]
with:
filter: '*.changes'
- name: Run changelog checker
run: |
files_modified=`git diff --name-only "origin/$GITHUB_BASE_REF..HEAD" | xargs`
ruby .github/scripts/changelog.rb "$files_modified"
ruby .github/scripts/changelog.rb ${{ steps.files.outputs.added_modified }}

changelog_approved:
if: github.event.action != 'closed'
Expand Down