Skip to content

Commit befe421

Browse files
authored
Implement CHANGELOG check (#4018)
* Initial test using dangerfiles. * Add ruby version * Add setup script. * Fix path to setup script. * Right modes. * Adjust token * Add gemfile. * Add yml for testing * Use labels for no-changelog. * Simplify dangerfile * Cleanup files. * Conditionally enable check during development * Run in ubuntu instead of macos * Don't run check on YAML file changes. * Use changelog instead of danger as name of the check. * Adjust naming * Get rid of .ruby-version * Put all danger related files inside ci/danger * Fix typo * Move working-directory to the right section * Another fix try * Only run the actual command inside the subir * Use cd instead * Fix path. * Copy gemfiles to root * Add Gemfile.lock to the repo * Use env var to point to the right Gemfile * Exclude more entries based on their directory and expand test team * Refactor has_sdk_changes into a function. * Increase depth to make Danger happy. See https://gitlab.com/gitlab-org/gitlab/-/issues/289953 for a related issue. * typo. * fetch-dept should be in a With block * Make exclude_directories global since that's what it is * Use same checkout config as other GA * Fetch depth 100 * Filter by directory only. Extension based filtering is too verbose.
1 parent 46293c9 commit befe421

File tree

5 files changed

+235
-0
lines changed

5 files changed

+235
-0
lines changed

.github/workflows/changelog.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Changelog
2+
3+
on:
4+
pull_request
5+
6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
8+
cancel-in-progress: true
9+
10+
jobs:
11+
danger:
12+
runs-on: ubuntu-22.04
13+
env:
14+
BUNDLE_GEMFILE: ./ci/danger/Gemfile
15+
steps:
16+
- uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 100
19+
submodules: true
20+
- uses: ruby/setup-ruby@v1
21+
with:
22+
ruby-version: '2.7'
23+
- name: Setup Bundler
24+
run: ./ci/danger/setup_bundler.sh
25+
- name: Danger CHANGELOG verifier
26+
env:
27+
DANGER_GITHUB_API_TOKEN: ${{ secrets.GOOGLE_OSS_BOT_TOKEN }}
28+
run:
29+
'[ ! -z $DANGER_GITHUB_API_TOKEN ] && bundle exec danger --dangerfile=./ci/danger/Dangerfile || echo "Skipping Danger for External Contributor"'

ci/danger/Dangerfile

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
## Copyright 2022 Google LLC
2+
##
3+
## Licensed under the Apache License, Version 2.0 (the "License");
4+
## you may not use this file except in compliance with the License.
5+
## You may obtain a copy of the License at
6+
##
7+
## http://www.apache.org/licenses/LICENSE-2.0
8+
##
9+
## Unless required by applicable law or agreed to in writing, software
10+
## distributed under the License is distributed on an "AS IS" BASIS,
11+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
## See the License for the specific language governing permissions and
13+
## limitations under the License.
14+
15+
### Helper functions
16+
17+
# Determine if there are changes in files matching any of the
18+
# path patterns provided.
19+
def shouldFileBeExcluded(file, exclude_paths)
20+
return exclude_paths.any? { |dir| file.include? dir }
21+
end
22+
23+
# Determine if there are changes in files matching any of the
24+
# path patterns provided.
25+
def hasChangesIn(paths)
26+
path_array = Array(paths)
27+
path_array.each do |dir|
28+
if !git.modified_files.grep(/#{dir}/).empty?
29+
return true
30+
end
31+
end
32+
return false
33+
end
34+
35+
### Definitions
36+
37+
# Label for any change that shouldn't have an accompanying CHANGELOG entry,
38+
# including all changes that do not affect the compiled binary (i.e. script
39+
# changes, test-only changes)
40+
declared_trivial = github.pr_labels.include? "no-changelog"
41+
42+
# Whether or not there are pending changes to any changelog file.
43+
has_changelog_changes = hasChangesIn(["CHANGELOG"])
44+
45+
# Ignore changes in these directories
46+
$exclude_directories = [
47+
'.github/',
48+
'buildSrc/',
49+
'ci/',
50+
'encoders/',
51+
'firebase-annotations/',
52+
'firebase-components/',
53+
'firebase-datatransport/',
54+
'gradle/',
55+
'health-metrics/',
56+
'integ-testing/',
57+
'protolite-well-known-types/',
58+
'smoke-tests/',
59+
'third_party/',
60+
'tools/',
61+
'transport/'
62+
]
63+
64+
# Whether or not the PR has modified SDK source files.
65+
def has_sdk_changes()
66+
files = (git.modified_files +
67+
git.added_files +
68+
git.deleted_files)
69+
return files.any? { |file|
70+
!shouldFileBeExcluded(file, $exclude_directories)
71+
}
72+
end
73+
74+
tester_team = [
75+
'rlazo',
76+
'vkryachko',
77+
'yifanyang',
78+
'VinayGuthal',
79+
'davidmotson',
80+
'daymxn',
81+
'emilypgoogle'
82+
]
83+
84+
is_enabled = true if tester_team.include? github.pr_author
85+
86+
### Actions
87+
88+
# Warn if a changelog is left out on a non-trivial PR that has modified
89+
# SDK source files.
90+
#
91+
# TODO: remove the `is_enabled` after tests are complete
92+
if is_enabled && has_sdk_changes()
93+
if !has_changelog_changes && !declared_trivial
94+
warning = "Did you forget to add a changelog entry? (Add the 'no-changelog'"\
95+
" label to the PR to silence this warning.)"
96+
warn(warning)
97+
end
98+
end

ci/danger/Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# To update, change version below, run bundle install, test,
2+
# commit Gemfile and Gemfile.lock.
3+
source 'https://rubygems.org'
4+
5+
gem 'danger', '8.4.5'

ci/danger/Gemfile.lock

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
addressable (2.8.1)
5+
public_suffix (>= 2.0.2, < 6.0)
6+
claide (1.1.0)
7+
claide-plugins (0.9.2)
8+
cork
9+
nap
10+
open4 (~> 1.3)
11+
colored2 (3.1.2)
12+
cork (0.3.0)
13+
colored2 (~> 3.1)
14+
danger (8.4.5)
15+
claide (~> 1.0)
16+
claide-plugins (>= 0.9.2)
17+
colored2 (~> 3.1)
18+
cork (~> 0.1)
19+
faraday (>= 0.9.0, < 2.0)
20+
faraday-http-cache (~> 2.0)
21+
git (~> 1.7)
22+
kramdown (~> 2.3)
23+
kramdown-parser-gfm (~> 1.0)
24+
no_proxy_fix
25+
octokit (~> 4.7)
26+
terminal-table (>= 1, < 4)
27+
faraday (1.10.1)
28+
faraday-em_http (~> 1.0)
29+
faraday-em_synchrony (~> 1.0)
30+
faraday-excon (~> 1.1)
31+
faraday-httpclient (~> 1.0)
32+
faraday-multipart (~> 1.0)
33+
faraday-net_http (~> 1.0)
34+
faraday-net_http_persistent (~> 1.0)
35+
faraday-patron (~> 1.0)
36+
faraday-rack (~> 1.0)
37+
faraday-retry (~> 1.0)
38+
ruby2_keywords (>= 0.0.4)
39+
faraday-em_http (1.0.0)
40+
faraday-em_synchrony (1.0.0)
41+
faraday-excon (1.1.0)
42+
faraday-http-cache (2.4.1)
43+
faraday (>= 0.8)
44+
faraday-httpclient (1.0.1)
45+
faraday-multipart (1.0.4)
46+
multipart-post (~> 2)
47+
faraday-net_http (1.0.1)
48+
faraday-net_http_persistent (1.2.0)
49+
faraday-patron (1.0.0)
50+
faraday-rack (1.0.0)
51+
faraday-retry (1.0.3)
52+
git (1.12.0)
53+
addressable (~> 2.8)
54+
rchardet (~> 1.8)
55+
kramdown (2.4.0)
56+
rexml
57+
kramdown-parser-gfm (1.1.0)
58+
kramdown (~> 2.0)
59+
multipart-post (2.2.3)
60+
nap (1.1.0)
61+
no_proxy_fix (0.1.2)
62+
octokit (4.25.1)
63+
faraday (>= 1, < 3)
64+
sawyer (~> 0.9)
65+
open4 (1.3.4)
66+
public_suffix (5.0.0)
67+
rchardet (1.8.0)
68+
rexml (3.2.5)
69+
ruby2_keywords (0.0.5)
70+
sawyer (0.9.2)
71+
addressable (>= 2.3.5)
72+
faraday (>= 0.17.3, < 3)
73+
terminal-table (3.0.2)
74+
unicode-display_width (>= 1.1.1, < 3)
75+
unicode-display_width (2.2.0)
76+
77+
PLATFORMS
78+
ruby
79+
80+
DEPENDENCIES
81+
danger (= 8.4.5)
82+
83+
BUNDLED WITH
84+
1.17.2

ci/danger/setup_bundler.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# Copyright 2022 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
bundle install
18+
bundle update --bundler # ensure bundler version is high enough for Gemfile.lock
19+
bundle --version

0 commit comments

Comments
 (0)