-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #10
- Loading branch information
Metin Yazici
committed
Mar 21, 2022
1 parent
21959dd
commit 30ea39e
Showing
19 changed files
with
248 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import argparse | ||
import difflib | ||
import subprocess | ||
|
||
|
||
def get_file_lines(filename): | ||
with open(filename) as file: | ||
lines = file.readlines() | ||
return lines | ||
|
||
|
||
def get_readme_text(lines, start_pattern, end_pattern): | ||
start_index = lines.index(start_pattern) + 1 | ||
end_index = lines.index(end_pattern) | ||
sublines = lines[start_index:end_index] | ||
# remove backticks | ||
sublines = [line for line in sublines if line != "```\n"] | ||
text = "".join(sublines) | ||
return text | ||
|
||
|
||
def get_command_output(command): | ||
cmd = command.split(" ") | ||
out = None | ||
run = subprocess.run(cmd, stdout=subprocess.PIPE) | ||
if run.returncode == 0: | ||
out = run.stdout.decode("utf-8") | ||
return out | ||
raise ValueError("could not get the help text") | ||
|
||
|
||
def check_if_equal(command_output, readme_text): | ||
equal = command_output == readme_text | ||
if not equal: | ||
d1 = command_output.splitlines(keepends=True) | ||
d2 = readme_text.splitlines(keepends=True) | ||
print("".join(difflib.ndiff(d1, d2))) | ||
print("* * *") | ||
raise ValueError("readme text is not up-to-date") | ||
print("help output in readme is up-to-date") | ||
|
||
|
||
def get_cli_args(): | ||
parser = argparse.ArgumentParser( | ||
description="Check a block of text in a file against an output returned by a command or any other piped output." | ||
) | ||
parser.add_argument("--file", required=True, help="file to check the block") | ||
parser.add_argument("--pattern_start", required=True, help="start pattern") | ||
parser.add_argument("--pattern_end", required=True, help="end pattern") | ||
parser.add_argument("--command", required=True, help="command to check the output") | ||
parsed_args = parser.parse_args() | ||
# this solution isn't great as it also removes the other unicode characters | ||
# but so far, I don't have any use case so fine. | ||
parsed_args.pattern_start = bytes(parsed_args.pattern_start, "utf-8").decode( | ||
"unicode_escape" | ||
) | ||
parsed_args.pattern_end = bytes(parsed_args.pattern_end, "utf-8").decode( | ||
"unicode_escape" | ||
) | ||
return parsed_args | ||
|
||
|
||
def main(): | ||
args = get_cli_args() | ||
lines = get_file_lines(args.file) | ||
readme_text = get_readme_text(lines, args.pattern_start, args.pattern_end) | ||
command_output = get_command_output(args.command) | ||
check_if_equal(command_output, readme_text) | ||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,34 +4,69 @@ on: [push, pull_request] | |
|
||
jobs: | ||
|
||
pre-commit: | ||
prepare: | ||
name: "Prepare for CI" | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 1 | ||
|
||
outputs: | ||
py_version: ${{ steps.versions.outputs.py_version }} | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Get versions | ||
id: versions | ||
run: | | ||
py_version="$(./get_version.sh __py_version__)" | ||
echo "::set-output name=py_version::$py_version" | ||
pre_commit: | ||
name: pre-commit checks | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 2 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
- uses: pre-commit/[email protected] | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
- uses: pre-commit/[email protected] | ||
|
||
tests: | ||
name: Run tests with python ${{ matrix.python-version }} | ||
check_readme: | ||
name: "Check README help text" | ||
needs: [ prepare ] | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 2 | ||
|
||
strategy: | ||
matrix: | ||
python-version: | ||
- "3.8" | ||
- "3.9" | ||
- "3.10" | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ needs.prepare.outputs.version }} | ||
|
||
- name: Install | ||
run: make install | ||
|
||
- name: Check if help text in README is up-to-date | ||
run: | | ||
python .github/scripts/check_text.py \ | ||
--file "README.md" \ | ||
--pattern_start '<!-- help-output: start -->\n' \ | ||
--pattern_end '<!-- help-output: end -->\n' \ | ||
--command "git-substatus --help" | ||
tests: | ||
name: "Run tests" | ||
needs: [ prepare ] | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 2 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
python-version: ${{ needs.prepare.outputs.version }} | ||
|
||
- name: Install dev dependencies | ||
run: | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Integration | ||
|
||
on: | ||
push: | ||
branches: | ||
- "master" | ||
|
||
jobs: | ||
|
||
test_docker: | ||
name: Build and test Docker image | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 3 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Build the Docker image | ||
run: make VERSION=test docker-build | ||
|
||
- name: Docker container can be run | ||
run: | | ||
./tests/gen_test_repos.sh && \ | ||
docker run --rm -t \ | ||
-v "$(pwd)":/"$(pwd)" \ | ||
-w "$(pwd)" strboul/git-substatus:test \ | ||
tests/generated-test-proj-dir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Get the package versions as listed in the init file | ||
|
||
variable="$1" | ||
sed -n "s/$variable = *\"\([^ ]*\)\"/\1/p" git_substatus/__init__.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# package version: | ||
__version__ = "0.2.9" | ||
__version__ = "0.2.10" | ||
|
||
# min default supported python version: | ||
__py_version__ = "3.8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.