-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workflow to test
working-directory
action input
- Loading branch information
Showing
1 changed file
with
137 additions
and
0 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,137 @@ | ||
--- | ||
name: Test working-directory input | ||
|
||
on: push # yamllint disable-line rule:truthy | ||
|
||
jobs: | ||
test-working-directory: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up test environment | ||
run: | | ||
pip install pip-requirements-parser | ||
mkdir -p $RUNNER_TEMP/test-repo | ||
pushd $RUNNER_TEMP/test-repo | ||
git init | ||
git config user.email "[email protected]" | ||
git config user.name "Test User" | ||
git commit --allow-empty -m "Initial empty commit" | ||
echo 'def hello(): return "Hello, World!"' > test.py | ||
git add test.py | ||
git commit -m "Add test.py file" | ||
echo 'def hello(): return "Hello, World!"' > test.py | ||
popd | ||
- name: "Run Darker without working-directory" | ||
uses: ./ | ||
continue-on-error: true | ||
id: no-work-dir | ||
with: | ||
version: "@gh-action-working-directory" | ||
options: --check --diff | ||
src: test.py | ||
revision: HEAD | ||
|
||
- name: Fail if no exit code 2 even though test.py was not found | ||
if: steps.no-work-dir.outputs.exitcode != '2' | ||
run: | | ||
echo "::error::Darker should have failed with exit code 2" | ||
echo "::error::It exited with ${{ steps.no-work-dir.outputs.exitcode }}" | ||
exit 1 | ||
- name: "Run Darker with correct working-directory" | ||
id: right-workdir | ||
if: always() | ||
uses: ./ | ||
continue-on-error: true | ||
with: | ||
version: "@gh-action-working-directory" | ||
options: --check --diff | ||
working-directory: ${{ runner.temp }}/test-repo | ||
src: test.py | ||
revision: HEAD | ||
|
||
- name: Fail if no exit code 1 even though reformatting is needed | ||
if: steps.right-workdir.outputs.exitcode != '1' | ||
run: | | ||
echo "::error::Darker should have exited with code 1" | ||
echo "::error::It exited with ${{ steps.right-workdir.outputs.exitcode }}" | ||
exit 1 | ||
- name: Verify diff output | ||
if: ( ! contains(steps.right-workdir.outputs.stdout, '@@') ) | ||
run: | | ||
echo "::error::Darker did not output a diff as expected" | ||
exit 1 | ||
- name: "Run Darker with incorrect working-directory" | ||
if: always() | ||
uses: ./ | ||
continue-on-error: true | ||
id: wrong-work-dir | ||
with: | ||
version: "@gh-action-working-directory" | ||
options: --check --diff | ||
working-directory: ${{ runner.temp }}/non-existent-dir | ||
src: test.py | ||
revision: HEAD | ||
|
||
- name: Check that Darker failed with a non-existing working-directory | ||
if: steps.wrong-work-dir.outputs.exitcode != '21' | ||
run: | | ||
echo "::error::Darker should have exited with code 21" | ||
echo "::error::It exited with ${{ steps.wrong-work-dir.outputs.exitcode }}" | ||
exit 1 | ||
- name: "Run Darker on a non-existing file" | ||
id: file-not-found | ||
if: always() | ||
uses: ./ | ||
continue-on-error: true | ||
with: | ||
version: "@gh-action-working-directory" | ||
options: --check --diff | ||
working-directory: ${{ runner.temp }}/test-repo | ||
src: non_existent_file.py | ||
|
||
- name: Check file not found error code | ||
if: steps.file-not-found.outputs.exitcode != '2' | ||
run: | | ||
echo "::error::Darker should have exited with code 2" | ||
echo "::error::It exited with ${{ steps.file-not-found.outputs.exitcode }}" | ||
exit 1 | ||
- name: "Run Darker with an invalid argument" | ||
id: invalid-arguments | ||
if: always() | ||
uses: ./ | ||
continue-on-error: true | ||
with: | ||
version: "@gh-action-working-directory" | ||
options: --invalid-option | ||
|
||
- name: Check invalid arguments error code | ||
if: steps.invalid-arguments.outputs.exitcode != '3' | ||
run: | | ||
echo "::error::Darker should have exited with code 3" | ||
echo "::error::It exited with ${{ steps.invalid-arguments.outputs.exitcode }}" | ||
exit 1 | ||
- name: "Run Darker with a missing dependency" | ||
id: missing-deps | ||
if: always() | ||
uses: ./ | ||
continue-on-error: true | ||
with: | ||
version: "@gh-action-working-directory" | ||
working-directory: ${{ runner.temp }}/test-repo | ||
options: --flynt | ||
|
||
- name: Check missing dependencies error code | ||
if: steps.missing-deps.outputs.exitcode != '4' | ||
run: | | ||
echo "::error::Darker should have exited with code 4" | ||
echo "::error::It exited with ${{ steps.missing-deps.outputs.exitcode }}" | ||
exit 1 |