Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support requirements.txt for version-file #68

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,23 @@ jobs:
fi
env:
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
test-default-version-from-requirements:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use default version from requirements.txt
id: ruff-action
uses: ./
with:
src: __tests__/fixtures/requirements
version-file: __tests__/fixtures/requirements/requirements.txt
- name: Correct version gets installed
run: |
if [ "$RUFF_VERSION" != "0.8.3" ]; then
exit 1
fi
env:
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
test-semver-range:
runs-on: ubuntu-latest
steps:
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ Currently `pyproject.toml` is supported.
version-file: "my-path/to/pyproject.toml"
```

And `requirements.txt` is supported.
daveisfera marked this conversation as resolved.
Show resolved Hide resolved

```yaml
- name: Install a version from a specified version file
uses: astral-sh/ruff-action@v3
with:
version-file: "my-path/to/requirements.txt"
```

### Validate checksum

You can specify a checksum to validate the downloaded executable. Checksums up to the default version
Expand Down
1 change: 1 addition & 0 deletions __tests__/fixtures/requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruff==0.8.3
daveisfera marked this conversation as resolved.
Show resolved Hide resolved
44 changes: 24 additions & 20 deletions src/utils/pyproject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,32 @@ export function getRuffVersionFromPyproject(
"dependency-groups"?: Map<string, Array<string | object>>;
}
| undefined;
try {
pyproject = toml.parse(pyprojectContent);
} catch (err) {
const message = (err as Error).message;
core.warning(`Error while parsing ${filePath}: ${message}`);
return undefined;
let allDependencies: string[];
if (filePath.endsWith(".txt")) {
allDependencies = pyprojectContent.split("\n");
} else {
try {
pyproject = toml.parse(pyprojectContent);
const dependencies: string[] = pyproject?.project?.dependencies || [];
const optionalDependencies: string[] = Object.values(
pyproject?.project?.["optional-dependencies"] || {},
).flat();
const devDependencies: string[] = Object.values(
pyproject?.["dependency-groups"] || {},
)
.flat()
.filter((item: string | object) => typeof item === "string");
allDependencies = dependencies.concat(
optionalDependencies,
devDependencies,
);
} catch (err) {
const message = (err as Error).message;
core.warning(`Error while parsing ${filePath}: ${message}`);
return undefined;
}
daveisfera marked this conversation as resolved.
Show resolved Hide resolved
}

const dependencies: string[] = pyproject?.project?.dependencies || [];
const optionalDependencies: string[] = Object.values(
pyproject?.project?.["optional-dependencies"] || {},
).flat();
const devDependencies: string[] = Object.values(
pyproject?.["dependency-groups"] || {},
)
.flat()
.filter((item: string | object) => typeof item === "string");
const allDependencies: string[] = dependencies.concat(
optionalDependencies,
devDependencies,
);

const ruffVersionDefinition = allDependencies.find((dep: string) =>
dep.startsWith("ruff"),
);
Expand Down
Loading