mirror of
https://github.com/astral-sh/ruff-action.git
synced 2026-11-25 21:41:57 +00:00
Compare commits
56
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aad462a4a3 | ||
|
|
602b80b240 | ||
|
|
af7afd2955 | ||
|
|
7013188d81 | ||
|
|
a9506688fc | ||
|
|
2acb44a1c3 | ||
|
|
665801e39d | ||
|
|
5226eeb6a9 | ||
|
|
ea181cb604 | ||
|
|
107126dd4d | ||
|
|
280e92ea43 | ||
|
|
be1f93951f | ||
|
|
747ffb9220 | ||
|
|
70c5336f5b | ||
|
|
22ba4f8560 | ||
|
|
f2f46687ac | ||
|
|
a737711ea8 | ||
|
|
4307b3970e | ||
|
|
8fc297008d | ||
|
|
6776b96909 | ||
|
|
cc56f639e4 | ||
|
|
3906fcf994 | ||
|
|
c890b57484 | ||
|
|
6f8f9a9d5f | ||
|
|
127e6a115e | ||
|
|
6d5deb5cee | ||
|
|
46b5b9699e | ||
|
|
848ccd1cb2 | ||
|
|
1f30a84c67 | ||
|
|
d3ef2489b0 | ||
|
|
81a72f25c9 | ||
|
|
2ce112e5ca | ||
|
|
28ec38735d | ||
|
|
2957f9e73d | ||
|
|
5b168050b9 | ||
|
|
3bb5cd7c3c | ||
|
|
8d2a42ddf5 | ||
|
|
278981a28c | ||
|
|
c35f46c92b | ||
|
|
f3db229c84 | ||
|
|
270e80dfe7 | ||
|
|
5fedeebdb3 | ||
|
|
99fe79f472 | ||
|
|
32ad1b993e | ||
|
|
f78e087041 | ||
|
|
2f88679623 | ||
|
|
b79a7ac759 | ||
|
|
30c0929868 | ||
|
|
b4bf7655a0 | ||
|
|
7f78e88b21 | ||
|
|
8c228c72ff | ||
|
|
248b6d6da3 | ||
|
|
ecaa98070e | ||
|
|
a9cfed68e4 | ||
|
|
eb44a0e99b | ||
|
|
2915b93f0d |
@@ -0,0 +1,53 @@
|
|||||||
|
---
|
||||||
|
name: dependabot-pr-rollup
|
||||||
|
description: Find open Dependabot PRs for ruff-action, compare each PR head to its base branch, replay only the remaining npm and GitHub Actions changes in a fresh worktree and branch, run repository validation, and optionally commit, push, and open a PR. Use when you want to batch or manually replicate active Dependabot updates.
|
||||||
|
license: MIT
|
||||||
|
compatibility: Requires git, git worktree, gh CLI auth, npm, and a GitHub repo with an origin remote.
|
||||||
|
---
|
||||||
|
|
||||||
|
# Dependabot PR Rollup
|
||||||
|
|
||||||
|
## When to use
|
||||||
|
|
||||||
|
Use this skill when the user wants to:
|
||||||
|
- find all open Dependabot PRs in this repo
|
||||||
|
- reproduce their net effect in one local branch
|
||||||
|
- validate the result with the repo's standard checks
|
||||||
|
- optionally commit, push, and open a PR
|
||||||
|
|
||||||
|
## Workflow
|
||||||
|
|
||||||
|
1. Inspect the current checkout state, but do not reuse a dirty worktree.
|
||||||
|
2. List open Dependabot PRs with `gh pr list --state open --author app/dependabot`.
|
||||||
|
3. For each PR, collect the title, base branch, head branch, changed files, and relevant diffs.
|
||||||
|
4. Compare each PR head against `origin/<base>` instead of trusting the PR title. Dependabot PRs can already be partially merged, superseded by newer versions, or have no remaining net effect.
|
||||||
|
5. Create a new worktree and branch from `origin/<base>`.
|
||||||
|
6. Reproduce only the remaining dependency changes in the new worktree.
|
||||||
|
- Inspect `package.json` before editing npm dependencies.
|
||||||
|
- Run `npm ci --ignore-scripts` before applying npm updates so dependency commands run from a clean install.
|
||||||
|
- Use `npm install ... --ignore-scripts` for direct npm dependency changes so `package-lock.json` stays in sync.
|
||||||
|
- Preserve whether an npm package is a `dependency` or `devDependency`.
|
||||||
|
- When updating `@biomejs/biome`, also update the Biome schema URL version in `biome.json` to match the installed Biome version.
|
||||||
|
- For GitHub Actions updates, apply the net workflow-file changes from the Dependabot PR heads after confirming they still apply cleanly to the selected base.
|
||||||
|
7. Run `npm run all`.
|
||||||
|
8. If requested, commit the changed source, lockfile, workflow files, and generated artifacts, then push and open a PR.
|
||||||
|
|
||||||
|
## Repo-specific notes
|
||||||
|
|
||||||
|
- Use `gh` for GitHub operations.
|
||||||
|
- Keep the user's original checkout untouched by working in a separate worktree.
|
||||||
|
- This repo has Dependabot configured for both `npm` and `github-actions`.
|
||||||
|
- In this repo, `npm run all` is the safest validation command because it runs build, check, package, and unit tests.
|
||||||
|
- `npm run check` may rewrite files with Biome; include those intentional formatting changes.
|
||||||
|
- If dependency changes affect bundled output, include the regenerated `dist/` files from `npm run package`.
|
||||||
|
|
||||||
|
## Report back
|
||||||
|
|
||||||
|
Always report:
|
||||||
|
- open Dependabot PRs found
|
||||||
|
- which PRs required no net changes
|
||||||
|
- new branch name
|
||||||
|
- new worktree path
|
||||||
|
- files changed
|
||||||
|
- `npm run all` result
|
||||||
|
- if applicable, commit SHA and PR URL
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
* text=auto eol=lf
|
* text=auto eol=lf
|
||||||
dist/** -diff linguist-generated=true
|
dist/** -diff linguist-generated=true
|
||||||
|
src/download/checksum/known-checksums.json linguist-generated=true
|
||||||
|
|||||||
@@ -4,8 +4,12 @@ updates:
|
|||||||
directory: /
|
directory: /
|
||||||
schedule:
|
schedule:
|
||||||
interval: daily
|
interval: daily
|
||||||
|
cooldown:
|
||||||
|
default-days: 30
|
||||||
|
|
||||||
- package-ecosystem: npm
|
- package-ecosystem: npm
|
||||||
directory: /
|
directory: /
|
||||||
schedule:
|
schedule:
|
||||||
interval: daily
|
interval: daily
|
||||||
|
cooldown:
|
||||||
|
default-days: 30
|
||||||
|
|||||||
@@ -39,13 +39,13 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@b20883b0cd1f46c72ae0ba6d1090936928f9fa30 # v4.32.0
|
uses: github/codeql-action/init@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
source-root: src
|
source-root: src
|
||||||
@@ -57,7 +57,7 @@ jobs:
|
|||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@b20883b0cd1f46c72ae0ba6d1090936928f9fa30 # v4.32.0
|
uses: github/codeql-action/autobuild@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
# 📚 https://git.io/JvXDl
|
# 📚 https://git.io/JvXDl
|
||||||
@@ -71,4 +71,4 @@ jobs:
|
|||||||
# make release
|
# make release
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@b20883b0cd1f46c72ae0ba6d1090936928f9fa30 # v4.32.0
|
uses: github/codeql-action/analyze@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ jobs:
|
|||||||
pull-requests: read
|
pull-requests: read
|
||||||
steps:
|
steps:
|
||||||
- name: 🚀 Run Release Drafter
|
- name: 🚀 Run Release Drafter
|
||||||
uses: release-drafter/release-drafter@5de93583980a40bd78603b6dfdcda5b4df377b32 # v7.2.0
|
uses: release-drafter/release-drafter@eada3c96a64734dd381cfbda23511034e328ddb0 # v7.6.0
|
||||||
|
with:
|
||||||
|
commitish: ${{ github.sha }}
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
@@ -11,31 +11,86 @@ on:
|
|||||||
permissions: {}
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
validate-release:
|
||||||
name: Release
|
name: Validate release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment: release
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- name: Validate version and draft release
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
|
|
||||||
- name: Validate version
|
|
||||||
env:
|
env:
|
||||||
|
GH_REPO: ${{ github.repository }}
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
VERSION: ${{ inputs.version }}
|
VERSION: ${{ inputs.version }}
|
||||||
|
TAG: v${{ inputs.version }}
|
||||||
run: |
|
run: |
|
||||||
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$ ]]; then
|
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$ ]]; then
|
||||||
echo "::error::Version must match MAJOR.MINOR.PATCH (e.g., 8.1.0)"
|
echo "::error::Version must match MAJOR.MINOR.PATCH (e.g., 8.1.0)"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
RELEASE_JSON=$(gh release view "$TAG" --json isDraft,targetCommitish 2>&1) || {
|
||||||
|
echo "::error::No release found for $TAG"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
IS_DRAFT=$(echo "$RELEASE_JSON" | jq -r '.isDraft')
|
||||||
|
TARGET=$(echo "$RELEASE_JSON" | jq -r '.targetCommitish')
|
||||||
|
|
||||||
|
if [[ "$IS_DRAFT" != "true" ]]; then
|
||||||
|
echo "::error::Release $TAG already exists and is not a draft"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$TARGET" != "$GITHUB_SHA" ]]; then
|
||||||
|
echo "::error::Draft release target ($TARGET) does not match current commit ($GITHUB_SHA)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
release-gate:
|
||||||
|
# N.B. This name should not change, it is used for downstream checks.
|
||||||
|
name: release-gate
|
||||||
|
needs:
|
||||||
|
- validate-release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
environment:
|
||||||
|
name: release-gate
|
||||||
|
steps:
|
||||||
|
- run: echo "Release approved"
|
||||||
|
|
||||||
|
create-deployment:
|
||||||
|
name: create-deployment
|
||||||
|
needs:
|
||||||
|
- validate-release
|
||||||
|
- release-gate
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
environment:
|
||||||
|
name: release
|
||||||
|
steps:
|
||||||
|
- run: echo "Release deployment created"
|
||||||
|
|
||||||
|
release:
|
||||||
|
name: Release
|
||||||
|
needs:
|
||||||
|
- validate-release
|
||||||
|
- release-gate
|
||||||
|
- create-deployment
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
steps:
|
||||||
- name: Publish release
|
- name: Publish release
|
||||||
env:
|
env:
|
||||||
|
GH_REPO: ${{ github.repository }}
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
VERSION: ${{ inputs.version }}
|
||||||
TAG: v${{ inputs.version }}
|
TAG: v${{ inputs.version }}
|
||||||
run: |
|
run: |
|
||||||
|
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$ ]]; then
|
||||||
|
echo "::error::Version must match MAJOR.MINOR.PATCH (e.g., 8.1.0)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
RELEASE_JSON=$(gh release view "$TAG" --json isDraft,targetCommitish 2>&1) || {
|
RELEASE_JSON=$(gh release view "$TAG" --json isDraft,targetCommitish 2>&1) || {
|
||||||
echo "::error::No release found for $TAG"
|
echo "::error::No release found for $TAG"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
+85
-27
@@ -18,19 +18,21 @@ jobs:
|
|||||||
permissions:
|
permissions:
|
||||||
security-events: write # for zizmor
|
security-events: write # for zizmor
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Actionlint
|
- name: Actionlint
|
||||||
uses: eifinger/actionlint-action@1fc89649be682d16ec5cf65ea16e269eb88d3982 # v1.10.2
|
uses: eifinger/actionlint-action@1fc89649be682d16ec5cf65ea16e269eb88d3982 # v1.10.2
|
||||||
- name: Run zizmor
|
- name: Run zizmor
|
||||||
uses: zizmorcore/zizmor-action@71321a20a9ded102f6e9ce5718a2fcec2c4f70d8 # v0.5.2
|
uses: zizmorcore/zizmor-action@cc914d7f3750a2d13d75c7f184a1060aa0e9d482 # v0.6.4
|
||||||
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
|
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
|
||||||
with:
|
with:
|
||||||
node-version-file: .nvmrc
|
node-version-file: .nvmrc
|
||||||
cache: npm
|
cache: npm
|
||||||
- run: |
|
- run: |
|
||||||
npm ci --ignore-scripts
|
npm ci --ignore-scripts
|
||||||
|
- name: Verify npm package signatures
|
||||||
|
run: npm audit signatures
|
||||||
- run: |
|
- run: |
|
||||||
npm run all
|
npm run all
|
||||||
- name: Check all jobs are in all-tests-passed.needs
|
- name: Check all jobs are in all-tests-passed.needs
|
||||||
@@ -45,9 +47,11 @@ jobs:
|
|||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, macos-latest, macos-14, windows-latest]
|
os: [ubuntu-latest, macos-latest, macos-15, windows-latest]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- if: runner.os == 'macOS'
|
||||||
|
uses: astral-sh/github-actions/demudhra@7aa50a3def9f5428c532b0ae972d1e5b357de5a5 # 2026.11.03.0
|
||||||
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Use latest version
|
- name: Use latest version
|
||||||
@@ -60,9 +64,11 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
ruff-version: ["0.1.7", "0.1.8", "0.4.7", "0.4.10", "0.7", "0.7.x", ">=0.7.0"]
|
ruff-version: ["0.1.7", "0.1.8", "0.4.7", "0.4.10", "0.7", "0.7.x", ">=0.7.0"]
|
||||||
os: [ ubuntu-latest, ubuntu-24.04-arm, macos-latest, macos-14, windows-latest ]
|
os: [ ubuntu-latest, ubuntu-24.04-arm, macos-latest, macos-15, windows-latest ]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- if: runner.os == 'macOS'
|
||||||
|
uses: astral-sh/github-actions/demudhra@7aa50a3def9f5428c532b0ae972d1e5b357de5a5 # 2026.11.03.0
|
||||||
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Use version ${{ matrix.ruff-version }}
|
- name: Use version ${{ matrix.ruff-version }}
|
||||||
@@ -73,7 +79,7 @@ jobs:
|
|||||||
test-unsupported-version:
|
test-unsupported-version:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Try install old version
|
- name: Try install old version
|
||||||
@@ -93,7 +99,7 @@ jobs:
|
|||||||
test-version-from-version-file-pyproject:
|
test-version-from-version-file-pyproject:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Use version from pyproject.toml
|
- name: Use version from pyproject.toml
|
||||||
@@ -112,7 +118,7 @@ jobs:
|
|||||||
test-default-version-from-pyproject:
|
test-default-version-from-pyproject:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Use default version from pyproject.toml
|
- name: Use default version from pyproject.toml
|
||||||
@@ -130,7 +136,7 @@ jobs:
|
|||||||
test-default-version-from-pyproject-dev-group:
|
test-default-version-from-pyproject-dev-group:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Use default version from pyproject.toml dev group
|
- name: Use default version from pyproject.toml dev group
|
||||||
@@ -149,7 +155,7 @@ jobs:
|
|||||||
test-default-version-from-pyproject-dependency-groups:
|
test-default-version-from-pyproject-dependency-groups:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Use default version from pyproject.toml dependency groups
|
- name: Use default version from pyproject.toml dependency groups
|
||||||
@@ -168,7 +174,7 @@ jobs:
|
|||||||
test-default-version-from-pyproject-dependency-groups-with-env-marker:
|
test-default-version-from-pyproject-dependency-groups-with-env-marker:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Use default version from pyproject.toml with environment marker
|
- name: Use default version from pyproject.toml with environment marker
|
||||||
@@ -188,7 +194,7 @@ jobs:
|
|||||||
test-default-version-from-pyproject-poetry-groups:
|
test-default-version-from-pyproject-poetry-groups:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Use default version from pyproject.toml poetry group dependencies
|
- name: Use default version from pyproject.toml poetry group dependencies
|
||||||
@@ -207,7 +213,7 @@ jobs:
|
|||||||
test-default-version-from-pyproject-poetry:
|
test-default-version-from-pyproject-poetry:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Use default version from pyproject.toml poetry dependencies
|
- name: Use default version from pyproject.toml poetry dependencies
|
||||||
@@ -226,7 +232,7 @@ jobs:
|
|||||||
test-default-version-from-pyproject-optional-dependencies:
|
test-default-version-from-pyproject-optional-dependencies:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Use default version from pyproject.toml optional dependencies
|
- name: Use default version from pyproject.toml optional dependencies
|
||||||
@@ -245,7 +251,7 @@ jobs:
|
|||||||
test-default-version-from-requirements:
|
test-default-version-from-requirements:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Use default version from requirements.txt
|
- name: Use default version from requirements.txt
|
||||||
@@ -264,7 +270,7 @@ jobs:
|
|||||||
test-default-version-from-requirements-with-hash:
|
test-default-version-from-requirements-with-hash:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Use default version from requirements-with-hash.txt
|
- name: Use default version from requirements-with-hash.txt
|
||||||
@@ -280,10 +286,29 @@ 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-uv-lock:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Use default version from uv.lock
|
||||||
|
id: ruff-action
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
src: __tests__/fixtures/python-project
|
||||||
|
version-file: __tests__/fixtures/uv.lock
|
||||||
|
- name: Correct version gets installed
|
||||||
|
run: |
|
||||||
|
if [ "$RUFF_VERSION" != "0.9.5" ]; 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:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Use version 0.7
|
- name: Use version 0.7
|
||||||
@@ -302,7 +327,7 @@ jobs:
|
|||||||
test-pep440-version-specifier:
|
test-pep440-version-specifier:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Install version 0.9.10
|
- name: Install version 0.9.10
|
||||||
@@ -328,7 +353,9 @@ jobs:
|
|||||||
- os: macos-latest
|
- os: macos-latest
|
||||||
checksum: "af9583bff12afbca5d5670334e0187dd60c4d91bc71317d1b2dde70cb1200ba9"
|
checksum: "af9583bff12afbca5d5670334e0187dd60c4d91bc71317d1b2dde70cb1200ba9"
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- if: runner.os == 'macOS'
|
||||||
|
uses: astral-sh/github-actions/demudhra@7aa50a3def9f5428c532b0ae972d1e5b357de5a5 # 2026.11.03.0
|
||||||
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Checksum matches expected
|
- name: Checksum matches expected
|
||||||
@@ -340,7 +367,7 @@ jobs:
|
|||||||
test-with-explicit-token:
|
test-with-explicit-token:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Use default version
|
- name: Use default version
|
||||||
@@ -354,7 +381,7 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest]
|
os: [ubuntu-latest, windows-latest]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Use args
|
- name: Use args
|
||||||
@@ -365,7 +392,7 @@ jobs:
|
|||||||
test-failure:
|
test-failure:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Format should fail
|
- name: Format should fail
|
||||||
@@ -395,13 +422,41 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
env:
|
env:
|
||||||
CHECK_SHOULD_FAIL_OUTCOME: ${{ steps.check-should-fail.outcome }}
|
CHECK_SHOULD_FAIL_OUTCOME: ${{ steps.check-should-fail.outcome }}
|
||||||
|
test-glob-src:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ ubuntu-latest, windows-latest ]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Use glob pattern in src
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
src: __tests__/fixtures/glob-project/**/*.py
|
||||||
|
|
||||||
|
test-glob-single-star-src:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ ubuntu-latest, windows-latest ]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Use single-star glob pattern in src
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
src: __tests__/fixtures/glob-single-star-project/foo/bar/*.py
|
||||||
|
|
||||||
test-multiple-src:
|
test-multiple-src:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ ubuntu-latest, windows-latest ]
|
os: [ ubuntu-latest, windows-latest ]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Use args
|
- name: Use args
|
||||||
@@ -414,7 +469,7 @@ jobs:
|
|||||||
test-parent-directory-pyproject:
|
test-parent-directory-pyproject:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Use version from parent directory pyproject.toml
|
- name: Use version from parent directory pyproject.toml
|
||||||
@@ -434,7 +489,7 @@ jobs:
|
|||||||
test-custom-manifest-file:
|
test-custom-manifest-file:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Create test src
|
- name: Create test src
|
||||||
@@ -473,12 +528,15 @@ jobs:
|
|||||||
- 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-default-version-from-requirements-with-hash
|
||||||
|
- test-default-version-from-uv-lock
|
||||||
- test-semver-range
|
- test-semver-range
|
||||||
- test-pep440-version-specifier
|
- test-pep440-version-specifier
|
||||||
- test-checksum
|
- test-checksum
|
||||||
- test-with-explicit-token
|
- test-with-explicit-token
|
||||||
- test-args
|
- test-args
|
||||||
- test-failure
|
- test-failure
|
||||||
|
- test-glob-src
|
||||||
|
- test-glob-single-star-src
|
||||||
- test-multiple-src
|
- test-multiple-src
|
||||||
- test-parent-directory-pyproject
|
- test-parent-directory-pyproject
|
||||||
- test-custom-manifest-file
|
- test-custom-manifest-file
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ jobs:
|
|||||||
contents: write
|
contents: write
|
||||||
pull-requests: write
|
pull-requests: write
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
|
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
|
||||||
with:
|
with:
|
||||||
node-version-file: .nvmrc
|
node-version-file: .nvmrc
|
||||||
cache: npm
|
cache: npm
|
||||||
@@ -22,10 +22,13 @@ jobs:
|
|||||||
id: update-known-checksums
|
id: update-known-checksums
|
||||||
run:
|
run:
|
||||||
node dist/update-known-checksums/index.cjs
|
node dist/update-known-checksums/index.cjs
|
||||||
src/download/checksum/known-checksums.ts ${{ secrets.GITHUB_TOKEN }}
|
src/download/checksum/known-checksums.json ${{ secrets.GITHUB_TOKEN }}
|
||||||
- run: npm ci --ignore-scripts && npm run all
|
- run: |
|
||||||
|
npm ci --ignore-scripts
|
||||||
|
npm audit signatures
|
||||||
|
npm run all
|
||||||
- name: Create Pull Request
|
- name: Create Pull Request
|
||||||
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
|
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
|
||||||
with:
|
with:
|
||||||
commit-message: "chore: update known checksums"
|
commit-message: "chore: update known checksums"
|
||||||
title:
|
title:
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ jobs:
|
|||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: true
|
persist-credentials: true
|
||||||
- name: Update Major Minor Tags
|
- name: Update Major Minor Tags
|
||||||
|
|||||||
@@ -32,8 +32,9 @@ anything `ruff` can (ex, fix).
|
|||||||
| `version` | The version of Ruff to install. See [Install specific versions](#install-specific-versions) | discovered from `pyproject.toml`, else `latest` |
|
| `version` | The version of Ruff to install. See [Install specific versions](#install-specific-versions) | discovered from `pyproject.toml`, else `latest` |
|
||||||
| `version-file` | The file to read the version from. See [Install a version from a specified version file](#install-a-version-from-a-specified-version-file) | None |
|
| `version-file` | The file to read the version from. See [Install a version from a specified version file](#install-a-version-from-a-specified-version-file) | None |
|
||||||
| `manifest-file` | URL to a custom Ruff manifest in the `astral-sh/versions` format. | None |
|
| `manifest-file` | URL to a custom Ruff manifest in the `astral-sh/versions` format. | None |
|
||||||
|
| `download-from-astral-mirror` | Download Ruff from the Astral mirror instead of directly from GitHub Releases. | `true` |
|
||||||
| `args` | The arguments to pass to the `ruff` command. See [Configuring Ruff] | `check` |
|
| `args` | The arguments to pass to the `ruff` command. See [Configuring Ruff] | `check` |
|
||||||
| `src` | The directory or single files to run `ruff` on. | [github.workspace] |
|
| `src` | Source path(s) to run `ruff` on. Supports glob patterns. | [github.workspace] |
|
||||||
| `checksum` | The sha256 checksum of the downloaded artifact. | None |
|
| `checksum` | The sha256 checksum of the downloaded artifact. | None |
|
||||||
| `github-token` | The GitHub token to use when downloading Ruff release artifacts from GitHub. | `GITHUB_TOKEN` |
|
| `github-token` | The GitHub token to use when downloading Ruff release artifacts from GitHub. | `GITHUB_TOKEN` |
|
||||||
|
|
||||||
@@ -43,33 +44,60 @@ By default, Ruff version metadata is resolved from the
|
|||||||
### Basic
|
### Basic
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: astral-sh/ruff-action@v3
|
- uses: astral-sh/ruff-action@v4.1.0
|
||||||
```
|
```
|
||||||
|
|
||||||
### Specify a different source directory
|
### Specify a different source directory
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: astral-sh/ruff-action@v3
|
- uses: astral-sh/ruff-action@v4.1.0
|
||||||
with:
|
with:
|
||||||
src: "./src"
|
src: "./src"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Specify multiple files
|
### Specify multiple files
|
||||||
|
|
||||||
|
Separate multiple `src` values with whitespace.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: astral-sh/ruff-action@v3
|
- uses: astral-sh/ruff-action@v4.1.0
|
||||||
with:
|
with:
|
||||||
src: >-
|
src: >-
|
||||||
path/to/file1.py
|
path/to/file1.py
|
||||||
path/to/file2.py
|
path/to/file2.py
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Use glob patterns
|
||||||
|
|
||||||
|
Glob patterns (`*`, `?`, `[...]`, and `**`) are expanded by the action using
|
||||||
|
[`@actions/glob`](https://github.com/actions/toolkit/tree/main/packages/glob),
|
||||||
|
so they work consistently across Linux, macOS, and Windows runners. This action
|
||||||
|
does not emulate Bash, PowerShell, or other shell-specific glob expansion.
|
||||||
|
|
||||||
|
Hidden files and directories are skipped by default; target them explicitly, for
|
||||||
|
example with `.venv/**/*.py`, to include them. If a pattern does not match any
|
||||||
|
files, the original pattern is passed to Ruff so Ruff can report the missing
|
||||||
|
path. Literal glob metacharacters in file or directory names must be escaped
|
||||||
|
using `@actions/glob` syntax.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: astral-sh/ruff-action@v4.1.0
|
||||||
|
with:
|
||||||
|
src: "src/**/*.py"
|
||||||
|
```
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> When using multiple patterns, only the first is used to search for
|
||||||
|
> `pyproject.toml` to determine the Ruff version. Use the `version` input
|
||||||
|
> for explicit control. Large glob expansions may hit command-line length limits,
|
||||||
|
> especially on Windows.
|
||||||
|
|
||||||
### Use to install ruff
|
### Use to install ruff
|
||||||
|
|
||||||
This action adds ruff to the PATH, so you can use it in subsequent steps.
|
This action adds ruff to the PATH, so you can use it in subsequent steps.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: astral-sh/ruff-action@v3
|
- uses: astral-sh/ruff-action@v4.1.0
|
||||||
- run: ruff check --fix
|
- run: ruff check --fix
|
||||||
- run: ruff format
|
- run: ruff format
|
||||||
```
|
```
|
||||||
@@ -80,7 +108,7 @@ you can use the `args` input to overwrite the default value (`check`):
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Install ruff without running check or format
|
- name: Install ruff without running check or format
|
||||||
uses: astral-sh/ruff-action@v3
|
uses: astral-sh/ruff-action@v4.1.0
|
||||||
with:
|
with:
|
||||||
args: "--version"
|
args: "--version"
|
||||||
```
|
```
|
||||||
@@ -88,7 +116,7 @@ you can use the `args` input to overwrite the default value (`check`):
|
|||||||
### Use `ruff format`
|
### Use `ruff format`
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: astral-sh/ruff-action@v3
|
- uses: astral-sh/ruff-action@v4.1.0
|
||||||
with:
|
with:
|
||||||
args: "format --check --diff"
|
args: "format --check --diff"
|
||||||
```
|
```
|
||||||
@@ -107,7 +135,7 @@ or no Ruff version is defined in `project.dependencies`, `project.optional-depen
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Install the latest version of ruff
|
- name: Install the latest version of ruff
|
||||||
uses: astral-sh/ruff-action@v3
|
uses: astral-sh/ruff-action@v4.1.0
|
||||||
with:
|
with:
|
||||||
version: "latest"
|
version: "latest"
|
||||||
```
|
```
|
||||||
@@ -116,7 +144,7 @@ or no Ruff version is defined in `project.dependencies`, `project.optional-depen
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Install a specific version of ruff
|
- name: Install a specific version of ruff
|
||||||
uses: astral-sh/ruff-action@v3
|
uses: astral-sh/ruff-action@v4.1.0
|
||||||
with:
|
with:
|
||||||
version: "0.4.4"
|
version: "0.4.4"
|
||||||
```
|
```
|
||||||
@@ -129,21 +157,21 @@ to install the latest version that satisfies the range.
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Install a semver range of ruff
|
- name: Install a semver range of ruff
|
||||||
uses: astral-sh/ruff-action@v3
|
uses: astral-sh/ruff-action@v4.1.0
|
||||||
with:
|
with:
|
||||||
version: ">=0.4.0"
|
version: ">=0.4.0"
|
||||||
```
|
```
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Pinning a minor version of ruff
|
- name: Pinning a minor version of ruff
|
||||||
uses: astral-sh/ruff-action@v3
|
uses: astral-sh/ruff-action@v4.1.0
|
||||||
with:
|
with:
|
||||||
version: "0.4.x"
|
version: "0.4.x"
|
||||||
```
|
```
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Install a pep440-specifier-satisfying version of ruff
|
- name: Install a pep440-specifier-satisfying version of ruff
|
||||||
uses: astral-sh/ruff-action@v3
|
uses: astral-sh/ruff-action@v4.1.0
|
||||||
with:
|
with:
|
||||||
version: ">=0.11.10,<0.12.0"
|
version: ">=0.11.10,<0.12.0"
|
||||||
```
|
```
|
||||||
@@ -151,14 +179,14 @@ to install the latest version that satisfies the range.
|
|||||||
#### Install a version from a specified version file
|
#### Install a version from a specified version file
|
||||||
|
|
||||||
You can specify a file to read the version from.
|
You can specify a file to read the version from.
|
||||||
Currently `pyproject.toml` and `requirements.txt` are supported. If the file cannot be parsed
|
Currently `pyproject.toml`, `requirements.txt` and `uv.lock` are supported. If the file cannot
|
||||||
or does not contain a Ruff version, the action warns and falls back to `latest`.
|
be parsed or does not contain a Ruff version, the action warns and falls back to `latest`.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Install a version from a specified version file
|
- name: Install a version from a specified version file
|
||||||
uses: astral-sh/ruff-action@v3
|
uses: astral-sh/ruff-action@v4.1.0
|
||||||
with:
|
with:
|
||||||
version-file: "my-path/to/pyproject.toml-or-requirements.txt"
|
version-file: "my-path/to/pyproject.toml-requirements.txt-or-uv.lock"
|
||||||
```
|
```
|
||||||
|
|
||||||
Version resolution precedence is:
|
Version resolution precedence is:
|
||||||
@@ -175,7 +203,7 @@ This affects both version resolution and artifact selection.
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Install Ruff from a custom manifest
|
- name: Install Ruff from a custom manifest
|
||||||
uses: astral-sh/ruff-action@v3
|
uses: astral-sh/ruff-action@v4.1.0
|
||||||
with:
|
with:
|
||||||
version: "latest"
|
version: "latest"
|
||||||
manifest-file: "https://example.com/ruff.ndjson"
|
manifest-file: "https://example.com/ruff.ndjson"
|
||||||
@@ -189,7 +217,7 @@ are automatically verified by this action. The sha256 hashes can be found on the
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Install a specific version and validate the checksum
|
- name: Install a specific version and validate the checksum
|
||||||
uses: astral-sh/ruff-action@v3
|
uses: astral-sh/ruff-action@v4.1.0
|
||||||
with:
|
with:
|
||||||
version: "0.7.4"
|
version: "0.7.4"
|
||||||
checksum: "0de731c669b9ece77e799ac3f4a160c30849752714d9775c94cc4cfaf326860c"
|
checksum: "0de731c669b9ece77e799ac3f4a160c30849752714d9775c94cc4cfaf326860c"
|
||||||
@@ -197,10 +225,12 @@ are automatically verified by this action. The sha256 hashes can be found on the
|
|||||||
|
|
||||||
### GitHub authentication token
|
### GitHub authentication token
|
||||||
|
|
||||||
By default, this action resolves available uv versions from
|
By default, this action resolves available Ruff versions from
|
||||||
[`astral-sh/versions`](https://github.com/astral-sh/versions) and downloads release artifacts from `https://releases.astral.sh`. If this fails this action falls back to downloading from the GitHub releases page of the ruff repository.
|
[`astral-sh/versions`](https://github.com/astral-sh/versions) and downloads release artifacts from `https://releases.astral.sh`. If this fails this action falls back to downloading from the GitHub releases page of the Ruff repository.
|
||||||
|
|
||||||
You can provide a token via `github-token` to authenticate those downloads. By default, the
|
Set `download-from-astral-mirror` to `false` to skip the Astral mirror and download directly from GitHub Releases.
|
||||||
|
|
||||||
|
You can provide a token via `github-token` to authenticate GitHub Releases downloads. By default, the
|
||||||
`GITHUB_TOKEN` secret is used, which is automatically provided by GitHub Actions.
|
`GITHUB_TOKEN` secret is used, which is automatically provided by GitHub Actions.
|
||||||
|
|
||||||
If the default
|
If the default
|
||||||
@@ -209,7 +239,7 @@ are not sufficient, you can provide a custom GitHub token with the necessary per
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Install the latest version of ruff with a custom GitHub token
|
- name: Install the latest version of ruff with a custom GitHub token
|
||||||
uses: astral-sh/ruff-action@v3
|
uses: astral-sh/ruff-action@v4.1.0
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
|
github-token: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { promises as fs } from "node:fs";
|
||||||
|
import os from "node:os";
|
||||||
|
import path from "node:path";
|
||||||
|
import { expect, jest, test } from "@jest/globals";
|
||||||
|
|
||||||
|
const mockDownloadTool = jest.fn<() => Promise<string>>();
|
||||||
|
|
||||||
|
jest.unstable_mockModule("@actions/tool-cache", () => ({
|
||||||
|
downloadTool: mockDownloadTool,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const { updateChecksums } = await import(
|
||||||
|
"../../../src/download/checksum/update-known-checksums"
|
||||||
|
);
|
||||||
|
|
||||||
|
test("serializes checksum entries as JSON data", async () => {
|
||||||
|
const tempDirectory = await fs.mkdtemp(
|
||||||
|
path.join(os.tmpdir(), "ruff-action-checksums-test-"),
|
||||||
|
);
|
||||||
|
const checksumPath = path.join(tempDirectory, "checksum");
|
||||||
|
const outputPath = path.join(tempDirectory, "known-checksums.json");
|
||||||
|
const checksum = 'checksum"\\value';
|
||||||
|
const platform = 'platform"\n};\ncompromised = true;';
|
||||||
|
const downloadUrl = `https://example.com/v1.0.0/ruff-1.0.0-${platform}.tar.gz.sha256`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await fs.writeFile(checksumPath, `${checksum} ruff.tar.gz`);
|
||||||
|
mockDownloadTool.mockResolvedValue(checksumPath);
|
||||||
|
|
||||||
|
await updateChecksums(outputPath, [downloadUrl]);
|
||||||
|
|
||||||
|
const content = await fs.readFile(outputPath, "utf8");
|
||||||
|
expect(JSON.parse(content)).toEqual({ [`${platform}-1.0.0`]: checksum });
|
||||||
|
expect(content.endsWith("\n")).toBe(true);
|
||||||
|
} finally {
|
||||||
|
await fs.rm(tempDirectory, { force: true, recursive: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import * as path from "node:path";
|
||||||
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
|
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
|
||||||
import * as semver from "semver";
|
import * as semver from "semver";
|
||||||
|
|
||||||
@@ -357,6 +358,32 @@ describe("download-version", () => {
|
|||||||
expect(mockDownloadTool).toHaveBeenCalledTimes(1);
|
expect(mockDownloadTool).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("skips the Astral mirror when downloadFromAstralMirror is false", async () => {
|
||||||
|
mockGetArtifact.mockResolvedValue({
|
||||||
|
archiveFormat: "tar.gz",
|
||||||
|
checksum: "abc123",
|
||||||
|
downloadUrl:
|
||||||
|
"https://github.com/astral-sh/ruff/releases/download/0.15.8/ruff-x86_64-unknown-linux-gnu.tar.gz",
|
||||||
|
});
|
||||||
|
|
||||||
|
await downloadVersion(
|
||||||
|
"unknown-linux-gnu",
|
||||||
|
"x86_64",
|
||||||
|
"0.15.8",
|
||||||
|
undefined,
|
||||||
|
"token",
|
||||||
|
undefined,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(mockDownloadTool).toHaveBeenCalledWith(
|
||||||
|
"https://github.com/astral-sh/ruff/releases/download/0.15.8/ruff-x86_64-unknown-linux-gnu.tar.gz",
|
||||||
|
undefined,
|
||||||
|
"token",
|
||||||
|
);
|
||||||
|
expect(mockDownloadTool).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
it("uses manifest-file checksum metadata when checksum input is unset", async () => {
|
it("uses manifest-file checksum metadata when checksum input is unset", async () => {
|
||||||
mockGetArtifact.mockResolvedValue({
|
mockGetArtifact.mockResolvedValue({
|
||||||
archiveFormat: "tar.gz",
|
archiveFormat: "tar.gz",
|
||||||
@@ -424,7 +451,7 @@ describe("download-version", () => {
|
|||||||
|
|
||||||
expect(mockExtractTar).toHaveBeenCalledWith("/tmp/downloaded");
|
expect(mockExtractTar).toHaveBeenCalledWith("/tmp/downloaded");
|
||||||
expect(mockCacheDir).toHaveBeenCalledWith(
|
expect(mockCacheDir).toHaveBeenCalledWith(
|
||||||
"/tmp/extracted/ruff-x86_64-unknown-linux-gnu",
|
path.join("/tmp/extracted", "ruff-x86_64-unknown-linux-gnu"),
|
||||||
"ruff",
|
"ruff",
|
||||||
"0.15.8",
|
"0.15.8",
|
||||||
"x86_64",
|
"x86_64",
|
||||||
|
|||||||
@@ -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.6.2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["hatchling"]
|
||||||
|
build-backend = "hatchling.build"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
print("hello")
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
print("deeper")
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
print("check me")
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# This file should be ignored when using foo/bar/*.py glob
|
||||||
|
print("ignore me")
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
[project]
|
||||||
|
name = "glob-single-star-project"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Add your description here"
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.12"
|
||||||
|
dependencies = [
|
||||||
|
"ruff==0.6.2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["hatchling"]
|
||||||
|
build-backend = "hatchling.build"
|
||||||
Generated
+20
@@ -0,0 +1,20 @@
|
|||||||
|
version = 1
|
||||||
|
revision = 1
|
||||||
|
requires-python = ">=3.11"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "example-project"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = { editable = "." }
|
||||||
|
dependencies = [
|
||||||
|
{ name = "ruff" },
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.metadata]
|
||||||
|
requires-dist = [{ name = "ruff", specifier = ">=0.9.0" }]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ruff"
|
||||||
|
version = "0.9.5"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/source/r/ruff/ruff-0.9.5.tar.gz", hash = "sha256:11aecd7a633932875ab3cb05a484c99970b9d52606ce9ea912b690b02653d56c", size = 3634177 }
|
||||||
@@ -0,0 +1,375 @@
|
|||||||
|
import * as fs from "node:fs/promises";
|
||||||
|
import * as os from "node:os";
|
||||||
|
import * as path from "node:path";
|
||||||
|
import { afterEach, describe, expect, it, jest } from "@jest/globals";
|
||||||
|
|
||||||
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
|
debug: jest.fn(),
|
||||||
|
info: jest.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const {
|
||||||
|
expandSourceInput,
|
||||||
|
getSourceBasePath,
|
||||||
|
getVersionSourceDirectory,
|
||||||
|
splitInput,
|
||||||
|
} = await import("../../src/utils/source-input");
|
||||||
|
const { findPyprojectToml } = await import("../../src/utils/pyproject-finder");
|
||||||
|
|
||||||
|
let tempDir: string | undefined;
|
||||||
|
const symlinkTest = process.platform === "win32" ? it.skip : it;
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
if (tempDir !== undefined) {
|
||||||
|
await fs.rm(tempDir, { force: true, recursive: true });
|
||||||
|
tempDir = undefined;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
async function createTempProject(): Promise<string> {
|
||||||
|
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "ruff-action-source-"));
|
||||||
|
await fs.mkdir(path.join(tempDir, "src", "package", "nested"), {
|
||||||
|
recursive: true,
|
||||||
|
});
|
||||||
|
await fs.writeFile(path.join(tempDir, "src", "package", "__init__.py"), "");
|
||||||
|
await fs.writeFile(path.join(tempDir, "src", "package", "main.py"), "");
|
||||||
|
await fs.writeFile(
|
||||||
|
path.join(tempDir, "src", "package", "nested", "mod.py"),
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
await fs.writeFile(path.join(tempDir, "src", "package", "notes.txt"), "");
|
||||||
|
await fs.mkdir(path.join(tempDir, "src", "pkg[legacy]"), {
|
||||||
|
recursive: true,
|
||||||
|
});
|
||||||
|
await fs.writeFile(path.join(tempDir, "src", "pkg[legacy]", "main.py"), "");
|
||||||
|
await fs.mkdir(path.join(tempDir, "src", "pkgl"), { recursive: true });
|
||||||
|
await fs.writeFile(path.join(tempDir, "src", "pkgl", "main.py"), "");
|
||||||
|
|
||||||
|
return tempDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("splitInput", () => {
|
||||||
|
it("splits whitespace-delimited inputs", () => {
|
||||||
|
expect(splitInput(" check --fix\n--diff ")).toEqual([
|
||||||
|
"check",
|
||||||
|
"--fix",
|
||||||
|
"--diff",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns an empty array for empty input", () => {
|
||||||
|
expect(splitInput(" \n\t ")).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("expandSourceInput", () => {
|
||||||
|
it("leaves non-glob sources unchanged", async () => {
|
||||||
|
await expect(expandSourceInput("src file.py")).resolves.toEqual([
|
||||||
|
"src",
|
||||||
|
"file.py",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("expands recursive globs without relying on shell behavior", async () => {
|
||||||
|
const projectDir = await createTempProject();
|
||||||
|
const pattern = path.join(projectDir, "src", "**", "*.py");
|
||||||
|
|
||||||
|
await expect(expandSourceInput(pattern)).resolves.toEqual([
|
||||||
|
path.join(projectDir, "src", "package", "__init__.py"),
|
||||||
|
path.join(projectDir, "src", "package", "main.py"),
|
||||||
|
path.join(projectDir, "src", "package", "nested", "mod.py"),
|
||||||
|
path.join(projectDir, "src", "pkg[legacy]", "main.py"),
|
||||||
|
path.join(projectDir, "src", "pkgl", "main.py"),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("preserves relative source patterns as relative paths", async () => {
|
||||||
|
const projectDir = await createTempProject();
|
||||||
|
const originalCwd = process.cwd();
|
||||||
|
|
||||||
|
try {
|
||||||
|
process.chdir(projectDir);
|
||||||
|
await expect(expandSourceInput("src/**/*.py")).resolves.toEqual([
|
||||||
|
path.join("src", "package", "__init__.py"),
|
||||||
|
path.join("src", "package", "main.py"),
|
||||||
|
path.join("src", "package", "nested", "mod.py"),
|
||||||
|
path.join("src", "pkg[legacy]", "main.py"),
|
||||||
|
path.join("src", "pkgl", "main.py"),
|
||||||
|
]);
|
||||||
|
} finally {
|
||||||
|
process.chdir(originalCwd);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("maps relative root glob matches to . instead of an empty argument", async () => {
|
||||||
|
const projectDir = await createTempProject();
|
||||||
|
const originalCwd = process.cwd();
|
||||||
|
|
||||||
|
try {
|
||||||
|
process.chdir(projectDir);
|
||||||
|
for (const pattern of ["**", "**/", "./**"]) {
|
||||||
|
const sources = await expandSourceInput(pattern);
|
||||||
|
|
||||||
|
expect(sources).toContain(".");
|
||||||
|
expect(sources).not.toContain("");
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
process.chdir(originalCwd);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("excludes hidden paths by default while allowing explicit hidden patterns", async () => {
|
||||||
|
const projectDir = await createTempProject();
|
||||||
|
const originalCwd = process.cwd();
|
||||||
|
await fs.mkdir(path.join(projectDir, ".venv"));
|
||||||
|
await fs.writeFile(path.join(projectDir, ".venv", "ignored.py"), "");
|
||||||
|
await fs.mkdir(path.join(projectDir, ".tox"));
|
||||||
|
await fs.writeFile(path.join(projectDir, ".tox", "ignored.py"), "");
|
||||||
|
|
||||||
|
try {
|
||||||
|
process.chdir(projectDir);
|
||||||
|
const defaultSources = await expandSourceInput("**/*.py");
|
||||||
|
|
||||||
|
expect(defaultSources).not.toContain(path.join(".venv", "ignored.py"));
|
||||||
|
expect(defaultSources).not.toContain(path.join(".tox", "ignored.py"));
|
||||||
|
await expect(expandSourceInput(".venv/**/*.py")).resolves.toEqual([
|
||||||
|
path.join(".venv", "ignored.py"),
|
||||||
|
]);
|
||||||
|
} finally {
|
||||||
|
process.chdir(originalCwd);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("preserves unmatched globs for Ruff to report", async () => {
|
||||||
|
const projectDir = await createTempProject();
|
||||||
|
const pattern = path.join(projectDir, "src", "**", "missing-*.py");
|
||||||
|
|
||||||
|
await expect(expandSourceInput(pattern)).resolves.toEqual([pattern]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("expands multiple sources in input order", async () => {
|
||||||
|
const projectDir = await createTempProject();
|
||||||
|
const first = path.join(projectDir, "src", "package", "main.py");
|
||||||
|
const second = path.join(projectDir, "src", "package", "nested", "*.py");
|
||||||
|
|
||||||
|
await expect(expandSourceInput(`${first} ${second}`)).resolves.toEqual([
|
||||||
|
first,
|
||||||
|
path.join(projectDir, "src", "package", "nested", "mod.py"),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses @actions/glob syntax for paths that contain glob metacharacters", async () => {
|
||||||
|
const projectDir = await createTempProject();
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
expandSourceInput(path.join(projectDir, "src", "pkg[legacy]")),
|
||||||
|
).resolves.toEqual([path.join(projectDir, "src", "pkgl")]);
|
||||||
|
await expect(
|
||||||
|
expandSourceInput(path.join(projectDir, "src", "pkg[legacy]", "*.py")),
|
||||||
|
).resolves.toEqual([path.join(projectDir, "src", "pkgl", "main.py")]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("supports @actions/glob escaping for literal glob metacharacters", async () => {
|
||||||
|
const projectDir = await createTempProject();
|
||||||
|
const pattern = path.join(projectDir, "src", "pkg[[]legacy]", "*.py");
|
||||||
|
|
||||||
|
await expect(expandSourceInput(pattern)).resolves.toEqual([
|
||||||
|
path.join(projectDir, "src", "pkg[legacy]", "main.py"),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
symlinkTest("does not traverse symlinked directories", async () => {
|
||||||
|
const projectDir = await createTempProject();
|
||||||
|
const externalDir = path.join(projectDir, "external");
|
||||||
|
const symlinkPath = path.join(projectDir, "src", "linked");
|
||||||
|
await fs.mkdir(externalDir);
|
||||||
|
await fs.writeFile(path.join(externalDir, "external.py"), "");
|
||||||
|
await fs.symlink(externalDir, symlinkPath, "dir");
|
||||||
|
|
||||||
|
const sources = await expandSourceInput(
|
||||||
|
path.join(projectDir, "src", "**", "*.py"),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(sources).not.toContain(path.join(symlinkPath, "external.py"));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("still expands missing paths that contain glob metacharacters", async () => {
|
||||||
|
const projectDir = await createTempProject();
|
||||||
|
const pattern = path.join(projectDir, "src", "pkg[l]");
|
||||||
|
|
||||||
|
await expect(expandSourceInput(pattern)).resolves.toEqual([
|
||||||
|
path.join(projectDir, "src", "pkgl"),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("getVersionSourceDirectory", () => {
|
||||||
|
it("does not scan src globs when version input is explicit", async () => {
|
||||||
|
await expect(
|
||||||
|
getVersionSourceDirectory("../**/*.py", "0.1.0", undefined),
|
||||||
|
).resolves.toBe(".");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not scan src globs when version-file input is explicit", async () => {
|
||||||
|
await expect(
|
||||||
|
getVersionSourceDirectory("../**/*.py", undefined, "pyproject.toml"),
|
||||||
|
).resolves.toBe(".");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses source discovery when no version input is explicit", async () => {
|
||||||
|
await expect(
|
||||||
|
getVersionSourceDirectory("../**/*.py", undefined, undefined),
|
||||||
|
).rejects.toThrow("Invalid pattern '../**/*.py'");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("getSourceBasePath", () => {
|
||||||
|
it("returns the directory for a plain path", async () => {
|
||||||
|
await expect(getSourceBasePath("my-project")).resolves.toBe("my-project");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns the directory for a dotted path", async () => {
|
||||||
|
await expect(getSourceBasePath("./src")).resolves.toBe("./src");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("preserves filesystem root paths", async () => {
|
||||||
|
const root = path.parse(process.cwd()).root;
|
||||||
|
|
||||||
|
await expect(getSourceBasePath(root)).resolves.toBe(root);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("strips glob pattern and returns parent directory", async () => {
|
||||||
|
await expect(getSourceBasePath("src/**/*.py")).resolves.toBe("src");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns . for a top-level glob", async () => {
|
||||||
|
await expect(getSourceBasePath("*.py")).resolves.toBe(".");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns . for empty string", async () => {
|
||||||
|
await expect(getSourceBasePath("")).resolves.toBe(".");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses only the first whitespace-delimited token", async () => {
|
||||||
|
await expect(getSourceBasePath("sub1/*.py sub2/")).resolves.toBe("sub1");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("handles trailing slash in prefix", async () => {
|
||||||
|
await expect(getSourceBasePath("sub/*.py")).resolves.toBe("sub");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses the parent directory when a glob appears in a filename", async () => {
|
||||||
|
await expect(getSourceBasePath("src/file*.py")).resolves.toBe("src");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("handles ? glob", async () => {
|
||||||
|
await expect(getSourceBasePath("file?.py")).resolves.toBe(".");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("handles bracket glob", async () => {
|
||||||
|
await expect(getSourceBasePath("file[0-9].py")).resolves.toBe(".");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses @actions/glob syntax for base paths with glob metacharacters", async () => {
|
||||||
|
const projectDir = await createTempProject();
|
||||||
|
const originalCwd = process.cwd();
|
||||||
|
|
||||||
|
try {
|
||||||
|
process.chdir(projectDir);
|
||||||
|
await expect(getSourceBasePath("src/pkg[legacy]")).resolves.toBe(
|
||||||
|
path.join("src", "pkgl"),
|
||||||
|
);
|
||||||
|
await expect(getSourceBasePath("src/pkg[legacy]/*.py")).resolves.toBe(
|
||||||
|
path.join("src", "pkgl", "main.py"),
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
process.chdir(originalCwd);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("supports @actions/glob escaping for version discovery from literal glob metacharacters", async () => {
|
||||||
|
const projectDir = await createTempProject();
|
||||||
|
const originalCwd = process.cwd();
|
||||||
|
const pyprojectPath = path.join(
|
||||||
|
projectDir,
|
||||||
|
"src",
|
||||||
|
"pkg[legacy]",
|
||||||
|
"pyproject.toml",
|
||||||
|
);
|
||||||
|
await fs.writeFile(
|
||||||
|
pyprojectPath,
|
||||||
|
"[project]\ndependencies = ['ruff==0.6.2']\n",
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
process.chdir(projectDir);
|
||||||
|
const sourceBasePath = await getSourceBasePath(
|
||||||
|
"src/pkg[[]legacy]/main.py",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(findPyprojectToml(sourceBasePath, projectDir)).toBe(
|
||||||
|
await fs.realpath(pyprojectPath),
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
process.chdir(originalCwd);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses the first expanded glob match for version discovery", async () => {
|
||||||
|
const projectDir = await createTempProject();
|
||||||
|
const originalCwd = process.cwd();
|
||||||
|
const pyprojectPath = path.join(
|
||||||
|
projectDir,
|
||||||
|
"packages",
|
||||||
|
"foo",
|
||||||
|
"pyproject.toml",
|
||||||
|
);
|
||||||
|
await fs.mkdir(path.join(projectDir, "packages", "foo", "src"), {
|
||||||
|
recursive: true,
|
||||||
|
});
|
||||||
|
await fs.writeFile(
|
||||||
|
pyprojectPath,
|
||||||
|
"[project]\ndependencies = ['ruff==0.10.0']\n",
|
||||||
|
);
|
||||||
|
await fs.writeFile(
|
||||||
|
path.join(projectDir, "packages", "foo", "src", "module.py"),
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
process.chdir(projectDir);
|
||||||
|
const sourceBasePath = await getSourceBasePath("packages/*/src/**/*.py");
|
||||||
|
|
||||||
|
expect(sourceBasePath).toBe(
|
||||||
|
path.join("packages", "foo", "src", "module.py"),
|
||||||
|
);
|
||||||
|
const workspaceRoot = await fs.realpath(projectDir);
|
||||||
|
expect(findPyprojectToml(sourceBasePath, workspaceRoot)).toBe(
|
||||||
|
await fs.realpath(pyprojectPath),
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
process.chdir(originalCwd);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses the unmatched glob fallback when version-discovery glob has no matches", async () => {
|
||||||
|
const projectDir = await createTempProject();
|
||||||
|
const originalCwd = process.cwd();
|
||||||
|
await fs.mkdir(path.join(projectDir, "packages"));
|
||||||
|
|
||||||
|
try {
|
||||||
|
process.chdir(projectDir);
|
||||||
|
await expect(getSourceBasePath("packages/*/src/**/*.py")).resolves.toBe(
|
||||||
|
"packages",
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
process.chdir(originalCwd);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not treat brace expansion as glob syntax", async () => {
|
||||||
|
await expect(getSourceBasePath("src/{a,b}/*.py")).resolves.toBe(
|
||||||
|
path.join("src", "{a,b}"),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -9,9 +9,11 @@ jest.unstable_mockModule("@actions/core", () => ({
|
|||||||
warning,
|
warning,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const { findRuffVersionInSpec, getRuffVersionFromFile } = await import(
|
const {
|
||||||
"../../src/version/file-parser"
|
findRuffVersionInSpec,
|
||||||
);
|
getRuffVersionFromFile,
|
||||||
|
getRuffVersionFromUvLockContent,
|
||||||
|
} = await import("../../src/version/file-parser");
|
||||||
|
|
||||||
describe("file-parser", () => {
|
describe("file-parser", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -124,5 +126,26 @@ describe("file-parser", () => {
|
|||||||
);
|
);
|
||||||
expect(result).toBe("~0.8.2");
|
expect(result).toBe("~0.8.2");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("reads the version from uv.lock", () => {
|
||||||
|
const result = getRuffVersionFromFile("__tests__/fixtures/uv.lock");
|
||||||
|
expect(result).toBe("0.9.5");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("getRuffVersionFromUvLockContent", () => {
|
||||||
|
it("extracts the ruff version from uv.lock content", () => {
|
||||||
|
const result = getRuffVersionFromUvLockContent(
|
||||||
|
'[[package]]\nname = "other"\nversion = "1.0.0"\n\n[[package]]\nname = "ruff"\nversion = "0.9.5"\n',
|
||||||
|
);
|
||||||
|
expect(result).toBe("0.9.5");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns undefined when ruff is not in uv.lock", () => {
|
||||||
|
const result = getRuffVersionFromUvLockContent(
|
||||||
|
'[[package]]\nname = "other"\nversion = "1.0.0"\n',
|
||||||
|
);
|
||||||
|
expect(result).toBeUndefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+6
-2
@@ -7,7 +7,7 @@ inputs:
|
|||||||
required: false
|
required: false
|
||||||
default: "check"
|
default: "check"
|
||||||
src:
|
src:
|
||||||
description: "Source to run Ruff. Defaults to the current directory."
|
description: "Source path(s) or @actions/glob pattern(s) to run Ruff on. Defaults to the current workspace."
|
||||||
required: false
|
required: false
|
||||||
default: ${{ github.workspace }}
|
default: ${{ github.workspace }}
|
||||||
version:
|
version:
|
||||||
@@ -15,7 +15,7 @@ inputs:
|
|||||||
required: false
|
required: false
|
||||||
default: ""
|
default: ""
|
||||||
version-file:
|
version-file:
|
||||||
description: "Path to a pyproject.toml or requirements.txt file to read the version from. If parsing fails, the action warns and falls back to `latest`."
|
description: "Path to a pyproject.toml, requirements.txt or uv.lock file to read the version from. If parsing fails, the action warns and falls back to `latest`."
|
||||||
required: false
|
required: false
|
||||||
checksum:
|
checksum:
|
||||||
description: "The checksum of the ruff version to install"
|
description: "The checksum of the ruff version to install"
|
||||||
@@ -23,6 +23,10 @@ inputs:
|
|||||||
manifest-file:
|
manifest-file:
|
||||||
description: "URL to a custom manifest file in the astral-sh/versions format."
|
description: "URL to a custom manifest file in the astral-sh/versions format."
|
||||||
required: false
|
required: false
|
||||||
|
download-from-astral-mirror:
|
||||||
|
description: "Download Ruff from the Astral mirror instead of directly from GitHub Releases."
|
||||||
|
required: false
|
||||||
|
default: "true"
|
||||||
github-token:
|
github-token:
|
||||||
description:
|
description:
|
||||||
"Used for authenticated downloads of Ruff release artifacts from GitHub."
|
"Used for authenticated downloads of Ruff release artifacts from GitHub."
|
||||||
|
|||||||
BIN
Binary file not shown.
BIN
Binary file not shown.
Generated
+461
-300
File diff suppressed because it is too large
Load Diff
+17
-6
@@ -5,12 +5,22 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "A GitHub Action to run Ruff, an extremely fast Python linter and code formatter.",
|
"description": "A GitHub Action to run Ruff, an extremely fast Python linter and code formatter.",
|
||||||
"main": "dist/ruff-action/index.cjs",
|
"main": "dist/ruff-action/index.cjs",
|
||||||
|
"engines": {
|
||||||
|
"npm": ">=11.10.0"
|
||||||
|
},
|
||||||
|
"devEngines": {
|
||||||
|
"packageManager": {
|
||||||
|
"name": "npm",
|
||||||
|
"version": ">=11.10.0",
|
||||||
|
"onFail": "error"
|
||||||
|
}
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc --noEmit",
|
"build": "tsc --noEmit",
|
||||||
"check": "biome check --write",
|
"check": "biome check --write",
|
||||||
"package": "node scripts/build-dist.mjs",
|
"package": "node scripts/build-dist.mjs",
|
||||||
"act": "act pull_request -W .github/workflows/test.yml --container-architecture linux/amd64 -s GITHUB_TOKEN=\"$(gh auth token)\"",
|
"act": "act pull_request -W .github/workflows/test.yml --container-architecture linux/amd64 -s GITHUB_TOKEN=\"$(gh auth token)\"",
|
||||||
"update-known-checksums": "RUNNER_TEMP=known_checksums node dist/update-known-checksums/index.cjs src/download/checksum/known-checksums.ts \"$(gh auth token)\"",
|
"update-known-checksums": "RUNNER_TEMP=known_checksums node dist/update-known-checksums/index.cjs src/download/checksum/known-checksums.json \"$(gh auth token)\"",
|
||||||
"test:unit": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js",
|
"test:unit": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js",
|
||||||
"test": "npm run build && npm run test:unit",
|
"test": "npm run build && npm run test:unit",
|
||||||
"all": "npm run build && npm run check && npm run package && npm run test:unit"
|
"all": "npm run build && npm run check && npm run package && npm run test:unit"
|
||||||
@@ -28,12 +38,13 @@
|
|||||||
"author": "@eifinger",
|
"author": "@eifinger",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^3.0.0",
|
"@actions/core": "^3.0.1",
|
||||||
"@actions/exec": "^3.0.0",
|
"@actions/exec": "^3.0.0",
|
||||||
|
"@actions/glob": "^0.7.0",
|
||||||
"@actions/tool-cache": "^4.0.0",
|
"@actions/tool-cache": "^4.0.0",
|
||||||
"@octokit/core": "^7.0.3",
|
"@octokit/core": "^7.0.6",
|
||||||
"@octokit/plugin-paginate-rest": "^13.1.1",
|
"@octokit/plugin-paginate-rest": "^13.1.1",
|
||||||
"@octokit/plugin-rest-endpoint-methods": "^16.0.0",
|
"@octokit/plugin-rest-endpoint-methods": "^17.0.0",
|
||||||
"@renovatebot/pep440": "^4.2.1",
|
"@renovatebot/pep440": "^4.2.1",
|
||||||
"smol-toml": "^1.6.0",
|
"smol-toml": "^1.6.0",
|
||||||
"undici": "^6.24.1"
|
"undici": "^6.24.1"
|
||||||
@@ -42,9 +53,9 @@
|
|||||||
"@biomejs/biome": "^2.4.7",
|
"@biomejs/biome": "^2.4.7",
|
||||||
"@types/jest": "^29.5.14",
|
"@types/jest": "^29.5.14",
|
||||||
"@types/js-yaml": "^4.0.9",
|
"@types/js-yaml": "^4.0.9",
|
||||||
"@types/node": "^25.5.0",
|
"@types/node": "^26.1.1",
|
||||||
"@types/semver": "^7.7.1",
|
"@types/semver": "^7.7.1",
|
||||||
"esbuild": "^0.27.4",
|
"esbuild": "^0.28.2",
|
||||||
"jest": "^30.3.0",
|
"jest": "^30.3.0",
|
||||||
"js-yaml": "^4.1.1",
|
"js-yaml": "^4.1.1",
|
||||||
"ts-jest": "^29.4.6",
|
"ts-jest": "^29.4.6",
|
||||||
|
|||||||
+3476
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -5,25 +5,16 @@ export async function updateChecksums(
|
|||||||
filePath: string,
|
filePath: string,
|
||||||
downloadUrls: string[],
|
downloadUrls: string[],
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await fs.rm(filePath);
|
const checksums: Record<string, string> = {};
|
||||||
await fs.appendFile(
|
|
||||||
filePath,
|
|
||||||
"// AUTOGENERATED_DO_NOT_EDIT\nexport const KNOWN_CHECKSUMS: { [key: string]: string } = {\n",
|
|
||||||
);
|
|
||||||
let firstLine = true;
|
|
||||||
for (const downloadUrl of downloadUrls) {
|
for (const downloadUrl of downloadUrls) {
|
||||||
const key = getKey(downloadUrl);
|
const key = getKey(downloadUrl);
|
||||||
if (key === undefined) {
|
if (key === undefined) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const checksum = await getOrDownloadChecksum(key, downloadUrl);
|
const checksum = await getOrDownloadChecksum(key, downloadUrl);
|
||||||
if (!firstLine) {
|
checksums[key] = checksum;
|
||||||
await fs.appendFile(filePath, ",\n");
|
|
||||||
}
|
|
||||||
await fs.appendFile(filePath, ` "${key}":\n "${checksum}"`);
|
|
||||||
firstLine = false;
|
|
||||||
}
|
}
|
||||||
await fs.appendFile(filePath, ",\n};\n");
|
await fs.writeFile(filePath, `${JSON.stringify(checksums, null, 2)}\n`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getKey(downloadUrl: string): string | undefined {
|
function getKey(downloadUrl: string): string | undefined {
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export async function downloadVersion(
|
|||||||
checksum: string | undefined,
|
checksum: string | undefined,
|
||||||
githubToken: string,
|
githubToken: string,
|
||||||
manifestUrl?: string,
|
manifestUrl?: string,
|
||||||
|
downloadFromAstralMirror = true,
|
||||||
): Promise<{ version: string; cachedToolDir: string }> {
|
): Promise<{ version: string; cachedToolDir: string }> {
|
||||||
const artifact = await getArtifact(version, arch, platform, manifestUrl);
|
const artifact = await getArtifact(version, arch, platform, manifestUrl);
|
||||||
|
|
||||||
@@ -57,6 +58,7 @@ export async function downloadVersion(
|
|||||||
arch,
|
arch,
|
||||||
version,
|
version,
|
||||||
getDownloadToken(artifact.downloadUrl, githubToken),
|
getDownloadToken(artifact.downloadUrl, githubToken),
|
||||||
|
downloadFromAstralMirror,
|
||||||
);
|
);
|
||||||
await validateChecksum(
|
await validateChecksum(
|
||||||
resolvedChecksum,
|
resolvedChecksum,
|
||||||
@@ -83,6 +85,10 @@ export async function downloadVersion(
|
|||||||
return { cachedToolDir, version };
|
return { cachedToolDir, version };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rewrite a GitHub Releases URL to the Astral mirror.
|
||||||
|
* Returns `undefined` if the URL does not match the expected GitHub prefix.
|
||||||
|
*/
|
||||||
export function rewriteToMirror(url: string): string | undefined {
|
export function rewriteToMirror(url: string): string | undefined {
|
||||||
if (!url.startsWith(GITHUB_RELEASES_PREFIX)) {
|
if (!url.startsWith(GITHUB_RELEASES_PREFIX)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -97,8 +103,11 @@ async function downloadArtifact(
|
|||||||
arch: Architecture,
|
arch: Architecture,
|
||||||
version: string,
|
version: string,
|
||||||
githubToken: string | undefined,
|
githubToken: string | undefined,
|
||||||
|
downloadFromAstralMirror: boolean,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const mirrorUrl = rewriteToMirror(downloadUrl);
|
const mirrorUrl = downloadFromAstralMirror
|
||||||
|
? rewriteToMirror(downloadUrl)
|
||||||
|
: undefined;
|
||||||
const resolvedDownloadUrl = mirrorUrl ?? downloadUrl;
|
const resolvedDownloadUrl = mirrorUrl ?? downloadUrl;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
+24
-10
@@ -9,6 +9,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
args,
|
args,
|
||||||
checkSum,
|
checkSum,
|
||||||
|
downloadFromAstralMirror,
|
||||||
githubToken,
|
githubToken,
|
||||||
manifestFile,
|
manifestFile,
|
||||||
src,
|
src,
|
||||||
@@ -21,6 +22,11 @@ import {
|
|||||||
getPlatform,
|
getPlatform,
|
||||||
type Platform,
|
type Platform,
|
||||||
} from "./utils/platforms";
|
} from "./utils/platforms";
|
||||||
|
import {
|
||||||
|
expandSourceInput,
|
||||||
|
getVersionSourceDirectory,
|
||||||
|
splitInput,
|
||||||
|
} from "./utils/source-input";
|
||||||
import { resolveRuffVersion } from "./version/resolve";
|
import { resolveRuffVersion } from "./version/resolve";
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
@@ -34,7 +40,13 @@ async function run(): Promise<void> {
|
|||||||
if (arch === undefined) {
|
if (arch === undefined) {
|
||||||
throw new Error(`Unsupported architecture: ${process.arch}`);
|
throw new Error(`Unsupported architecture: ${process.arch}`);
|
||||||
}
|
}
|
||||||
const setupResult = await setupRuff(platform, arch, checkSum, githubToken);
|
const setupResult = await setupRuff(
|
||||||
|
platform,
|
||||||
|
arch,
|
||||||
|
checkSum,
|
||||||
|
githubToken,
|
||||||
|
downloadFromAstralMirror,
|
||||||
|
);
|
||||||
|
|
||||||
addRuffToPath(setupResult.ruffDir);
|
addRuffToPath(setupResult.ruffDir);
|
||||||
setOutputFormat();
|
setOutputFormat();
|
||||||
@@ -42,11 +54,7 @@ async function run(): Promise<void> {
|
|||||||
core.setOutput("ruff-version", setupResult.version);
|
core.setOutput("ruff-version", setupResult.version);
|
||||||
core.info(`Successfully installed ruff version ${setupResult.version}`);
|
core.info(`Successfully installed ruff version ${setupResult.version}`);
|
||||||
|
|
||||||
await runRuff(
|
await runRuff(path.join(setupResult.ruffDir, "ruff"), args, src);
|
||||||
path.join(setupResult.ruffDir, "ruff"),
|
|
||||||
args.split(" "),
|
|
||||||
src.split(" "),
|
|
||||||
);
|
|
||||||
|
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -59,6 +67,7 @@ async function setupRuff(
|
|||||||
arch: Architecture,
|
arch: Architecture,
|
||||||
checkSum: string | undefined,
|
checkSum: string | undefined,
|
||||||
githubToken: string,
|
githubToken: string,
|
||||||
|
downloadFromAstralMirror: boolean,
|
||||||
): Promise<{ ruffDir: string; version: string }> {
|
): Promise<{ ruffDir: string; version: string }> {
|
||||||
const resolvedVersion = await determineVersion();
|
const resolvedVersion = await determineVersion();
|
||||||
const manifestUrl = manifestFile || undefined;
|
const manifestUrl = manifestFile || undefined;
|
||||||
@@ -83,6 +92,7 @@ async function setupRuff(
|
|||||||
checkSum,
|
checkSum,
|
||||||
githubToken,
|
githubToken,
|
||||||
manifestUrl,
|
manifestUrl,
|
||||||
|
downloadFromAstralMirror,
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -94,7 +104,11 @@ async function setupRuff(
|
|||||||
async function determineVersion(): Promise<string> {
|
async function determineVersion(): Promise<string> {
|
||||||
return await resolveRuffVersion({
|
return await resolveRuffVersion({
|
||||||
manifestFile: manifestFile || undefined,
|
manifestFile: manifestFile || undefined,
|
||||||
sourceDirectory: src,
|
sourceDirectory: await getVersionSourceDirectory(
|
||||||
|
src,
|
||||||
|
version,
|
||||||
|
versionFileInput,
|
||||||
|
),
|
||||||
version,
|
version,
|
||||||
versionFile: versionFileInput,
|
versionFile: versionFileInput,
|
||||||
workspaceRoot: process.env.GITHUB_WORKSPACE || ".",
|
workspaceRoot: process.env.GITHUB_WORKSPACE || ".",
|
||||||
@@ -125,10 +139,10 @@ function getActionRoot(): string {
|
|||||||
|
|
||||||
async function runRuff(
|
async function runRuff(
|
||||||
ruffExecutablePath: string,
|
ruffExecutablePath: string,
|
||||||
args: string[],
|
args: string,
|
||||||
src: string[],
|
src: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const execArgs = [...args, ...src];
|
const execArgs = [...splitInput(args), ...(await expandSourceInput(src))];
|
||||||
await exec.exec(ruffExecutablePath, execArgs);
|
await exec.exec(ruffExecutablePath, execArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,3 +7,14 @@ export const args = core.getInput("args");
|
|||||||
export const src = core.getInput("src");
|
export const src = core.getInput("src");
|
||||||
export const versionFile = core.getInput("version-file");
|
export const versionFile = core.getInput("version-file");
|
||||||
export const manifestFile = core.getInput("manifest-file");
|
export const manifestFile = core.getInput("manifest-file");
|
||||||
|
export const downloadFromAstralMirror = getBooleanInput(
|
||||||
|
"download-from-astral-mirror",
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
|
function getBooleanInput(name: string, defaultValue: boolean): boolean {
|
||||||
|
if (core.getInput(name) === "") {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
return core.getBooleanInput(name);
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,19 +3,22 @@ import * as path from "node:path";
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search for a pyproject.toml file starting from the given directory
|
* Search for a pyproject.toml file starting from the given source path
|
||||||
* and traversing upwards through parent directories until reaching
|
* and traversing upwards through parent directories until reaching
|
||||||
* the GitHub workspace root.
|
* the GitHub workspace root.
|
||||||
*
|
*
|
||||||
* @param startDir The directory to start the search from (e.g., the src input)
|
* If the source path points to a file, the search begins in that file's
|
||||||
|
* parent directory.
|
||||||
|
*
|
||||||
|
* @param startPath The source path to start the search from (file or directory)
|
||||||
* @param workspaceRoot The GitHub workspace directory (GITHUB_WORKSPACE)
|
* @param workspaceRoot The GitHub workspace directory (GITHUB_WORKSPACE)
|
||||||
* @returns The path to the found pyproject.toml, or undefined if not found
|
* @returns The path to the found pyproject.toml, or undefined if not found
|
||||||
*/
|
*/
|
||||||
export function findPyprojectToml(
|
export function findPyprojectToml(
|
||||||
startDir: string,
|
startPath: string,
|
||||||
workspaceRoot: string,
|
workspaceRoot: string,
|
||||||
): string | undefined {
|
): string | undefined {
|
||||||
let currentDir = path.resolve(startDir);
|
let currentDir = resolveStartDirectory(startPath);
|
||||||
const resolvedWorkspaceRoot = path.resolve(workspaceRoot);
|
const resolvedWorkspaceRoot = path.resolve(workspaceRoot);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -42,6 +45,19 @@ export function findPyprojectToml(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resolveStartDirectory(startPath: string): string {
|
||||||
|
const resolvedStartPath = path.resolve(startPath);
|
||||||
|
|
||||||
|
if (!fs.existsSync(resolvedStartPath)) {
|
||||||
|
return resolvedStartPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
const stats = fs.statSync(resolvedStartPath);
|
||||||
|
return stats.isDirectory()
|
||||||
|
? resolvedStartPath
|
||||||
|
: path.dirname(resolvedStartPath);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a given path is within or equal to the workspace root.
|
* Check if a given path is within or equal to the workspace root.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,161 @@
|
|||||||
|
import * as fs from "node:fs/promises";
|
||||||
|
import * as path from "node:path";
|
||||||
|
import * as glob from "@actions/glob";
|
||||||
|
|
||||||
|
const GLOB_PATTERN = /[*?[]/;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Split an action input into whitespace-delimited tokens.
|
||||||
|
*
|
||||||
|
* The action has historically documented both `args` and `src` as plain
|
||||||
|
* whitespace-delimited inputs. Keep that behavior instead of invoking a shell.
|
||||||
|
*/
|
||||||
|
export function splitInput(input: string): string[] {
|
||||||
|
return input.trim().split(/\s+/).filter(Boolean);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expand glob patterns from the `src` input in a cross-platform way.
|
||||||
|
*
|
||||||
|
* Glob syntax is defined by @actions/glob. This action does not emulate shell
|
||||||
|
* expansion. Unmatched patterns are preserved so Ruff can report the missing
|
||||||
|
* path.
|
||||||
|
*/
|
||||||
|
export async function expandSourceInput(srcInput: string): Promise<string[]> {
|
||||||
|
const sources = splitInput(srcInput);
|
||||||
|
|
||||||
|
if (sources.length === 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const expandedSources: string[] = [];
|
||||||
|
for (const source of sources) {
|
||||||
|
if (!hasGlobPattern(source)) {
|
||||||
|
expandedSources.push(source);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const matches = await globMatches(source);
|
||||||
|
expandedSources.push(...(matches.length > 0 ? matches : [source]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return expandedSources;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve the starting path for version discovery from the `src` input.
|
||||||
|
*
|
||||||
|
* Takes the first whitespace-delimited token. Literal paths are preserved. Glob
|
||||||
|
* patterns use their first sorted match when available, so pyproject.toml
|
||||||
|
* discovery starts from a path Ruff will actually check. Unmatched globs fall
|
||||||
|
* back to @actions/glob's search path.
|
||||||
|
*/
|
||||||
|
export async function getVersionSourceDirectory(
|
||||||
|
srcInput: string,
|
||||||
|
versionInput: string | undefined,
|
||||||
|
versionFileInput: string | undefined,
|
||||||
|
): Promise<string> {
|
||||||
|
if (hasInput(versionInput) || hasInput(versionFileInput)) {
|
||||||
|
return ".";
|
||||||
|
}
|
||||||
|
|
||||||
|
return await getSourceBasePath(srcInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getSourceBasePath(srcInput: string): Promise<string> {
|
||||||
|
const firstSource = splitInput(srcInput)[0] ?? ".";
|
||||||
|
|
||||||
|
if (!hasGlobPattern(firstSource)) {
|
||||||
|
return stripTrailingSeparators(firstSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
const globber = await createGlobber(firstSource);
|
||||||
|
const matches = (await globber.glob()).sort();
|
||||||
|
if (matches.length > 0) {
|
||||||
|
return (
|
||||||
|
(await preserveSourcePathStyle(firstSource, [matches[0] ?? "."]))[0] ??
|
||||||
|
"."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const searchPaths = globber.getSearchPaths().sort();
|
||||||
|
if (searchPaths.length > 0) {
|
||||||
|
return (
|
||||||
|
(
|
||||||
|
await preserveSourcePathStyle(firstSource, [searchPaths[0] ?? "."])
|
||||||
|
)[0] ?? "."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ".";
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasInput(input: string | undefined): boolean {
|
||||||
|
return input !== undefined && input.trim() !== "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasGlobPattern(source: string): boolean {
|
||||||
|
return GLOB_PATTERN.test(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
function stripTrailingSeparators(source: string): string {
|
||||||
|
const root = path.parse(source).root;
|
||||||
|
const strippedSource = source.replace(/[/\\]+$/, "");
|
||||||
|
|
||||||
|
if (root !== "" && strippedSource.length < root.length) {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
return strippedSource || root || ".";
|
||||||
|
}
|
||||||
|
|
||||||
|
async function globMatches(pattern: string): Promise<string[]> {
|
||||||
|
const globber = await createGlobber(pattern);
|
||||||
|
const matches = await globber.glob();
|
||||||
|
|
||||||
|
return await preserveSourcePathStyle(pattern, matches.sort());
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createGlobber(pattern: string): Promise<glob.Globber> {
|
||||||
|
return await glob.create(normalizeGlobPattern(pattern), {
|
||||||
|
excludeHiddenFiles: !explicitlyTargetsHiddenPath(pattern),
|
||||||
|
followSymbolicLinks: false,
|
||||||
|
implicitDescendants: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function preserveSourcePathStyle(
|
||||||
|
pattern: string,
|
||||||
|
matches: string[],
|
||||||
|
): Promise<string[]> {
|
||||||
|
if (path.isAbsolute(pattern)) {
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cwd = await fs.realpath(process.cwd());
|
||||||
|
return matches.map((match) => path.relative(cwd, match) || ".");
|
||||||
|
}
|
||||||
|
|
||||||
|
function explicitlyTargetsHiddenPath(pattern: string): boolean {
|
||||||
|
return splitSourcePath(pattern).some(isHiddenPathSegment);
|
||||||
|
}
|
||||||
|
|
||||||
|
function splitSourcePath(source: string): string[] {
|
||||||
|
const root = path.parse(source).root;
|
||||||
|
const relativePath = source.slice(root.length);
|
||||||
|
const separatorPattern = process.platform === "win32" ? /[/\\]+/ : /\/+/;
|
||||||
|
|
||||||
|
return relativePath.split(separatorPattern).filter(Boolean);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isHiddenPathSegment(segment: string): boolean {
|
||||||
|
return segment.startsWith(".") && segment !== "." && segment !== "..";
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeGlobPattern(pattern: string): string {
|
||||||
|
if (process.platform !== "win32") {
|
||||||
|
return pattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pattern.replace(/\\/g, "/");
|
||||||
|
}
|
||||||
@@ -24,6 +24,10 @@ interface Pyproject {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface UvLock {
|
||||||
|
package?: Array<{ name?: string; version?: string }>;
|
||||||
|
}
|
||||||
|
|
||||||
const VERSION_FILE_PARSERS: VersionFileParser[] = [
|
const VERSION_FILE_PARSERS: VersionFileParser[] = [
|
||||||
{
|
{
|
||||||
format: "pyproject.toml",
|
format: "pyproject.toml",
|
||||||
@@ -33,6 +37,14 @@ const VERSION_FILE_PARSERS: VersionFileParser[] = [
|
|||||||
},
|
},
|
||||||
supports: (filePath) => filePath.endsWith("pyproject.toml"),
|
supports: (filePath) => filePath.endsWith("pyproject.toml"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
format: "uv.lock",
|
||||||
|
parse: (filePath) => {
|
||||||
|
const fileContent = fs.readFileSync(filePath, "utf-8");
|
||||||
|
return getRuffVersionFromUvLockContent(fileContent);
|
||||||
|
},
|
||||||
|
supports: (filePath) => filePath.endsWith("uv.lock"),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
format: "requirements",
|
format: "requirements",
|
||||||
parse: (filePath) => {
|
parse: (filePath) => {
|
||||||
@@ -132,6 +144,18 @@ export function parsePyprojectContent(pyprojectContent: string): Pyproject {
|
|||||||
return toml.parse(pyprojectContent) as Pyproject;
|
return toml.parse(pyprojectContent) as Pyproject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getRuffVersionFromUvLockContent(
|
||||||
|
uvLockContent: string,
|
||||||
|
): string | undefined {
|
||||||
|
const uvLock = toml.parse(uvLockContent) as UvLock;
|
||||||
|
const ruffPackage = (uvLock.package || []).find((pkg) => pkg.name === "ruff");
|
||||||
|
if (ruffPackage?.version === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
core.info(`Found ruff version in uv.lock: ${ruffPackage.version}`);
|
||||||
|
return ruffPackage.version;
|
||||||
|
}
|
||||||
|
|
||||||
function getVersionFileParser(filePath: string): VersionFileParser | undefined {
|
function getVersionFileParser(filePath: string): VersionFileParser | undefined {
|
||||||
return VERSION_FILE_PARSERS.find((parser) => parser.supports(filePath));
|
return VERSION_FILE_PARSERS.find((parser) => parser.supports(filePath));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ export type VersionSource =
|
|||||||
| "pyproject.toml"
|
| "pyproject.toml"
|
||||||
| "default";
|
| "default";
|
||||||
|
|
||||||
export type VersionFileFormat = "pyproject.toml" | "requirements";
|
export type VersionFileFormat = "pyproject.toml" | "requirements" | "uv.lock";
|
||||||
|
|
||||||
export interface ParsedVersionFile {
|
export interface ParsedVersionFile {
|
||||||
format: VersionFileFormat;
|
format: VersionFileFormat;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
"module": "esnext",
|
"module": "esnext",
|
||||||
"moduleResolution": "bundler",
|
"moduleResolution": "bundler",
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"target": "ES2022"
|
"target": "ES2022"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user