-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #591 from akaihola/gh-action-working-directory
GH action to respect `working-directory`
- Loading branch information
Showing
5 changed files
with
218 additions
and
23 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,107 @@ | ||
--- | ||
name: "GH Action `working-directory:` test" | ||
|
||
on: push # yamllint disable-line rule:truthy | ||
|
||
jobs: | ||
setup: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set up initial test repository | ||
run: | | ||
mkdir -p test-repo | ||
cd 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 | ||
- name: Upload test repository | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: test-repo | ||
path: test-repo | ||
|
||
test: | ||
needs: setup | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
scenario: | ||
- name: no-work-dir | ||
working_directory: null # Consider it omitted | ||
src: test.py | ||
options: --check --diff | ||
expected_exitcode: 2 | ||
- name: right-workdir | ||
working_directory: test-repo | ||
src: test.py | ||
options: --check --diff | ||
expected_exitcode: 1 | ||
- name: wrong-work-dir | ||
working_directory: non-existent-dir | ||
src: test.py | ||
options: --check --diff | ||
expected_exitcode: 21 | ||
- name: file-not-found | ||
working_directory: test-repo | ||
src: non_existent_file.py | ||
options: --check --diff | ||
expected_exitcode: 2 | ||
- name: invalid-arguments | ||
working_directory: test-repo | ||
src: test.py | ||
options: --invalid-option | ||
expected_exitcode: 3 | ||
- name: missing-deps | ||
working_directory: test-repo | ||
src: test.py | ||
options: --flynt # not yet supported by the action | ||
expected_exitcode: 4 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 10 | ||
|
||
- name: Download test repository | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: test-repo | ||
path: ${{ runner.temp }}/test-repo | ||
|
||
- name: "Run Darker - ${{ matrix.scenario.name }}" | ||
uses: ./ | ||
continue-on-error: true | ||
id: darker-run | ||
with: | ||
version: "@gh-action-working-directory" | ||
options: ${{ matrix.scenario.options }} | ||
# In the action, '.' is the default value used if `working-directory` omitted | ||
working-directory: >- | ||
${{ | ||
matrix.scenario.working_directory == null && '.' | ||
|| format('{0}/{1}', runner.temp, matrix.scenario.working_directory) | ||
}} | ||
src: ${{ matrix.scenario.src }} | ||
revision: HEAD | ||
|
||
- name: Check exit code | ||
if: >- | ||
steps.darker-run.outputs.exitcode != matrix.scenario.expected_exitcode | ||
run: | | ||
echo "::error::Expected exit code ${{ matrix.scenario.expected_exitcode }}" | ||
echo "::error::Darker exited with ${{ steps.darker-run.outputs.exitcode }}" | ||
exit 1 | ||
- name: Verify diff output for right-workdir scenario | ||
if: > | ||
matrix.scenario.name == 'right-workdir' && | ||
!contains(steps.darker-run.outputs.stdout, '@@') | ||
run: | | ||
echo "::error::Darker did not output a diff as expected" | ||
exit 1 |
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 |
---|---|---|
|
@@ -27,6 +27,19 @@ inputs: | |
NOTE: Baseline linting has been moved to the Graylint package. | ||
required: false | ||
default: '' | ||
working-directory: | ||
description: >- | ||
Directory to run Darker in, either absolute or relative to | ||
$GITHUB_WORKSPACE. By default, Darker is run in $GITHUB_WORKSPACE. | ||
required: false | ||
default: '.' | ||
outputs: | ||
exitcode: | ||
description: "Exit code of Darker" | ||
value: ${{ steps.darker.outputs.exitcode }} | ||
stdout: | ||
description: "Standard output of Darker" | ||
value: ${{ steps.darker.outputs.stdout }} | ||
branding: | ||
color: "black" | ||
icon: "check-circle" | ||
|
@@ -35,8 +48,18 @@ runs: | |
steps: | ||
- name: Commit Range | ||
id: commit-range | ||
uses: akaihola/darker/.github/actions/[email protected] | ||
uses: ./.github/actions/commit-range | ||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.x' | ||
cache: 'pip' | ||
- name: Install dependencies | ||
run: | | ||
pip install pip-requirements-parser | ||
shell: bash | ||
- name: Run Darker | ||
id: darker | ||
run: | | ||
# Exists since using github.action_path + path to main script doesn't | ||
# work because bash interprets the backslashes in github.action_path | ||
|
@@ -68,5 +91,6 @@ runs: | |
INPUT_REVISION: ${{ inputs.revision }} | ||
INPUT_LINT: ${{ inputs.lint }} | ||
INPUT_COMMIT_RANGE: ${{ steps.commit-range.outputs.commit-range }} | ||
INPUT_WORKING_DIRECTORY: ${{ inputs.working-directory }} | ||
pythonioencoding: utf-8 | ||
shell: bash |
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