├── .gitignore
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── rules
├── block-string.sh
├── has-pattern.sh
├── line-length.sh
├── mandate-conventional-commit.sh
├── no-second-line.sh
├── path-exists.sh
├── require-ci.sh
├── tests
│ ├── block-string-test.sh
│ ├── has-pattern-test.sh
│ ├── has-string-test.sh
│ ├── line-length-test.sh
│ ├── mandate-conventional-commit-test.sh
│ ├── no-second-line-test.sh
│ ├── path-exists-examples
│ │ ├── invalid-fullpath-readme.md
│ │ ├── invalid-localpath-readme.md
│ │ ├── invalid-url-readme.md
│ │ ├── valid-readme.md
│ │ ├── valid-url-readme.md
│ │ └── valid-url301-readme.md
│ ├── path-exists-test.sh
│ ├── require-ci-test.sh
│ ├── trailing-whitespace-test.sh
│ └── verb-tense-test.sh
├── trailing-whitespace.sh
└── verb-tense.sh
└── tools
├── archive.sh
├── changelog.sh
├── conventional-changelog.sh
├── filelist.sh
├── spdx-dependencies.sh
├── spdx.sh
├── spdx
└── license-ids.txt
└── tests
├── .archiveignore
├── archive-test.sh
├── conventional-changelog-test.sh
├── conventional.md
├── file1.txt
├── file2.txt
├── filelist-test.sh
├── listoffiles-fail.tar.gz
├── listoffiles-pass.tar.gz
├── listoffiles.txt
├── spdx-approved-licenses-mit-only.txt
├── spdx-approved-licenses.txt
├── spdx-dependencies-test.sh
└── spdx-test.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | archive-test.zip
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to Contribute
2 |
3 | We'd love to accept your patches and contributions to this project. There are
4 | just a few small guidelines you need to follow.
5 |
6 | ## Contributor License Agreement
7 |
8 | Contributions to this project must be accompanied by a Contributor License
9 | Agreement. You (or your employer) retain the copyright to your contribution;
10 | this simply gives us permission to use and redistribute your contributions as
11 | part of the project. Head over to to see
12 | your current agreements on file or to sign a new one.
13 |
14 | You generally only need to submit a CLA once, so if you've already submitted one
15 | (even if it was for a different project), you probably don't need to do it
16 | again.
17 |
18 | ## Code reviews
19 |
20 | All submissions, including submissions by project members, require review. We
21 | use GitHub pull requests for this purpose. Consult
22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23 | information on using pull requests.
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Git Presubmit Linter
2 | Git Presubmit Linter is a project which contains a variety of QOL tools
3 | to help developers maintain high-quality, consistent commits in
4 | their projects.
5 |
6 | The project contains a collection of shell scripts which can be
7 | configured and run during a pre-submit task. The scripts will report
8 | potential issues found in the commit.
9 |
10 | This is not an officially supported Google product.
11 |
12 | ## Get Started
13 | You can easily include this project into your CI system when
14 | it runs:
15 |
16 | ```bash
17 | git clone https://github.com/google/git-presubmit-linter
18 | set -e
19 | git log -1 --pretty=%B | ./git-presubmit-linter/rules/verb-tense.sh
20 | ```
21 |
22 | ### Complete Setup
23 | A more thorough test script may include a step to verify the directory
24 | exists before cloning, and simplify running several tests with variables:
25 |
26 | ```bash
27 | GIT_PRESUBMIT_LINTER='git-presubmit-linter'
28 | RULES="${GIT_PRESUBMIT_LINTER}/rules"
29 |
30 | if [ ! -d ${GIT_PRESUBMIT_LINTER} ]; then
31 | # Clone the git presubmit linter repository
32 | git clone https://github.com/google/git-presubmit-linter.git
33 | fi
34 | cd ${GIT_PRESUBMIT_LINTER}
35 | git pull origin master
36 | cd ../
37 |
38 | # Check git commit for style
39 | git log -1 --pretty=%B | ${RULES}/verb-tense.sh imperative
40 | git log -1 --pretty=%B | ${RULES}/no-second-line.sh
41 | git log -1 --pretty=%B | ${RULES}/line-length.sh 100
42 |
43 | # Check git diff lines that have been modified for style
44 | git diff HEAD~1 | grep '^\+' | ${RULES}/trailing-whitespace.sh
45 | ```
46 |
47 | ## Using Rules
48 | There are many rules that are available in the `rules/` directory.
49 | Each can be accessed in a shell script by piping a string into the
50 | script and providing additional parameters.
51 |
52 | Each rule will either complete without issue or return an error
53 | code. In a presubmit script, you can set errors to exit the
54 | script early.
55 |
56 | `set -e`
57 |
58 | ### Verb Tense
59 | This rule is used to verify that a commit message is written in a
60 | given verb tense, such as present tense or past tense.
61 |
62 | `git log -1 --pretty=%B | ./rules/verb-tense.sh `
63 |
64 | If the commit message starts with a `present` tense verb, like:
65 |
66 | "**Adds new field**"
67 |
68 | The script succeeds. However, if it is in a different tense like below,
69 | the script will exit early with a non-zero status.
70 |
71 | "**I have added a new field**"
72 |
73 | This supports `present`, `imperative`, and `past` tense verbs.
74 |
75 | ### No Second Line
76 | This rule verifies that the second line in a commit message is
77 | empty, a common style in git.
78 |
79 | `git log -1 --pretty=%B | ./rules/no-second-line.sh`
80 |
81 | The script succeeds if the second line of the commit message is
82 | empty, and it fails otherwise with a non-zero status.
83 |
84 | ### Line Length
85 | This rule verifies that every line in a commit message or in the
86 | code diff is under a certain line length. Style guides often
87 | want code to be a maximum length per line, and git commit
88 | messages are typically short as well.
89 |
90 | It can be used by passing a string and including the maximum
91 | length.
92 |
93 | `git log -1 --pretty=%B | ./rules/line-length.sh `
94 | `git diff HEAD~1 --pretty=%B | ./rules/line-length.sh `
95 |
96 | **Note**: Git diffs will add in additional spacing to each line.
97 | To verify the line length, you will need to add 2 to your maximum,
98 | eg. A style guide with `80` characters max per line should use `82`.
99 |
100 | #### First Line Length
101 | Sometimes you may only want to check the length of the first line of
102 | a message only, or may want a different maximum. This can be implemented
103 | by piping your commit message into the rule using `head`.
104 |
105 | `git log -1 --pretty=%B | head -n1 | ./rules/line-length.sh `
106 |
107 | ### Contains String
108 | This rule verifies that a certain string appears in a commit message.
109 | Style guides may require developers to include a description of a test,
110 | or an issue number.
111 |
112 | It can be used by including the string you want to identify. This script
113 | will pass if the string is exactly matched anywhere on any line of the
114 | string.
115 |
116 | `git log -1 --pretty=%B | ./rules/has-string.sh `
117 |
118 | To require contributors to mention tests, you can use:
119 | `git log -1 --pretty=%B | ./rules/has-string.sh "Test:"`
120 |
121 | #### Searching for edited files
122 | If you want to check whether a certain file has been modified such as a
123 | `CHANGELOG` file, you can instead run:
124 |
125 | `git diff HEAD~1 --name-only | ./rules/has-string.sh "CHANGELOG"`
126 |
127 | ### Contains Pattern
128 | Sometimes simple string matching is not enough. This rule will check
129 | every line for the instance of a regular expression.
130 |
131 | `git log -1 --pretty=%B | head -n1 | ./rules/has-pattern.sh `
132 |
133 | If a style guide requires commit messages to start with a capital
134 | letter, you can use:
135 |
136 | `git log -1 --pretty=%B | head -n1 | ./rules/has-pattern.sh "^[A-Z]"`
137 |
138 | ### Does not contain string
139 | Style guides may ban the use of certain notes that developers put into
140 | code such as "TODO", "FIXME", "NOTE", etc. This rule will check each line
141 | and exit with a non-zero status if a given string is found.
142 |
143 | `git log -1 --pretty=%B | ./rules/block-string.sh `
144 |
145 | ### Trailing Whitespace
146 | This rule verifies that no changed line has any trailing whitespace.
147 | Style guides may require this to be removed.
148 |
149 | `git diff HEAD~1 --pretty=%B | ./rules/trailing-whitespace.sh`
150 |
151 | ### Mandate Conventional Changelog format
152 | This rule verifies that the commit title fits the
153 | [conventional changelog](https://www.conventionalcommits.org/en/v1.0.0/)
154 | format.
155 |
156 | `git log -1 --pretty=%B | ./rules/mandate-conventional-changelog.sh`
157 |
158 | ### Check if CI is required
159 | This rule analyzes a commit diff and determines if any source code has changed.
160 | This is useful in knowing whether source code has changed or whether it was
161 | just documentation / code comments.
162 |
163 | For each changed file, the file extension is checked. Only a few source code
164 | languages are currently supported. Files to ignore include documentation,
165 | metadata, and images. Any file not supported will raise an error, as it may
166 | affect the build/tests.
167 |
168 | Errors are printed to the terminal.
169 |
170 | ```bash
171 | git diff HEAD~1 | ./rules/require-ci.sh
172 | if [ $? -eq 0 ]; then
173 | # No source code has changed. We can skip CI.
174 | exit 0
175 | fi
176 | # If `1` is returned, that means source code was potentially changed.
177 | # Run build and tests
178 | ```
179 |
180 | ## Tools
181 | This repo also contains tools to be run during a presubmit task. These do
182 | not verify the git metadata or other project details, but can produce
183 | useful artifacts that may be part of the presubmit process.
184 |
185 | ### Changelog
186 | This tool will generate a changelog between two points in your git history in
187 | a Markdown format, with the summary of each commit prepended by an asterisk.
188 |
189 | `./tools/changelog.sh` - Generates a changelog between HEAD and the most recent tag
190 | `./tools/changelog.sh v1.0.0` - Generates a changelog between HEAD and the provided revision
191 | `./tools/changelog.sh v1.0.0 v1.0.1` - Generates a changelog between the two revisions
192 |
193 | ### Conventional Commit Changelog
194 | The [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec
195 | aims to provide semantic definitons to version control changelists.
196 |
197 | This tool will generate a changelog for a project using this spec between two
198 | points in your git history in a Markdown format, following the guidelines
199 | defined by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
200 |
201 | `./tools/conventional-changelog.sh` - Generates a changelog between HEAD and the most recent tag
202 | `./tools/conventional-changelog.sh v1.0.0` - Generates a changelog between HEAD and the provided revision
203 | `./tools/conventional-changelog.sh v1.0.0 v1.0.1` - Generates a changelog between the two revisions
204 |
205 | ### Generate sanitized archives
206 | This tool will generate zipped archives of specific directories and the files inside.
207 | Unlike a standard `zip` command, this tool will check each file against a blocklist,
208 | denoted as the file `.archiveignore`, and prevent any unwanted files (credentials, build files, etc.)
209 | from being added to your archive.
210 |
211 | An `.archiveignore` is a simple list of files, separated by newlines. It checks against the filename, so
212 | any part that matches will block it from being included in the archive.
213 |
214 | ```
215 | file1.txt
216 | file2.txt
217 | zip
218 | ```
219 |
220 | `./tools/archive.sh myfiles.zip "*"` - Puts all non-blocked files in an archive called `myfiles.zip`
221 | `./tools/archive.sh myfiles.zip /src "*"` - Puts all non-blocked files from the `src` directory in an archive called `myfiles.zip`
222 |
223 | ### Verify package contents
224 | This tool will take in a list of files, which can come from an archive file, and check each file
225 | against a list of regular expressions. If an packaged file does not match any of the regular
226 | expressions, the tool will report the file and fail.
227 |
228 | `tar -tf myfiles.tar.gz | ./tools/filelist.sh ./listoffiles.txt`
229 |
230 | The `listoffiles.txt` can contain a series of regular expressions. Be sure to escape backslashes.
231 |
232 | ```
233 | file\\d\\.txt
234 | ```
235 |
236 | For some CI systems, you may need to set a custom IFS (Internal Field Separator). That can be
237 | a second parameter. In the example below, the IFS will be manually set to a single space. By
238 | default, this is typically a newline character (\n).
239 |
240 | `tar -tf myfiles.tar.gz | ./tools/filelist.sh ./listoffiles.txt " "`
241 |
242 | ### SPDX Licenses
243 | Code licenses can be identified using the SPDX license list in a standardized way.
244 | (https://spdx.org/licenses/)
245 |
246 | To make it easy for developers to validate individual licenses, a tool has been created that
247 | will check the input against the current list of licenses.
248 |
249 | `echo "MIT" | ./tools/spdx.sh`
250 |
251 | This will return 0 or 1 depending if the license is valid or invalid, respectively.
252 |
253 | A second tool exists which can validate a list of dependencies against an approved list of licenses.
254 | This tool pulls licensing information from https://libraries.io, and requires an API key to be obtained
255 | first.
256 |
257 | `cat requirements.txt | sed -r 's/([A-Za-z-]*).*/\1/g' | ./tools/spdx-dependencies.sh pypi approved-licenses.txt `
258 |
259 | The list of approved licenses, `approved-licenses.txt`, is a text file with each approved license on a new line in the spdx format.
260 |
261 | ### Filepath exists
262 | This rule finds all filenames in provided files, such as documentation,
263 | and verifies that the file exists either in that directory or in general.
264 |
265 | If it is a URL, this script will check that the URL returns a `200` status code. If you also
266 | want to allow redirects to pass, use the flag `--allow-redirects`.
267 |
268 | `cat *.md | ./rules/path-exists.sh`
269 |
270 | `cat *.md | ./rules/path-exists.sh --allow-redirects`
271 |
272 | ## License
273 | See `LICENSE`.
--------------------------------------------------------------------------------
/rules/block-string.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2018 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 | # https://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 | # Example usage:
18 | # git log -1 --pretty=%B | ./block-string.sh "TODO"
19 |
20 | if [ "$#" -lt 1 ]; then
21 | echo "Expected usage: 'string' | ./block-string.sh "
22 | echo "Looking for the string to block"
23 | exit 1
24 | fi
25 |
26 | ! grep -n "$1"
27 | if [ $? -ne 0 ]; then
28 | exit 1
29 | fi
30 | echo "No unwanted phrases found"
--------------------------------------------------------------------------------
/rules/has-pattern.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2018 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 | # https://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 | # Example usage:
18 | # git log -1 --pretty=%B | ./has-pattern.sh "^[A-Z]*"
19 |
20 | if [ "$#" -lt 1 ]; then
21 | echo "Expected usage: 'string' | ./has-pattern.sh "
22 | echo "Looking for the regex pattern to identify"
23 | exit 1
24 | fi
25 |
26 | grep -n "$1"
27 | if [ $? -eq 0 ]; then
28 | exit 0
29 | fi
30 |
31 | echo "No pattern matching '$1' was found"
32 | exit 1
--------------------------------------------------------------------------------
/rules/line-length.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2018 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 | # https://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 | # Example usage:
18 | # git log -1 --pretty=%B | ./line-length.sh 80
19 |
20 | if [ "$#" -lt 1 ]; then
21 | echo "Expected usage: 'string' | ./line-length.sh "
22 | echo "Looking for the maximum line length"
23 | exit 1
24 | fi
25 |
26 | while read line;
27 | do
28 | echo $line
29 | if [ ${#line} -gt $1 ]; then
30 | echo "This line is too long, >$1 characters"
31 | exit 1
32 | fi
33 | done
34 |
35 | echo "Commit message length verified"
--------------------------------------------------------------------------------
/rules/mandate-conventional-commit.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2021 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 | # https://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 | # Example usage:
18 | # git log -1 --pretty=%B | ./mandate-conventional-changelog.sh
19 | COMMIT_REGEX="^([a-z]*\!?)(\(([A-Za-z]*)\))?:\s(.*)$"
20 |
21 | read msg # Read first line
22 | echo "${msg}" | grep -Pn "${COMMIT_REGEX}" > /dev/null
23 | if [ $? -eq 0 ]; then
24 | exit 0
25 | fi
26 |
27 | echo "Commit '${msg}' does not match conventional changelog format: https://www.conventionalcommits.org/en/v1.0.0/"
28 | exit 1
29 |
--------------------------------------------------------------------------------
/rules/no-second-line.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2018 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 | # https://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 | # Example usage:
18 | # git log -1 --pretty=%B | ./no-second-line.sh
19 |
20 | line2=$(sed -ne 2p)
21 | if [ ! -z "$line2" ] ; then
22 | echo "Text detected on the second line of the commit message: $line2"
23 | exit 1
24 | fi
--------------------------------------------------------------------------------
/rules/path-exists.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2018 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 | # https://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 | # Example usage:
18 | # cat *.md | ./rules/path-exists.sh
19 | # cat *.md | ./rules/path-exists.sh --allow-redirects
20 |
21 | # grep all filenames and URLs, then remove any ` characters
22 | STDIN=`cat`
23 | FILES=$(echo $STDIN |\
24 | grep -Po '[\s\b`](:?\.?\/?\w+)*[\w_-]+\.[a-z]\w+`?' |\
25 | cut -d "\`" -f 2)
26 | URLS=$(echo $STDIN |\
27 | grep -Po 'https?:\/\/[\w./-]+' |\
28 | cut -d "\`" -f 2)
29 | ALLOW_REDIRECTS=0
30 |
31 | for var in "$@"
32 | do
33 | if [ ${var} == "--allow-redirects" ]; then
34 | ALLOW_REDIRECTS=1
35 | fi
36 | done
37 |
38 | if [ ! -z "$FILES" ]; then
39 | while read -r line;
40 | do
41 | if [ ! -f ${line} ]; then
42 | # Check that this line is not a common name
43 | if [ ${line} == "node.js" ] || [ ${line} == "Node.js" ]; then
44 | continue
45 | fi
46 | # See if the file exists elsewhere
47 | FILE_PATH=$(find . -name "${line}" -type f)
48 | if [ -z "$FILE_PATH" ]; then
49 | # The file path is empty and URL is not okay
50 | echo "× ${line} not found!"
51 | exit 1
52 | fi
53 | fi
54 | echo "✓ ${line}"
55 | if [ ! -z "${FILE_PATH}" ]; then
56 | echo " file found at ${FILE_PATH}"
57 | # Reset variable
58 | FILE_PATH=
59 | fi
60 | done <<< $FILES
61 | fi
62 |
63 | if [ ! -z "$URLS" ]; then
64 | while read -r line;
65 | do
66 | HTTP_STATUS=$(curl -s -o /dev/null -I -w "%{http_code}" ${line})
67 | if [ "${HTTP_STATUS}" == "301" ] && [ ! -z ${ALLOW_REDIRECTS} ]; then
68 | continue
69 | fi
70 | if [ "${HTTP_STATUS}" != "200" ]; then
71 | # The file path is empty and URL is not okay
72 | echo "× ${line} is invalid - returned status ${HTTP_STATUS}!"
73 | exit 1
74 | fi
75 | echo "✓ ${line}"
76 | done <<< $URLS
77 | fi
78 |
79 | echo "File references are all valid"
--------------------------------------------------------------------------------
/rules/require-ci.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2021 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 | # https://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 | # Example usage:
18 | # git diff HEAD~1 | ./mandate-conventional-changelog.sh
19 | # if [ $? -eq 0 ]; then
20 | # # No need to run CI as no change was flagged
21 | # exit 0
22 | # fi
23 | # # Run tests
24 |
25 | # Define a series of types to determine the 'state' of the parser
26 | TYPE_CODE=0
27 | TYPE_COMMENT_START=1
28 | TYPE_COMMENT_MIDDLE=2
29 | TYPE_COMMENT_END=3
30 | TYPE_COMMENT_SINGLE=4
31 | TYPE_DIFF_HEAD=5
32 | CURRENT_LINE_STATE=$TYPE_CODE
33 |
34 | CURRENT_FILEEXT=""
35 | CURRENT_RESULT=0
36 |
37 | # array_contains "string to find" "${array[@]}"
38 | array_contains () {
39 | local el match="$1"
40 | shift
41 | for e; do [[ "$e" == "$match" ]] && return 0; done
42 | return 1 # Not found
43 | }
44 |
45 | # categorize_source "$line" "$CURRENT_EXT"
46 | categorize_source () {
47 | echo $line | grep -n "^diff --git" > /dev/null
48 | if [ $? -eq 0 ]; then
49 | return $TYPE_DIFF_HEAD
50 | fi
51 | if [ $CURRENT_LINE_STATE -eq $TYPE_CODE ] ||
52 | [ $CURRENT_LINE_STATE -eq $TYPE_COMMENT_SINGLE ] ||
53 | [ $CURRENT_LINE_STATE -eq $TYPE_COMMENT_END ]; then
54 | # Identify the current line
55 | echo $line | grep -n "^[+-]\s*${MAP_SINGLE_COMMENT[$CURRENT_FILEEXT]}\s*" > /dev/null
56 | if [ $? -eq 0 ]; then
57 | return $TYPE_COMMENT_SINGLE
58 | fi
59 |
60 | echo $line | grep -n "^[+-]\s*${MAP_START_COMMENT[$CURRENT_FILEEXT]}\s*" > /dev/null
61 | if [ $? -eq 0 ]; then
62 | return $TYPE_COMMENT_START
63 | fi
64 |
65 | return $TYPE_CODE
66 | fi
67 | if [ $CURRENT_LINE_STATE -eq $TYPE_COMMENT_START ] ||
68 | [ $CURRENT_LINE_STATE -eq $TYPE_COMMENT_MIDDLE ]; then
69 | # See if we are still in multiline comment
70 | echo $line | grep -n "^[+-]\s*${MAP_END_COMMENT[$CURRENT_FILEEXT]}\s*" > /dev/null
71 | if [ $? -eq 0 ]; then
72 | return $TYPE_COMMENT_END
73 | fi
74 |
75 | return $TYPE_COMMENT_MIDDLE
76 | fi
77 | }
78 |
79 | # report_ignore_source
80 | report_ignore_source () {
81 | array_contains "$CURRENT_FILE" "${SCANNED_FILES[@]}"
82 | if [[ $? == 1 && $CURRENT_FILE != "" ]]; then
83 | array_contains "$CURRENT_FILEEXT" "${EXT_SRC[@]}"
84 | if [ $? -eq 0 ]; then
85 | # Provide a helpful note
86 | echo " Ignore $CURRENT_FILE. No source changes detected."
87 | fi
88 | fi
89 | }
90 |
91 | # Source code files
92 | EXT_SRC=(
93 | "go"
94 | "java"
95 | "js"
96 | "py"
97 | "ts"
98 | "sh"
99 | )
100 |
101 | # Regex to define a line that is a comment for a given file extension.
102 | # Each entry in EXT_SRC should be defined here.
103 | # Declare as an associate array.
104 | declare -A MAP_SINGLE_COMMENT
105 | MAP_SINGLE_COMMENT=(
106 | ["go"]="//"
107 | ["java"]="//"
108 | ["js"]="//"
109 | ["py"]="#"
110 | ["ts"]="//"
111 | ["sh"]="#"
112 | )
113 |
114 | # Define the start and end of multiline comments.
115 | # The parser reads line-by-line and so needs to identify these tokens.
116 | # If the language does not support multiline comments, use the same token as
117 | # for single lines.
118 | declare -A MAP_START_COMMENT
119 | MAP_START_COMMENT=(
120 | ["go"]="/*"
121 | ["java"]="/*"
122 | ["js"]="/*"
123 | ["py"]='"""'
124 | ["ts"]="/*"
125 | ["sh"]="#"
126 | )
127 |
128 | declare -A MAP_END_COMMENT
129 | MAP_END_COMMENT=(
130 | ["go"]="*/"
131 | ["java"]="*/"
132 | ["js"]="*/"
133 | ["py"]='"""'
134 | ["ts"]="*/"
135 | ["sh"]="#"
136 | )
137 |
138 | # Documentation or other files
139 | EXT_IGNORE=(
140 | # Documentation files
141 | "doc"
142 | "html"
143 | "html"
144 | "md"
145 | "rtf"
146 | "txt"
147 | # Image files
148 | "bmp"
149 | "gif"
150 | "jpeg"
151 | "jpg"
152 | "png"
153 | # Metadata files
154 | "gitignore"
155 | )
156 |
157 | SCANNED_FILES=()
158 |
159 | while read line;
160 | do
161 | categorize_source $line $CURRENT_FILEEXT
162 | CURRENT_LINE_STATE=$?
163 | if [ $CURRENT_LINE_STATE -eq $TYPE_DIFF_HEAD ]; then
164 | # Optional report from previous file
165 | report_ignore_source
166 | # Extract the file name from this line
167 | CURRENT_FILE=$(echo $line | sed -r "s/^diff --git a\\/([a-zA-Z0-9/.\\-]*)\s.*/\1/")
168 | CURRENT_FILEEXT=$(echo $CURRENT_FILE | sed -r "s/[a-zA-Z0-9/.\\-]*[.]([a-zA-Z])/\1/")
169 | echo "Checking $CURRENT_FILE ($CURRENT_FILEEXT)"
170 | array_contains "$CURRENT_FILEEXT" "${EXT_IGNORE[@]}"
171 | if [ $? -eq 0 ]; then
172 | # This is a doc file.
173 | # We can say with certainty that CI does not need to run
174 | # and no further processing is necessary.
175 | # So we can reset the state and quickly churn through all
176 | # lines of the diff.
177 | echo " Ignore .${CURRENT_FILEEXT} file"
178 | else
179 | array_contains "$CURRENT_FILEEXT" "${EXT_SRC[@]}"
180 | if [ $? -ne 0 ]; then
181 | # Else this is neither a source file nor doc file.
182 | # It is unclear how to process this, so we will have to assume it
183 | # has some CI implications and exit.
184 | echo "ERROR: Do not know how to handle file $CURRENT_FILE"
185 | CURRENT_RESULT=1
186 | fi
187 | fi
188 | else
189 | array_contains "$CURRENT_FILEEXT" "${EXT_SRC[@]}"
190 | if [ $? -eq 0 ]; then
191 | # This is a line from a source file.
192 | #
193 | # Match "+source code"
194 | # Match "-source code"
195 | # Do not match "--- /dev/null"
196 | # Do not match "+++ b/file"
197 | echo $line | grep -n "^[+-][^+-]" > /dev/null
198 | if [ $? -eq 0 ]; then
199 | # Check if this is a comment by use category
200 | if [ $CURRENT_LINE_STATE -eq $TYPE_CODE ]; then
201 | array_contains "$CURRENT_FILE" "${SCANNED_FILES[@]}"
202 | if [ $? -eq 1 ]; then
203 | # Report error for this file once
204 | echo "ERROR: Source code changed in $CURRENT_FILE: \`$line\`"
205 | CURRENT_RESULT=1
206 | # Add to list of scanned files to prevent duplicate error messages
207 | SCANNED_FILES+=($CURRENT_FILE)
208 | fi
209 | fi
210 | fi
211 | fi
212 | fi
213 | done
214 |
215 | report_ignore_source
216 |
217 | exit $CURRENT_RESULT
218 |
--------------------------------------------------------------------------------
/rules/tests/block-string-test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2018 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 | # https://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 |
18 | gitmessage1="diff --git a/README.md b/README.md
19 | index 304484b..0401187 100644
20 | --- a/README.md
21 | +++ b/README.md
22 | @@ -33,4 +33,9 @@ is no more than 80 characters. This command will pass.
23 | `./commit_message.sh "Adds new field to protobuf and sample" false 80`
24 |
25 | This will verify that the commit message above should be in past-tense and each
26 | -line is no more than 80 characters. This command will fail.
27 | \ No newline at end of file
28 | +line is no more than 80 characters. This command will fail.
29 | +
30 | +## Git Diffs
31 | +There are variety of changes that a contributor may make to a repo. To ensure
32 | +that changes are consistent, this script can be used to verify a variety of
33 | +potential changes.
34 | \ No newline at end of file
35 | "
36 |
37 | gitmessage1_todo="diff --git a/README.md b/README.md
38 | index 304484b..0401187 100644
39 | --- a/README.md
40 | +++ b/README.md
41 | @@ -33,4 +33,9 @@ is no more than 80 characters. This command will pass.
42 | # (TODO @ Nick) Fix this typo
43 | `./commit_message.sh "Adds new field to protobuf and sample" false 80`
44 |
45 | This will verify that the commit message above should be in past-tense and each
46 | -line is no more than 80 characters. This command will fail.
47 | \ No newline at end of file
48 | +line is no more than 80 characters. This command will fail.
49 | +
50 | +## Git Diffs
51 | +todo remove this line later
52 | +There are variety of changes that a contributor may make to a repo. To ensure
53 | +that changes are consistent, this script can be used to verify a variety of
54 | +potential changes.
55 | \ No newline at end of file
56 | "
57 |
58 | # Verifies that the code does not have a TODO
59 | echo "$gitmessage1" | ./rules/block-string.sh "TODO"
60 | if [ $? -ne 0 ]; then
61 | echo "Test failed"
62 | exit 1
63 | fi
64 |
65 | # Verify that the commit has TODOs
66 | echo "$gitmessage1_todo" | ./rules/block-string.sh "TODO"
67 | if [ $? -eq 0 ]; then
68 | echo "Test failed"
69 | exit 1
70 | fi
71 |
72 | echo "All tests pass"
--------------------------------------------------------------------------------
/rules/tests/has-pattern-test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2018 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 | # https://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 | commit_msg_present="Adds new field to protobuf and sample"
18 | commit_msg_bug="Adds new field
19 |
20 | Bug: #123"
21 | gitdiff_names="README.md
22 | git_diff.sh
23 | tests/test_git_diff.sh"
24 |
25 | gitdiff_names_noreadme="CHANGELOG.md
26 | git_diff.sh
27 | tests/test_git_diff.sh"
28 |
29 | # Verify that the commit message has an included detail of interest
30 | echo "$commit_msg_bug" | ./rules/has-pattern.sh "^[A-Z][a-z]*:"
31 | if [ $? -ne 0 ]; then
32 | echo "Test failed"
33 | exit 1
34 | fi
35 |
36 | # Verify that the commit message does not have an included detail of interest
37 | echo "$commit_msg_present" | ./rules/has-pattern.sh "^[A-Z][a-z]*:"
38 | if [ $? -eq 0 ]; then
39 | echo "Test failed"
40 | exit 1
41 | fi
42 |
43 | # Verifies that the commit changed any markdown file
44 | echo "$gitdiff_names" | ./rules/has-pattern.sh "[A-Z]*[.]md"
45 | if [ $? -ne 0 ]; then
46 | echo "Test failed"
47 | exit 1
48 | fi
49 |
50 | # Verify that the commit has not changed any file starting with R
51 | echo "$gitdiff_names_noreadme" | ./rules/has-pattern.sh "^R[A-Z]*"
52 | if [ $? -eq 0 ]; then
53 | echo "Test failed"
54 | exit 1
55 | fi
56 |
57 | echo "All tests pass"
--------------------------------------------------------------------------------
/rules/tests/has-string-test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2018 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 | # https://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 | commit_msg_present="Adds new field to protobuf and sample"
18 | commit_msg_bug="Adds new field
19 |
20 | Bug: #123"
21 | gitdiff_names="README.md
22 | git_diff.sh
23 | tests/test_git_diff.sh"
24 |
25 | gitdiff_names_noreadme="git_diff.sh
26 | tests/test_git_diff.sh"
27 |
28 | # Verify that the commit message has an inclucing bug
29 | echo "$commit_msg_bug" | ./rules/has-pattern.sh "Bug:"
30 | if [ $? -ne 0 ]; then
31 | echo "Test failed"
32 | exit 1
33 | fi
34 |
35 | # Verify that the commit message does not have an included bug
36 | echo "$commit_msg_present" | ./rules/has-pattern.sh "Bug:"
37 | if [ $? -eq 0 ]; then
38 | echo "Test failed"
39 | exit 1
40 | fi
41 |
42 | # Verifies that the commit changed any README file
43 | echo "$gitdiff_names" | ./rules/has-pattern.sh "README"
44 | if [ $? -ne 0 ]; then
45 | echo "Test failed"
46 | exit 1
47 | fi
48 |
49 | # Verify that the commit has not changed any README file
50 | echo "$gitdiff_names_noreadme" | ./rules/has-pattern.sh "README"
51 | if [ $? -eq 0 ]; then
52 | echo "Test failed"
53 | exit 1
54 | fi
55 |
56 | echo "All tests pass"
--------------------------------------------------------------------------------
/rules/tests/line-length-test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2018 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 | # https://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 | # Tests the variety of potential commit_messages
18 |
19 | commit_msg_multiline="Adds new field
20 | to protobuf and sample"
21 | commit_msg_multiline_nosecondline="Adds new field
22 |
23 | to both the protobuf and sample"
24 | gitmessage1="diff --git a/README.md b/README.md
25 | index 304484b..0401187 100644
26 | --- a/README.md
27 | +++ b/README.md
28 | @@ -33,4 +33,9 @@ is no more than 80 characters. This command will pass.
29 | `./commit_message.sh "Adds new field to protobuf and sample" false 80`
30 |
31 | This will verify that the commit message above should be in past-tense and each
32 | -line is no more than 80 characters. This command will fail.
33 | \ No newline at end of file
34 | +line is no more than 80 characters. This command will fail.
35 | +
36 | +## Git Diffs
37 | +There are variety of changes that a contributor may make to a repo. To ensure
38 | +that changes are consistent, this script can be used to verify a variety of
39 | +potential changes.
40 | \ No newline at end of file
41 | "
42 |
43 | # Verify that the message is under the maximum length
44 | echo "$commit_msg_multiline" | ./rules/line-length.sh 80
45 | if [ $? -ne 0 ]; then
46 | echo "Test failed"
47 | exit 1
48 | fi
49 |
50 | # Verify that the message is over the maximum length
51 | echo "$commit_msg_multiline" | ./rules/line-length.sh 8
52 | if [ $? -eq 0 ]; then
53 | echo "Test failed"
54 | exit 1
55 | fi
56 |
57 | # Verify that the first line of the message is under the maximum length
58 | echo "$commit_msg_multiline" | head -n1 | ./rules/line-length.sh 80
59 | if [ $? -ne 0 ]; then
60 | echo "Test failed"
61 | exit 1
62 | fi
63 |
64 | # Verify that the first line of the message is over the maximum length
65 | echo "$commit_msg_multiline" | head -n1 | ./rules/line-length.sh 8
66 | if [ $? -eq 0 ]; then
67 | echo "Test failed"
68 | exit 1
69 | fi
70 |
71 | # Verify that the changed code is under the maximum length
72 | echo "$gitmessage1" | ./rules/line-length.sh 82
73 | if [ $? -ne 0 ]; then
74 | echo "Test failed"
75 | exit 1
76 | fi
77 |
78 | # Verify that the changed code is over the maximum length
79 | echo "$gitmessage1" | ./rules/line-length.sh 10
80 | if [ $? -eq 0 ]; then
81 | echo "Test failed"
82 | exit 1
83 | fi
84 |
85 | echo "All tests pass"
--------------------------------------------------------------------------------
/rules/tests/mandate-conventional-commit-test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2021 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 | # https://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 | commit_msg_fix="fix: lowercase works for non-Latin characters"
18 | commit_msg_scope="fix(text): lowercase works for non-Latin characters"
19 | commit_msg_breaking="fix!: removed lowercase"
20 | commit_msg_fail="Fix lowercase for non-Latin characters"
21 |
22 | # Verify a simple commit message passes
23 | echo "$commit_msg_fix" | ./rules/mandate-conventional-commit.sh
24 | if [ $? -ne 0 ]; then
25 | echo "Test failed"
26 | exit 1
27 | fi
28 |
29 | # Verify that a scoped commit message passes
30 | echo "$commit_msg_fix" | ./rules/mandate-conventional-commit.sh
31 | if [ $? -ne 0 ]; then
32 | echo "Test failed"
33 | exit 1
34 | fi
35 |
36 | # Verify a breaking commit passes
37 | echo "$commit_msg_breaking" | ./rules/mandate-conventional-commit.sh
38 | if [ $? -ne 0 ]; then
39 | echo "Test failed"
40 | exit 1
41 | fi
42 |
43 | # Verify that the commit not matching the format fails
44 | echo "$commit_msg_fail" | ./rules/mandate-conventional-commit.sh
45 | if [ $? -eq 0 ]; then
46 | echo "Test failed"
47 | exit 1
48 | fi
49 |
50 | echo "All tests pass"
51 |
--------------------------------------------------------------------------------
/rules/tests/no-second-line-test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2018 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 | # https://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 | # Tests the variety of potential commit_messages
18 |
19 | commit_msg_multiline="Adds new field
20 | to protobuf and sample"
21 | commit_msg_multiline_nosecondline="Adds new field
22 |
23 | to both the protobuf and sample"
24 |
25 | # Verify that there is no text on the second line
26 | echo "$commit_msg_multiline_nosecondline" | ./rules/no-second-line.sh
27 | if [ $? -ne 0 ]; then
28 | echo "Test failed"
29 | exit 1
30 | fi
31 |
32 | # Verify that there is text on the second line
33 | echo "$commit_msg_multiline" | ./rules/no-second-line.sh
34 | if [ $? -eq 0 ]; then
35 | echo "Test failed"
36 | exit 1
37 | fi
38 |
39 | echo "All tests pass"
--------------------------------------------------------------------------------
/rules/tests/path-exists-examples/invalid-fullpath-readme.md:
--------------------------------------------------------------------------------
1 | # Hello World
2 |
3 | To get started, just run `/bin/path-exists.sh`
4 |
5 | Learn more in our `functions` directory
6 |
7 | foo.bar
--------------------------------------------------------------------------------
/rules/tests/path-exists-examples/invalid-localpath-readme.md:
--------------------------------------------------------------------------------
1 | # Hello World
2 |
3 | To get started, just run `./ruleZ/path-exists.sh`
4 |
5 | Learn more in our `functions` directory
--------------------------------------------------------------------------------
/rules/tests/path-exists-examples/invalid-url-readme.md:
--------------------------------------------------------------------------------
1 | # Hello World
2 |
3 | To get started, just visit https://github.com/google/git-presubmit-linter/invalid-url
--------------------------------------------------------------------------------
/rules/tests/path-exists-examples/valid-readme.md:
--------------------------------------------------------------------------------
1 | # Hello World
2 |
3 | To get started, just run `path-exists.sh`.
4 |
5 | Alternatively, you can access `./rules/path-exists.sh`
6 |
7 | Neither file is written using Node.js.
8 |
9 | This is version 1.0 or higher
--------------------------------------------------------------------------------
/rules/tests/path-exists-examples/valid-url-readme.md:
--------------------------------------------------------------------------------
1 | # Hello World
2 |
3 | To get started, just visit https://github.com/google/git-presubmit-linter
--------------------------------------------------------------------------------
/rules/tests/path-exists-examples/valid-url301-readme.md:
--------------------------------------------------------------------------------
1 | # Hello World
2 |
3 | To get started, just visit https://developers.google.com/actions
--------------------------------------------------------------------------------
/rules/tests/path-exists-test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2018 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 | # https://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 | # Verifies that the file has all valid filepaths
18 |
19 | cat ./rules/tests/path-exists-examples/valid-readme.md | ./rules/path-exists.sh
20 | if [ $? -ne 0 ]; then
21 | echo "Test failed"
22 | exit 1
23 | fi
24 |
25 | # Verifies that the file does not have valid filepaths
26 | cat ./rules/tests/path-exists-examples/invalid-fullpath-readme.md | ./rules/path-exists.sh
27 | if [ $? -eq 0 ]; then
28 | echo "Test failed"
29 | exit 1
30 | fi
31 |
32 | # Verifies that the file does not have valid filepaths
33 | cat ./rules/tests/path-exists-examples/invalid-localpath-readme.md | ./rules/path-exists.sh
34 | if [ $? -eq 0 ]; then
35 | echo "Test failed"
36 | exit 1
37 | fi
38 |
39 | # Verifies that the file has valid urls
40 | cat ./rules/tests/path-exists-examples/valid-url-readme.md | ./rules/path-exists.sh
41 | if [ $? -ne 0 ]; then
42 | echo "Test failed"
43 | exit 1
44 | fi
45 |
46 | # Verifies that the file has valid urls
47 | cat ./rules/tests/path-exists-examples/valid-url301-readme.md | ./rules/path-exists.sh --allow-redirects
48 | if [ $? -ne 0 ]; then
49 | echo "Test failed"
50 | exit 1
51 | fi
52 |
53 | # Verifies that the file has invalid urls
54 | cat ./rules/tests/path-exists-examples/invalid-url-readme.md | ./rules/path-exists.sh
55 | if [ $? -eq 0 ]; then
56 | echo "Test failed"
57 | exit 1
58 | fi
59 | echo "All tests passed"
--------------------------------------------------------------------------------
/rules/tests/require-ci-test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2021 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 | # https://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 |
18 | # Define test cases that can be skipped
19 | DIFF_README_ONLY="diff --git a/README.md b/README.md
20 | index 12e5fb6..413900b 100644
21 | --- a/README.md
22 | +++ b/README.md
23 | @@ -19,6 +19,31 @@ set -e
24 | -Hello earth
25 | +Hello world
26 | "
27 |
28 | DIFF_README_COMMENT="diff --git a/README.md b/README.md
29 | index 12e5fb6..413900b 100644
30 | --- a/README.md
31 | +++ b/README.md
32 | @@ -19,6 +19,31 @@ set -e
33 | -Hello earth
34 | +Hello world
35 | diff --git a/example.sh b/example.sh
36 | index 12e5fb6..413900b 100644
37 | --- a/example.sh
38 | +++ b/example.sh
39 | @@ -19,6 +19,31 @@ set -e
40 | -# exit 1
41 | +# exit 0
42 | "
43 |
44 | DIFF_README_MULTICOMMENT="diff --git a/README.md b/README.md
45 | index 12e5fb6..413900b 100644
46 | --- a/README.md
47 | +++ b/README.md
48 | @@ -19,6 +19,31 @@ set -e
49 | -Hello earth
50 | +Hello world
51 | diff --git a/example.js b/example.js
52 | index 12e5fb6..413900b 100644
53 | --- a/example.js
54 | +++ b/example.js
55 | @@ -19,6 +19,31 @@ set -e
56 | + /*
57 | + * Multiline comment
58 | + */
59 | "
60 |
61 | # Define test cases that cannot be skipped
62 | DIFF_README_CODE="diff --git a/README.md b/README.md
63 | index 12e5fb6..413900b 100644
64 | --- a/README.md
65 | +++ b/README.md
66 | @@ -19,6 +19,31 @@ set -e
67 | -Hello earth
68 | +Hello world
69 | diff --git a/example.sh b/example.sh
70 | index 12e5fb6..413900b 100644
71 | --- a/example.sh
72 | +++ b/example.sh
73 | @@ -19,6 +19,31 @@ set -e
74 | -exit 1
75 | +exit 0
76 | "
77 |
78 | DIFF_UNKNOWNFILE="diff --git a/file.mystery b/file.mystery
79 | index 12e5fb6..413900b 100644
80 | --- a/file.mystery
81 | +++ b/file.mystery
82 | @@ -19,6 +19,31 @@ set -e
83 | -Hello earth
84 | +Hello world
85 | "
86 |
87 | # Split string by newline character
88 | IFS='\n'
89 |
90 | echo $DIFF_README_ONLY | ./rules/require-ci.sh
91 | if [ $? -ne 0 ]; then
92 | echo "Test failed"
93 | exit 1
94 | fi
95 |
96 | echo $DIFF_README_COMMENT | ./rules/require-ci.sh
97 | if [ $? -ne 0 ]; then
98 | echo "Test failed"
99 | exit 1
100 | fi
101 |
102 | echo $DIFF_README_MULTICOMMENT | ./rules/require-ci.sh
103 | if [ $? -ne 0 ]; then
104 | echo "Test failed"
105 | exit 1
106 | fi
107 |
108 | echo $DIFF_README_CODE | ./rules/require-ci.sh
109 | if [ $? -eq 0 ]; then
110 | echo "Test failed"
111 | exit 1
112 | fi
113 |
114 | echo $DIFF_UNKNOWNFILE | ./rules/require-ci.sh
115 | if [ $? -eq 0 ]; then
116 | echo "Test failed"
117 | exit 1
118 | fi
119 |
120 | echo "All tests pass"
121 |
--------------------------------------------------------------------------------
/rules/tests/trailing-whitespace-test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2018 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 | # https://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 | # Tests the variety of potential commit_messages
18 |
19 | gitmessage1="diff --git a/README.md b/README.md
20 | index 304484b..0401187 100644
21 | --- a/README.md
22 | +++ b/README.md
23 | @@ -33,4 +33,9 @@ is no more than 80 characters. This command will pass.
24 | `./commit_message.sh "Adds new field to protobuf and sample" false 80`
25 |
26 | This will verify that the commit message above should be in past-tense and each
27 | -line is no more than 80 characters. This command will fail.
28 | \ No newline at end of file
29 | +line is no more than 80 characters. This command will fail.
30 | +
31 | +## Git Diffs
32 | +There are variety of changes that a contributor may make to a repo. To ensure
33 | +that changes are consistent, this script can be used to verify a variety of
34 | +potential changes.
35 | \ No newline at end of file
36 | "
37 |
38 | gitmessage1_whitespace="diff --git a/README.md b/README.md
39 | index 304484b..0401187 100644
40 | --- a/README.md
41 | +++ b/README.md
42 | @@ -33,4 +33,9 @@ is no more than 80 characters. This command will pass.
43 | `./commit_message.sh "Adds new field to protobuf and sample" false 80`
44 |
45 | This will verify that the commit message above should be in past-tense and each
46 | -line is no more than 80 characters. This command will fail.
47 | \ No newline at end of file
48 | +line is no more than 80 characters. This command will fail.
49 | +
50 | +## Git Diffs
51 | +There are variety of changes that a contributor may make to a repo. To ensure
52 | +that changes are consistent, this script can be used to verify a variety of
53 | +potential changes.
54 | \ No newline at end of file
55 | "
56 |
57 | # Verify that there is no text on the second line
58 | echo "$gitmessage1" | ./rules/trailing-whitespace.sh
59 | if [ $? -ne 0 ]; then
60 | echo "Test failed"
61 | exit 1
62 | fi
63 |
64 | # Verify that there is text on the second line
65 | echo "$gitmessage1_whitespace" | ./rules/trailing-whitespace.sh
66 | if [ $? -eq 0 ]; then
67 | echo "Test failed"
68 | exit 1
69 | fi
70 |
71 | echo "All tests pass"
--------------------------------------------------------------------------------
/rules/tests/verb-tense-test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2018 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 | # https://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 | # Tests the variety of potential commit_messages
18 |
19 | commit_msg_present="Adds new field to protobuf and sample"
20 | commit_msg_present_2="He adds new field to protobuf and sample"
21 | commit_msg_present_3="Triple-checks exception"
22 | commit_msg_past="Added new field to protobuf and sample"
23 | commit_msg_past_2="She Added new field to protobuf and sample"
24 | commit_msg_imperative="Add new field to protobuf and sample"
25 | commit_msg_imperative_2="Update dependencies"
26 | commit_msg_na="I have made some changes"
27 |
28 | # Verify that present-tense checking passes with present-tense verb
29 | echo "$commit_msg_present" | ./rules/verb-tense.sh present
30 | if [ $? -ne 0 ]; then
31 | echo "Test failed"
32 | exit 1
33 | fi
34 |
35 | # Verify that present-tense checking passes with hyphenated word
36 | echo "$commit_msg_present_3" | ./rules/verb-tense.sh present
37 | if [ $? -ne 0 ]; then
38 | echo "Test failed"
39 | exit 1
40 | fi
41 |
42 | # Verify that present-tense checking fails with past-tense verb
43 | echo "$commit_msg_past" | ./rules/verb-tense.sh present
44 | if [ $? -eq 0 ]; then
45 | echo "Test failed"
46 | exit 1
47 | fi
48 |
49 | # Verify that present-tense checking fails if it doesn't start with verb
50 | echo "$commit_msg_present_2" | ./rules/verb-tense.sh present
51 | if [ $? -eq 0 ]; then
52 | echo "Test failed"
53 | exit 1
54 | fi
55 |
56 | # Verify that past-tense checking succeeds with past-tense verb
57 | echo "$commit_msg_past" | ./rules/verb-tense.sh past
58 | if [ $? -ne 0 ]; then
59 | echo "Test failed"
60 | exit 1
61 | fi
62 |
63 | # Verify that past-tense checking fails with present-tense verb
64 | echo "$commit_msg_present" | ./rules/verb-tense.sh past
65 | if [ $? -eq 0 ]; then
66 | echo "Test failed"
67 | exit 1
68 | fi
69 |
70 | # Verify that past-tense checking fails if it doesn't start with verb
71 | echo "$commit_msg_past_2" | ./rules/verb-tense.sh past
72 | if [ $? -eq 0 ]; then
73 | echo "Test failed"
74 | exit 1
75 | fi
76 |
77 | # Verify that imperative-tense checking succeeds with imperative-tense verb
78 | echo "$commit_msg_imperative" | ./rules/verb-tense.sh imperative
79 | if [ $? -ne 0 ]; then
80 | echo "Test failed"
81 | exit 1
82 | fi
83 |
84 | # Verify that imperative-tense checking succeeds with imperative-tense verb
85 | echo "$commit_msg_imperative_2" | ./rules/verb-tense.sh imperative
86 | if [ $? -ne 0 ]; then
87 | echo "Test failed"
88 | exit 1
89 | fi
90 |
91 | # Verify that imperative-tense checking fails with present-tense verb
92 | echo "$commit_msg_present" | ./rules/verb-tense.sh imperative
93 | if [ $? -eq 0 ]; then
94 | echo "Test failed"
95 | exit 1
96 | fi
97 |
98 | # Verify that imperative-tense checking fails with past-tense verb
99 | echo "$commit_msg_past" | ./rules/verb-tense.sh imperative
100 | if [ $? -eq 0 ]; then
101 | echo "Test failed"
102 | exit 1
103 | fi
104 |
105 | # Verify that imperative-tense checking fails with invalid phrase
106 | echo "$commit_msg_na" | ./rules/verb-tense.sh imperative
107 | if [ $? -eq 0 ]; then
108 | echo "Test failed"
109 | exit 1
110 | fi
111 |
112 | echo "All tests passed"
--------------------------------------------------------------------------------
/rules/trailing-whitespace.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2018 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 | # https://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 | # Example usage:
18 | # git diff HEAD~1 --pretty=%B | ./trailing-whitespace.sh
19 |
20 | grep -Ene "^\S+.*\s+$"
21 | if [ $? -eq 0 ]; then
22 | echo "A line with trailing whitespace found"
23 | exit 1
24 | fi
25 | echo "No trailing whitespace found"
--------------------------------------------------------------------------------
/rules/verb-tense.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2018 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 | # https://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 | # Example usage:
18 | # git log -1 --pretty=%B | ./verb-tense.sh present
19 |
20 | if [ "$#" -lt 1 ]; then
21 | echo "Expected usage: 'string' | ./verb-tense.sh "
22 | echo "Values: "
23 | echo " present - Add*s*"
24 | echo " past - Add*ed*"
25 | echo " imperative - Add"
26 | exit 1
27 | fi
28 |
29 | read msg # Read the first line of the message
30 |
31 | if [ "$1" == "present" ]; then
32 | # Use present-tense only
33 | # "Adds"
34 | # "Removes"
35 | # "Checks"
36 | echo "Checking for present-tense in commit messages"
37 | echo $msg | grep '^[A-Z][a-z-]*s\s'
38 | if [ $? -ne 0 ]; then
39 | echo $msg
40 | echo "The first line of the commit message is not in the present tense"
41 | exit 1
42 | fi
43 | elif [ "$1" == "past" ]; then
44 | # Use past-tense only
45 | # "Added"
46 | # "Removed"
47 | # "Checked"
48 | echo "Checking for past-tense in commit messages"
49 | echo $msg | grep '^[A-Z][a-z-]*ed\s'
50 | if [ $? -ne 0 ]; then
51 | echo $msg
52 | echo "The first line of the commit message is not in the past tense"
53 | exit 1
54 | fi
55 | elif [ "$1" == "imperative" ]; then
56 | # Use the imperative form only
57 | # "Add"
58 | # "Remove"
59 | # "Check"
60 | echo "Checking for imperative-tense in commit messages"
61 | # This regular expression matches past or present. Check that grep does not match.
62 | echo $msg | grep -P '(?:(?:^[A-Z][a-z]*(?:ed|s)\s)|(?:^[A-Z]\s))'
63 | if [ $? -eq 0 ]; then
64 | echo $msg
65 | echo "The first line of the commit message is not in the imperative tense"
66 | exit 1
67 | fi
68 | fi
69 | echo "Commit message tense verified"
--------------------------------------------------------------------------------
/tools/archive.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # A zip script that uses an .archiveignore file to not process
3 | # certain files
4 | #
5 | # Example usage:
6 | # ./tools/archive.sh archive.zip *
7 |
8 | if [ "$#" -lt 2 ]; then
9 | echo "Expected usage: ./tools/archive.sh "
10 | echo " or"
11 | echo "Expected usage: ./tools/archive.sh "
12 | exit 1
13 | fi
14 |
15 | if [ "$#" -eq 2 ]; then
16 | directory="."
17 | filter="$2"
18 | archiveignore="./.archiveignore"
19 | elif [ "$#" -eq 3 ]; then
20 | directory="$2"
21 | filter="$3"
22 | archiveignore="$directory/.archiveignore"
23 | fi
24 |
25 |
26 | find $directory -type f -iname "$filter" -print0 | while IFS= read -r -d $'\0' line; do
27 | echo "$line" | grep -f $archiveignore
28 | if [ $? -ne 0 ]; then
29 | echo "✓ $line"
30 | zip $1 "$line"
31 | else
32 | echo "× $line is blocked"
33 | fi
34 | done
--------------------------------------------------------------------------------
/tools/changelog.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Example usage:
3 | # ./tools/changelog.sh
4 | # ./tools/changelog.sh github/v2.1.0
5 | # ./tools/changelog.sh github/v2.1.0 github/v2.1.3
6 | if [ "$#" -eq 0 ]; then
7 | # Use last tag and HEAD
8 | tag=$(git tag --sort=-creatordate | sed -ne 1p)
9 | git log --pretty=%s $tag..HEAD | sed 's/^/* /'
10 | elif [ "$#" -eq 1 ]; then
11 | # Use included tag and HEAD
12 | git log --pretty=%s $1..HEAD | sed 's/^/* /'
13 | elif [ "$#" -eq 2 ]; then
14 | # Use two parameterized tags
15 | git log --pretty=%s $1..$2 | sed 's/^/* /'
16 | fi
--------------------------------------------------------------------------------
/tools/conventional-changelog.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Copyright 2020 Google LLC
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # https://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 | # Generates changelogs using Conventional Commits
17 | # and follows guidelines from Keep a Changelog
18 | # See https://www.conventionalcommits.org/en/v1.0.0/
19 | # See https://keepachangelog.com/en/1.0.0/
20 | #
21 | # Example usage:
22 | # ./tools/conventional-changelog.sh
23 | # ./tools/conventional-changelog.sh test
24 | # ./tools/conventional-changelog.sh github/v2.1.0
25 | # ./tools/conventional-changelog.sh github/v2.1.0 github/v2.1.3
26 |
27 | PLACEHOLDER="2020-03-30|feat: Added something
28 | 2020-03-25|fix: Fix bugs
29 | 2020-03-25|fix(processor): Fix processing hangup
30 | 2020-03-20|build: Update dependencies
31 | 2020-03-15|chore: Convert array to object
32 | 2020-03-10|ci: Add lint test
33 | 2020-03-05|docs: Fix typo
34 | 2020-02-29|style: Switch from tabs to spaces
35 | 2020-02-24|refactor: Rename Adapter to Interface
36 | 2020-02-19|perf: Improve load times by 50%
37 | 2020-02-14|test: Add test for timeout
38 | 2020-02-09|vuln: Sanitize SQL entries
39 | 2020-01-31|fix!: The CPU no longer overheats when you hold down spacebar"
40 |
41 | # Grab git logs in the format `|`
42 | if [ "$#" -eq 0 ]; then
43 | # Use last tag and HEAD
44 | TAG=$(git tag --sort=-creatordate | sed -ne 1p)
45 | COMMITS=$(git log --pretty="%ad|%s" --date=short $TAG..HEAD)
46 | elif [ "$#" -eq 1 ]; then
47 | if [ "$1" == "test" ]; then
48 | # This is a test, use placeholder values
49 | TAG="github/v1.0.0"
50 | COMMITS=$PLACEHOLDER
51 | else
52 | # Use included tag and HEAD
53 | TAG=$1
54 | COMMITS=$(git log --pretty="%ad|%s" --date=short $1..HEAD)
55 | fi
56 | elif [ "$#" -eq 2 ]; then
57 | # Use two parameterized tags
58 | TAG=$2
59 | COMMITS=$(git log --pretty="%ad|%s" --date=short $1..$2)
60 | fi
61 |
62 | IFS=$'\n'
63 |
64 | # Create version subsections with scopes
65 | declare -A added=()
66 | declare -A changed=()
67 | declare -A deprecated=()
68 | declare -A fixed=()
69 | declare -A security=()
70 |
71 | # Parse each commit using Conventional Commit format
72 | # Place it in a Keep A Changelog category
73 | COMMIT_REGEX="^([[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2})\|([a-z]*\!?)(\(([A-Za-z]*)\))?:\s(.*)$"
74 |
75 | for commit in $COMMITS
76 | do
77 | CATEGORY=$(echo $commit | sed -r "s/${COMMIT_REGEX}/\2/")
78 | SCOPE=$(echo $commit | sed -r "s/${COMMIT_REGEX}/\4/")
79 | COMMIT=$(echo $commit | sed -r "s/${COMMIT_REGEX}/\5/")
80 |
81 | if [ -z $SCOPE ]; then
82 | SCOPE="other" # Default
83 | fi
84 |
85 | echo $CATEGORY | grep '!' > /dev/null
86 | if [ $? -eq 0 ]; then
87 | deprecated[$SCOPE]+="* $COMMIT$IFS"
88 | break
89 | fi
90 |
91 | if [ $CATEGORY == 'feat' ]; then
92 | added["$SCOPE"]+="* $COMMIT$IFS"
93 | fi
94 | if [ $CATEGORY == 'fix' ]; then
95 | fixed["$SCOPE"]+="* $COMMIT$IFS"
96 | fi
97 | if [ $CATEGORY == 'vuln' ]; then
98 | security["$SCOPE"]+="* $COMMIT$IFS"
99 | fi
100 | if [ $CATEGORY == 'build' ] ||
101 | [ $CATEGORY == 'chore' ] ||
102 | [ $CATEGORY == 'ci' ] ||
103 | [ $CATEGORY == 'docs' ] ||
104 | [ $CATEGORY == 'style' ] ||
105 | [ $CATEGORY == 'refactor' ] ||
106 | [ $CATEGORY == 'perf' ] ||
107 | [ $CATEGORY == 'test' ]; then
108 | changed["$SCOPE"]+="* $COMMIT$IFS"
109 | fi
110 | done
111 |
112 | # Create changelog output
113 | DATE=$(echo ${COMMITS[0]} | sed -r "s/${COMMIT_REGEX}/\1/")
114 | # github/v2.12.0 -> v2.12.0
115 | echo "# $(echo $TAG | sed 's/github\///') - $DATE"
116 | # Create subsections for each category of commit
117 | # Create optional subsubsections for each scoped change
118 |
119 | # Deprecated
120 | if [ ${#deprecated[@]} -ne 0 ]; then
121 | echo "## Deprecated"
122 | for scope in ${!deprecated[@]}
123 | do
124 | if [ ${#deprecated[@]} -gt 1 ]; then
125 | echo "### $scope"
126 | fi
127 | echo "${deprecated[$scope]}"
128 | done
129 | fi
130 |
131 | # Added
132 | if [ ${#added[@]} -ne 0 ]; then
133 | echo "## Added"
134 | for scope in ${!added[@]}
135 | do
136 | if [ ${#added[@]} -gt 1 ]; then
137 | echo "### $scope"
138 | fi
139 | echo "${added[$scope]}"
140 | done
141 | fi
142 |
143 | # Changed
144 | if [ ${#changed[@]} -ne 0 ]; then
145 | echo "## Changed"
146 | for scope in ${!changed[@]}
147 | do
148 | if [ ${#changed[@]} -gt 1 ]; then
149 | echo "### $scope"
150 | fi
151 | echo "${changed[$scope]}"
152 | done
153 | fi
154 |
155 | # Fixed
156 | if [ ${#fixed[@]} -ne 0 ]; then
157 | echo "## Fixed"
158 | for scope in ${!fixed[@]}
159 | do
160 | if [ ${#fixed[@]} -gt 1 ]; then
161 | echo "### $scope"
162 | fi
163 | echo "${fixed[$scope]}"
164 | done
165 | fi
166 |
167 | # Security
168 | if [ ${#security[@]} -ne 0 ]; then
169 | echo "## Security"
170 | for scope in ${!security[@]}
171 | do
172 | if [ ${#security[@]} -gt 1 ]; then
173 | echo "### $scope"
174 | fi
175 | echo "${security[$scope]}"
176 | done
177 | fi
178 |
--------------------------------------------------------------------------------
/tools/filelist.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2019 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 | # https://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 | # This script checks file contents against a list of regular expressions
18 | # In a CI system, you may pass in a list of files from a tar archive.
19 | #
20 | # For some CI systems, you may need to specify a custom IFS
21 | # (Internal Field Separator)
22 | #
23 | # Example usage:
24 | # tar -tf archive.tar.gz | ./tools/filelist.sh listoffiles.txt
25 | # tar -tf archive.tar.gz | ./tools/filelist.sh listoftiles.txt ' '
26 |
27 | if [ "$#" -lt 1 ]; then
28 | echo "Expected usage: '' | ./tools/filelist.sh listoffiles.txt"
29 | exit 1
30 | fi
31 | if [ "$#" -gt 1 ]; then
32 | # Set the IFS (Internal Field Separator)
33 | IFS=$2
34 | fi
35 |
36 | REJECTED_FILES=0
37 | while read tarFile
38 | do
39 | VALID=0
40 | while read pattern
41 | do
42 | echo "$tarFile" | grep -Po "^$pattern\$" > /dev/null
43 | if [ $? -eq 0 ]; then
44 | # Package file matches a valid pattern
45 | VALID=1
46 | break
47 | fi
48 | done <<< `cat $1`
49 | if [ $VALID -ne 1 ]; then
50 | echo "$tarFile does not match any pattern"
51 | REJECTED_FILES=$((REJECTED_FILES + 1))
52 | fi
53 | done
54 | if [ $REJECTED_FILES -gt 0 ]; then
55 | echo "Filelist check failed ($REJECTED_FILES item(s) invalid)"
56 | exit 1
57 | fi
--------------------------------------------------------------------------------
/tools/spdx-dependencies.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2019 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 | # https://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 | # This script checks project dependencies. Depending on the package
18 | # manager, a different process will occur to obtain the license.
19 | #
20 | # Each license will be validated against an spdx identifier and a
21 | # list provided by the developer listing the approved licenses that
22 | # they can use.
23 | #
24 | # Example usage (npm):
25 | # cat package.json | jq .dependencies | grep -Po '".*":' | sed -e 's/[\":]//g' | ./tools/spdx-dependencies.sh npm approved-licenses.txt
26 | # Example usage (pypi):
27 | # cat requirements.txt | sed -r 's/([A-Za-z-]*).*/\1/g' | ./tools/spdx-dependencies.sh pypi approved-licenses.txt
28 |
29 | if [ "$#" -lt 2 ]; then
30 | echo "Expected usage: '' | ./tools/spdx-dependencies.sh approved-licenses.txt "
31 | echo " Supported package managers here: https://libraries.io/platforms"
32 | exit 1
33 | fi
34 |
35 | if [ "$#" -lt 3 ]; then
36 | echo "Missing parameter: "
37 | echo "To obtain licensing data, this script uses libraries.io"
38 | echo "An API key is required. Visit https://libraries.io/account"
39 | echo "to get one."
40 | exit 2
41 | fi
42 |
43 | while read dependency
44 | do
45 | # Escape any slashes in the dependency name
46 | dependency=`echo $dependency | sed -r 's/\//%2F/g'`
47 | API_RESPONSE=`curl -s "https://libraries.io/api/$1/$dependency?api_key=$3"`
48 | LICENSE=`echo $API_RESPONSE | sed -r 's/.*"normalized_licenses":\["([A-Za-z0-9.-]*)"].*/\1/g'`
49 |
50 | # Check if it has a valid spdx license
51 | echo $LICENSE | ./tools/spdx.sh > /dev/null
52 | if [ $? -ne 0 ]; then
53 | echo "$dependency does not have a valid license: $LICENSE"
54 | exit 3
55 | fi
56 |
57 | # Check if license matches approved licenses list
58 | cat $2 | grep $LICENSE > /dev/null
59 | if [ $? -ne 0 ]; then
60 | echo "$dependency does not have an approved license: $LICENSE"
61 | exit 4
62 | fi
63 | done
--------------------------------------------------------------------------------
/tools/spdx.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2019 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 | # https://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 | # This script checks whether the input is a valid spdx identifier
18 | #
19 | # Example usage:
20 | # echo "MIT" | ./tools/spdx.sh
21 | # Exits with 0
22 | #
23 | # echo "MITT" | ./tools/spdx.sh
24 | # Exits with 1
25 | #
26 | # List version 3.4 (2018-12-20)
27 | # https://spdx.org/licenses/
28 |
29 | read input
30 | # Check contents against a list of identifiers
31 | cat ./tools/spdx/license-ids.txt | grep -Po "^$input\$"
--------------------------------------------------------------------------------
/tools/spdx/license-ids.txt:
--------------------------------------------------------------------------------
1 | 0BSD
2 | AAL
3 | ADSL
4 | AFL-1.1
5 | AFL-1.2
6 | AFL-2.0
7 | AFL-2.1
8 | AFL-3.0
9 | AGPL-1.0-only
10 | AGPL-1.0-or-later
11 | AGPL-3.0-only
12 | AGPL-3.0-or-later
13 | AMDPLPA
14 | AML
15 | AMPAS
16 | ANTLR-PD
17 | APAFML
18 | APL-1.0
19 | APSL-1.0
20 | APSL-1.1
21 | APSL-1.2
22 | APSL-2.0
23 | Abstyles
24 | Adobe-2006
25 | Adobe-Glyph
26 | Afmparse
27 | Aladdin
28 | Apache-1.0
29 | Apache-1.1
30 | Apache-2.0
31 | Artistic-1.0
32 | Artistic-1.0-Perl
33 | Artistic-1.0-cl8
34 | Artistic-2.0
35 | BSD-1-Clause
36 | BSD-2-Clause
37 | BSD-2-Clause-FreeBSD
38 | BSD-2-Clause-NetBSD
39 | BSD-2-Clause-Patent
40 | BSD-3-Clause
41 | BSD-3-Clause-Attribution
42 | BSD-3-Clause-Clear
43 | BSD-3-Clause-LBNL
44 | BSD-3-Clause-No-Nuclear-License
45 | BSD-3-Clause-No-Nuclear-License-2014
46 | BSD-3-Clause-No-Nuclear-Warranty
47 | BSD-4-Clause
48 | BSD-4-Clause-UC
49 | BSD-Protection
50 | BSD-Source-Code
51 | BSL-1.0
52 | Bahyph
53 | Barr
54 | Beerware
55 | BitTorrent-1.0
56 | BitTorrent-1.1
57 | Borceux
58 | CATOSL-1.1
59 | CC-BY-1.0
60 | CC-BY-2.0
61 | CC-BY-2.5
62 | CC-BY-3.0
63 | CC-BY-4.0
64 | CC-BY-NC-1.0
65 | CC-BY-NC-2.0
66 | CC-BY-NC-2.5
67 | CC-BY-NC-3.0
68 | CC-BY-NC-4.0
69 | CC-BY-NC-ND-1.0
70 | CC-BY-NC-ND-2.0
71 | CC-BY-NC-ND-2.5
72 | CC-BY-NC-ND-3.0
73 | CC-BY-NC-ND-4.0
74 | CC-BY-NC-SA-1.0
75 | CC-BY-NC-SA-2.0
76 | CC-BY-NC-SA-2.5
77 | CC-BY-NC-SA-3.0
78 | CC-BY-NC-SA-4.0
79 | CC-BY-ND-1.0
80 | CC-BY-ND-2.0
81 | CC-BY-ND-2.5
82 | CC-BY-ND-3.0
83 | CC-BY-ND-4.0
84 | CC-BY-SA-1.0
85 | CC-BY-SA-2.0
86 | CC-BY-SA-2.5
87 | CC-BY-SA-3.0
88 | CC-BY-SA-4.0
89 | CC0-1.0
90 | CDDL-1.0
91 | CDDL-1.1
92 | CDLA-Permissive-1.0
93 | CDLA-Sharing-1.0
94 | CECILL-1.0
95 | CECILL-1.1
96 | CECILL-2.0
97 | CECILL-2.1
98 | CECILL-B
99 | CECILL-C
100 | CNRI-Jython
101 | CNRI-Python
102 | CNRI-Python-GPL-Compatible
103 | CPAL-1.0
104 | CPL-1.0
105 | CPOL-1.02
106 | CUA-OPL-1.0
107 | Caldera
108 | ClArtistic
109 | Condor-1.1
110 | Crossword
111 | CrystalStacker
112 | Cube
113 | D-FSL-1.0
114 | DOC
115 | DSDP
116 | Dotseqn
117 | ECL-1.0
118 | ECL-2.0
119 | EFL-1.0
120 | EFL-2.0
121 | EPL-1.0
122 | EPL-2.0
123 | EUDatagrid
124 | EUPL-1.0
125 | EUPL-1.1
126 | EUPL-1.2
127 | Entessa
128 | ErlPL-1.1
129 | Eurosym
130 | FSFAP
131 | FSFUL
132 | FSFULLR
133 | FTL
134 | Fair
135 | Frameworx-1.0
136 | FreeImage
137 | GFDL-1.1-only
138 | GFDL-1.1-or-later
139 | GFDL-1.2-only
140 | GFDL-1.2-or-later
141 | GFDL-1.3-only
142 | GFDL-1.3-or-later
143 | GL2PS
144 | GPL-1.0-only
145 | GPL-1.0-or-later
146 | GPL-2.0-only
147 | GPL-2.0-or-later
148 | PL-3.0-only
149 | GPL-3.0-or-later
150 | Giftware
151 | Glide
152 | Glulxe
153 | HPND
154 | HaskellReport
155 | IBM-pibs
156 | ICU
157 | IJG
158 | IPA
159 | IPL-1.0
160 | ISC
161 | ImageMagick
162 | Imlib2
163 | Info-ZIP
164 | Intel
165 | Intel-ACPI
166 | Interbase-1.0
167 | JSON
168 | JasPer-2.0
169 | LAL-1.2
170 | LAL-1.3
171 | LGPL-2.0-only
172 | LGPL-2.0-or-later
173 | LGPL-2.1-only
174 | LGPL-2.1-or-later
175 | LGPL-3.0-only
176 | LGPL-3.0-or-later
177 | LGPLLR
178 | LPL-1.0
179 | LPL-1.02
180 | LPPL-1.0
181 | LPPL-1.1
182 | LPPL-1.2
183 | LPPL-1.3a
184 | LPPL-1.3c
185 | Latex2e
186 | Leptonica
187 | LiLiQ-P-1.1
188 | LiLiQ-R-1.1
189 | LiLiQ-Rplus-1.1
190 | Libpng
191 | Linux-OpenIB
192 | MIT
193 | MIT-0
194 | MIT-CMU
195 | MIT-advertising
196 | MIT-enna
197 | MIT-feh
198 | MITNFA
199 | MPL-1.0
200 | MPL-1.1
201 | MPL-2.0
202 | MPL-2.0-no-copyleft-exception
203 | MS-PL
204 | MS-RL
205 | MTLL
206 | MakeIndex
207 | MirOS
208 | Motosoto
209 | Multics
210 | Mup
211 | NASA-1.3
212 | NBPL-1.0
213 | NCSA
214 | NGPL
215 | NLOD-1.0
216 | NLPL
217 | NOSL
218 | NPL-1.0
219 | NPL-1.1
220 | NPOSL-3.0
221 | NRL
222 | NTP
223 | Naumen
224 | Net-SNMP
225 | NetCDF
226 | Newsletr
227 | Nokia
228 | Noweb
229 | OCCT-PL
230 | OCLC-2.0
231 | ODC-By-1.0
232 | ODbL-1.0
233 | OFL-1.0
234 | OFL-1.1
235 | OGL-UK-1.0
236 | OGL-UK-2.0
237 | OGL-UK-3.0
238 | OGTSL
239 | OLDAP-1.1
240 | OLDAP-1.2
241 | OLDAP-1.3
242 | OLDAP-1.4
243 | OLDAP-2.0
244 | OLDAP-2.0.1
245 | OLDAP-2.1
246 | OLDAP-2.2
247 | OLDAP-2.2.1
248 | OLDAP-2.2.2
249 | OLDAP-2.3
250 | OLDAP-2.4
251 | OLDAP-2.5
252 | OLDAP-2.6
253 | OLDAP-2.7
254 | OLDAP-2.8
255 | OML
256 | OPL-1.0
257 | OSET-PL-2.1
258 | OSL-1.0
259 | OSL-1.1
260 | OSL-2.0
261 | OSL-2.1
262 | OSL-3.0
263 | OpenSSL
264 | PDDL-1.0
265 | PHP-3.0
266 | PHP-3.01
267 | Plexus
268 | PostgreSQL
269 | Python-2.0
270 | QPL-1.0
271 | Qhull
272 | RHeCos-1.1
273 | RPL-1.1
274 | RPL-1.5
275 | RPSL-1.0
276 | RSA-MD
277 | RSCPL
278 | Rdisc
279 | Ruby
280 | SAX-PD
281 | SCEA
282 | SGI-B-1.0
283 | SGI-B-1.1
284 | SGI-B-2.0
285 | SISSL
286 | SISSL-1.2
287 | SMLNJ
288 | SMPPL
289 | SNIA
290 | SPL-1.0
291 | SWL
292 | Saxpath
293 | Sendmail
294 | Sendmail-8.23
295 | SimPL-2.0
296 | Sleepycat
297 | Spencer-86
298 | Spencer-94
299 | Spencer-99
300 | SugarCRM-1.1.3
301 | TCL
302 | TCP-wrappers
303 | TMate
304 | TORQUE-1.1
305 | TOSL
306 | TU-Berlin-1.0
307 | TU-Berlin-2.0
308 | UPL-1.0
309 | Unicode-DFS-2015
310 | Unicode-DFS-2016
311 | Unicode-TOU
312 | Unlicense
313 | VOSTROM
314 | VSL-1.0
315 | Vim
316 | W3C
317 | W3C-19980720
318 | W3C-20150513
319 | WTFPL
320 | Watcom-1.0
321 | Wsuipa
322 | X11
323 | XFree86-1.1
324 | XSkat
325 | Xerox
326 | Xnet
327 | YPL-1.0
328 | YPL-1.1
329 | ZPL-1.1
330 | ZPL-2.0
331 | ZPL-2.1
332 | Zed
333 | Zend-2.0
334 | imbra-1.3
335 | Zimbra-1.4
336 | Zlib
337 | bzip2-1.0.5
338 | bzip2-1.0.6
339 | copyleft-next-0.3.0
340 | copyleft-next-0.3.1
341 | curl
342 | diffmark
343 | dvipdfm
344 | eGenix
345 | gSOAP-1.3b
346 | gnuplot
347 | iMatix
348 | libtiff
349 | mpich2
350 | psfrag
351 | psutils
352 | xinetd
353 | xpp
354 | zlib-acknowledgement
--------------------------------------------------------------------------------
/tools/tests/.archiveignore:
--------------------------------------------------------------------------------
1 | file1.txt
--------------------------------------------------------------------------------
/tools/tests/archive-test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | rm archive-test.zip # Remove if needed
4 | ./tools/archive.sh archive-test.zip "tools/tests" "*"
5 |
6 | zipinfo -1 archive-test.zip | grep "file1.txt"
7 | if [ $? -eq 0 ]; then
8 | echo "Archive should not contain file1.txt"
9 | exit 1
10 | fi
11 |
12 | zipinfo -1 archive-test.zip | grep "file2.txt"
13 | if [ $? -ne 0 ]; then
14 | echo "Archive is missing file2.txt"
15 | exit 1
16 | fi
17 |
18 | echo "All tests pass"
--------------------------------------------------------------------------------
/tools/tests/conventional-changelog-test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Copyright 2020 Google LLC
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # https://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 | bash ./tools/conventional-changelog.sh test > /tmp/conventional.md
17 | diff ./tools/tests/conventional.md /tmp/conventional.md
18 |
19 | if [ $? -eq 0 ]; then
20 | echo "Test passed"
21 | else
22 | echo "Test failed"
23 | exit 1
24 | fi
25 |
--------------------------------------------------------------------------------
/tools/tests/conventional.md:
--------------------------------------------------------------------------------
1 | # v1.0.0 - 2020-03-30
2 | ## Deprecated
3 | * The CPU no longer overheats when you hold down spacebar
4 |
5 | ## Added
6 | * Added something
7 |
8 | ## Changed
9 | * Update dependencies
10 | * Convert array to object
11 | * Add lint test
12 | * Fix typo
13 | * Switch from tabs to spaces
14 | * Rename Adapter to Interface
15 | * Improve load times by 50%
16 | * Add test for timeout
17 |
18 | ## Fixed
19 | ### other
20 | * Fix bugs
21 |
22 | ### processor
23 | * Fix processing hangup
24 |
25 | ## Security
26 | * Sanitize SQL entries
27 |
28 |
--------------------------------------------------------------------------------
/tools/tests/file1.txt:
--------------------------------------------------------------------------------
1 | I am file 1.
--------------------------------------------------------------------------------
/tools/tests/file2.txt:
--------------------------------------------------------------------------------
1 | I am file 2.
--------------------------------------------------------------------------------
/tools/tests/filelist-test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2019 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 | # https://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 | tar -tf ./tools/tests/listoffiles-pass.tar.gz | ./tools/filelist.sh ./tools/tests/listoffiles.txt
18 | if [ $? -ne 0 ]; then
19 | echo "listoffiles-pass.tar.gz check did not pass as expected"
20 | exit 1
21 | fi
22 |
23 | tar -tf ./tools/tests/listoffiles-fail.tar.gz | ./tools/filelist.sh ./tools/tests/listoffiles.txt
24 | if [ $? -eq 0 ]; then
25 | echo "listoffiles-fail.tar.gz check did not fail as expected"
26 | exit 1
27 | fi
28 |
29 | echo "All tests pass"
--------------------------------------------------------------------------------
/tools/tests/listoffiles-fail.tar.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/git-presubmit-linter/2cce6818fac0ebb5e7d49245363cf75d3e1fc123/tools/tests/listoffiles-fail.tar.gz
--------------------------------------------------------------------------------
/tools/tests/listoffiles-pass.tar.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/git-presubmit-linter/2cce6818fac0ebb5e7d49245363cf75d3e1fc123/tools/tests/listoffiles-pass.tar.gz
--------------------------------------------------------------------------------
/tools/tests/listoffiles.txt:
--------------------------------------------------------------------------------
1 | file\\d\\.txt
--------------------------------------------------------------------------------
/tools/tests/spdx-approved-licenses-mit-only.txt:
--------------------------------------------------------------------------------
1 | MIT
--------------------------------------------------------------------------------
/tools/tests/spdx-approved-licenses.txt:
--------------------------------------------------------------------------------
1 | MIT
2 | Apache-2.0
--------------------------------------------------------------------------------
/tools/tests/spdx-dependencies-test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2019 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 | # https://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 |
18 | if [ "$#" -lt 1 ]; then
19 | echo "Missing parameter: "
20 | echo "To obtain licensing data, this script uses libraries.io"
21 | echo "An API key is required. Visit https://libraries.io/account"
22 | echo "to get one."
23 | exit 1
24 | fi
25 |
26 | # Test a valid list
27 |
28 | DEPENDENCIES_NPM="
29 | actions-on-google-testing\\n
30 | typedoc-neo-theme"
31 |
32 | echo -e $DEPENDENCIES_NPM | ./tools/spdx-dependencies.sh npm ./tools/tests/spdx-approved-licenses.txt $1
33 | if [ $? -ne 0 ]; then
34 | echo "SPDX check did not pass as expected"
35 | exit 1
36 | fi
37 |
38 | # Test a list with invalid dependencies
39 |
40 | DEPENDENCIES_NPM="
41 | actions-on-google-testing-0\\n
42 | typedoc-neo-theme"
43 |
44 | echo -e $DEPENDENCIES_NPM | ./tools/spdx-dependencies.sh npm ./tools/tests/spdx-approved-licenses.txt $1
45 | if [ $? -eq 0 ]; then
46 | echo "SPDX check did not fail as expected"
47 | exit 1
48 | fi
49 |
50 | # Test a list where a license is not approved
51 |
52 | DEPENDENCIES_NPM="
53 | actions-on-google-testing\\n
54 | typedoc-neo-theme"
55 |
56 | echo -e $DEPENDENCIES_NPM | ./tools/spdx-dependencies.sh npm ./tools/tests/spdx-approved-licenses-mit-only.txt $1
57 | if [ $? -eq 0 ]; then
58 | echo "SPDX check did not fail as expected"
59 | exit 1
60 | fi
61 |
62 | DEPENDENCIES_PYPI="
63 | google-assistant-sdk"
64 |
65 | echo -e $DEPENDENCIES_PYPI | ./tools/spdx-dependencies.sh pypi ./tools/tests/spdx-approved-licenses.txt $1
66 | if [ $? -ne 0 ]; then
67 | echo "SPDX check did not pass as expected"
68 | exit 1
69 | fi
70 |
71 | DEPENDENCIES_PYPI="
72 | google-assistant-sdk-0\\n"
73 |
74 | echo -e $DEPENDENCIES_PYPI | ./tools/spdx-dependencies.sh pypi ./tools/tests/spdx-approved-licenses.txt $1
75 | if [ $? -eq 0 ]; then
76 | echo "SPDX check did not fail as expected"
77 | exit 1
78 | fi
79 |
80 | DEPENDENCIES_PYPI="
81 | google-assistant-sdk"
82 |
83 | echo -e $DEPENDENCIES_PYPI | ./tools/spdx-dependencies.sh pypi ./tools/tests/spdx-approved-licenses-mit-only.txt $1
84 | if [ $? -eq 0 ]; then
85 | echo "SPDX check did not fail as expected"
86 | exit 1
87 | fi
88 |
89 |
90 | echo "All tests pass"
--------------------------------------------------------------------------------
/tools/tests/spdx-test.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright 2019 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 | # https://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 | echo "MIT" | ./tools/spdx.sh > /dev/null
18 | if [ $? -ne 0 ]; then
19 | echo "MIT should be a valid spdx identifier"
20 | exit 1
21 | fi
22 |
23 | echo "MITT" | ./tools/spdx.sh > /dev/null
24 | if [ $? -eq 0 ]; then
25 | echo "MITT is not a valid spdx identifier"
26 | exit 1
27 | fi
28 |
29 | echo "All tests pass"
--------------------------------------------------------------------------------