Skip to content

Commit

Permalink
Fix version-file input
Browse files Browse the repository at this point in the history
The input was previously ignored
  • Loading branch information
eifinger committed Feb 6, 2025
1 parent f14634c commit 7868836
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ jobs:
with:
version: ${{ matrix.ruff-version }}
src: __tests__/fixtures/python-project
test-version-from-version-file-pyproject:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use version from pyproject.toml
id: ruff-action
uses: ./
with:
src: __tests__/fixtures/python-project
version-file: __tests__/fixtures/pyproject.toml
- name: Correct version gets installed
run: |
if [ "$RUFF_VERSION" != "0.9.3" ]; then
exit 1
fi
env:
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
test-default-version-from-pyproject:
runs-on: ubuntu-latest
steps:
Expand Down
13 changes: 13 additions & 0 deletions __tests__/fixtures/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[project]
name = "pyython-project"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"ruff==0.9.3",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
10 changes: 8 additions & 2 deletions dist/ruff-action/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/download/download-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export async function resolveVersion(
versionInput: string,
githubToken: string,
): Promise<string> {
core.debug(`Resolving ${versionInput}...`);
const version =
versionInput === "latest"
? await getLatestVersion(githubToken)
Expand All @@ -84,6 +85,7 @@ export async function resolveVersion(
if (resolvedVersion === "") {
throw new Error(`No version found for ${version}`);
}
core.debug(`Resolved version: ${resolvedVersion}`);
return resolvedVersion;
}

Expand Down
10 changes: 8 additions & 2 deletions src/ruff-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,22 @@ async function determineVersion(): Promise<string> {
const versionFromPyproject = getRuffVersionFromPyproject(versionFileInput);
if (versionFromPyproject === undefined) {
core.warning(
"Could not parse version from supplied pyproject.toml. Using latest version.",
`Could not parse version from ${versionFileInput}. Using latest version.`,
);
return await resolveVersion("latest", githubToken);
}
return await resolveVersion(versionFromPyproject || "latest", githubToken);
}
const pyProjectPath = path.join(src, "pyproject.toml");
if (!fs.existsSync(pyProjectPath)) {
core.info(`Could not find ${pyProjectPath}. Using latest version.`);
return await resolveVersion("latest", githubToken);
}
const versionFromPyproject = getRuffVersionFromPyproject(pyProjectPath);
if (versionFromPyproject === undefined) {
core.warning(
`Could not parse version from ${pyProjectPath}. Using latest version.`,
);
}
return await resolveVersion(versionFromPyproject || "latest", githubToken);
}

Expand Down

0 comments on commit 7868836

Please sign in to comment.