Support hashes in requirement files for version-file (#287)

This commit is contained in:
Mattias L
2025-12-17 16:29:06 +01:00
committed by GitHub
parent 8b935c8722
commit e85c033ebc
4 changed files with 31 additions and 14 deletions
+20
View File
@@ -236,6 +236,25 @@ jobs:
fi fi
env: env:
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }} RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
test-default-version-from-requirements-with-hash:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Use default version from requirements-with-hash.txt
id: ruff-action
uses: ./
with:
src: __tests__/fixtures/python-project
version-file: __tests__/fixtures/requirements-with-hash.txt
- name: Correct version gets installed
run: |
if [ "$RUFF_VERSION" != "0.9.0" ]; then
exit 1
fi
env:
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
test-semver-range: test-semver-range:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@@ -383,6 +402,7 @@ jobs:
- test-default-version-from-pyproject-poetry - test-default-version-from-pyproject-poetry
- test-default-version-from-pyproject-optional-dependencies - test-default-version-from-pyproject-optional-dependencies
- test-default-version-from-requirements - test-default-version-from-requirements
- test-default-version-from-requirements-with-hash
- test-semver-range - test-semver-range
- test-pep440-version-specifier - test-pep440-version-specifier
- test-checksum - test-checksum
@@ -0,0 +1,2 @@
ruff==0.9.0 \
--hash=sha256:badc0de
Generated Vendored
+4 -7
View File
@@ -32317,14 +32317,11 @@ const toml = __importStar(__nccwpck_require__(7106));
function getRuffVersionFromAllDependencies(allDependencies) { function getRuffVersionFromAllDependencies(allDependencies) {
const ruffVersionDefinition = allDependencies.find((dep) => dep.startsWith("ruff")); const ruffVersionDefinition = allDependencies.find((dep) => dep.startsWith("ruff"));
if (ruffVersionDefinition) { if (ruffVersionDefinition) {
const ruffVersion = ruffVersionDefinition const match = ruffVersionDefinition.trim().match(/^ruff\s*==\s*([^\s\\]+)/);
.match(/^ruff([^A-Z0-9._-]+.*)$/)?.[1] if (match) {
.trim(); core.info(`Found ruff version in requirements file: ${match[1]}`);
if (ruffVersion?.startsWith("==")) { return match[1];
return ruffVersion.slice(2);
} }
core.info(`Found ruff version in pyproject.toml: ${ruffVersion}`);
return ruffVersion;
} }
return undefined; return undefined;
} }
+5 -7
View File
@@ -10,14 +10,12 @@ function getRuffVersionFromAllDependencies(
); );
if (ruffVersionDefinition) { if (ruffVersionDefinition) {
const ruffVersion = ruffVersionDefinition const match = ruffVersionDefinition.trim().match(/^ruff\s*==\s*([^\s\\]+)/);
.match(/^ruff([^A-Z0-9._-]+.*)$/)?.[1]
.trim(); if (match) {
if (ruffVersion?.startsWith("==")) { core.info(`Found ruff version in requirements file: ${match[1]}`);
return ruffVersion.slice(2); return match[1];
} }
core.info(`Found ruff version in pyproject.toml: ${ruffVersion}`);
return ruffVersion;
} }
return undefined; return undefined;