mirror of
https://github.com/astral-sh/ruff-action.git
synced 2026-08-08 18:27:03 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ce1b0bf8b | ||
|
|
9b8caf6c41 | ||
|
|
535554df96 | ||
|
|
2186c6ecae | ||
|
|
26892dbe43 | ||
|
|
d7f6ad639a | ||
|
|
5b5935861b | ||
|
|
0be154b683 | ||
|
|
f611dfc122 | ||
|
|
d40baf4d10 | ||
|
|
18ddc929c7 | ||
|
|
25445a5bce | ||
|
|
cb58d827d0 | ||
|
|
845ce6a88f | ||
|
|
48f37fab2d | ||
|
|
53288957fd | ||
|
|
bab84a8f49 | ||
|
|
4919ec5cf1 | ||
|
|
1977806bc6 | ||
|
|
aedff8d295 | ||
|
|
191187a20a | ||
|
|
ecac2cc03c | ||
|
|
ddb8c29960 | ||
|
|
5eee2a4332 | ||
|
|
1d756c4b80 | ||
|
|
fde82cb611 | ||
|
|
deb632007b | ||
|
|
90ea8a399c | ||
|
|
7840fe30a7 | ||
|
|
56403b4f7c | ||
|
|
eacaa6bf71 | ||
|
|
e85c033ebc | ||
|
|
8b935c8722 | ||
|
|
c03f335068 | ||
|
|
7b97a6d66e | ||
|
|
5960f93ec0 | ||
|
|
1e133b7ccc | ||
|
|
cd51da8b6c | ||
|
|
27c6fcea11 | ||
|
|
b08f7b47e5 | ||
|
|
e7baf99fcc | ||
|
|
4f45dfa46b | ||
|
|
4ac3c5ec56 | ||
|
|
7f084f337e | ||
|
|
87990efc6b | ||
|
|
5ad29210b1 | ||
|
|
e46bd63c5f | ||
|
|
bfff570296 | ||
|
|
6576144cee | ||
|
|
7af5f13130 | ||
|
|
c48d3eaf66 | ||
|
|
f18f95d449 | ||
|
|
15a82c0309 | ||
|
|
5071c37a33 | ||
|
|
c397d0cf88 | ||
|
|
16fb2a8927 | ||
|
|
421486e990 | ||
|
|
6d8460e4e6 | ||
|
|
74b1866cee | ||
|
|
fbc7e4525b | ||
|
|
57714a7c8a | ||
|
|
f46fd74e35 | ||
|
|
6afcb280fd | ||
|
|
232c1eca56 | ||
|
|
6b45781b82 | ||
|
|
a099b88c70 | ||
|
|
b63c059bc7 | ||
|
|
0c50076f12 | ||
|
|
966d2455d2 | ||
|
|
b9e360afba | ||
|
|
2b785e352d | ||
|
|
8c3aa952c0 | ||
|
|
52ac3ada91 | ||
|
|
813f619ec2 | ||
|
|
110a15d08b | ||
|
|
6228face02 | ||
|
|
eaf0ecdd66 | ||
|
|
78b7b9921e | ||
|
|
9b2efb7fd8 | ||
|
|
da0c801a2d | ||
|
|
257550e917 | ||
|
|
94b3590e87 | ||
|
|
7a9e8edffe | ||
|
|
84f83ecf9e | ||
|
|
ea12b8ac41 | ||
|
|
b259b0b299 | ||
|
|
c6bea5606c | ||
|
|
400ab365db | ||
|
|
719c6e52c1 | ||
|
|
9a7114796b | ||
|
|
07c64b80af | ||
|
|
f800ba97f6 | ||
|
|
fd7f7e1868 | ||
|
|
faac838a0b | ||
|
|
94d4d711a6 | ||
|
|
9828f49eb4 | ||
|
|
8bfebd2812 | ||
|
|
b08b0d12d5 | ||
|
|
aecd4a32f6 | ||
|
|
8b3439f688 | ||
|
|
708db45010 | ||
|
|
9bdf1198e7 | ||
|
|
736d6639d0 | ||
|
|
bba8eb68c5 | ||
|
|
140ba44f2c | ||
|
|
5b3aacfc8f | ||
|
|
b11c1acffb | ||
|
|
19e5e84cff | ||
|
|
39f75e526a | ||
|
|
e0aedf576b | ||
|
|
160796f1a1 | ||
|
|
a7b1296fb5 | ||
|
|
097d5252c8 | ||
|
|
5f8cbe30d7 | ||
|
|
d8f577dec4 | ||
|
|
f173943ec8 | ||
|
|
d34edb0565 | ||
|
|
f14634c415 | ||
|
|
47de3deae8 | ||
|
|
d8281c74d4 | ||
|
|
a634044659 | ||
|
|
2993ff4a65 | ||
|
|
20a3b171f4 | ||
|
|
1c1aef9e3d | ||
|
|
0ceb04d9a0 | ||
|
|
18db80c954 | ||
|
|
0a5dfb89f1 | ||
|
|
9071a7b1c3 | ||
|
|
0c24450c01 | ||
|
|
e6390afda0 | ||
|
|
55d5f5e208 | ||
|
|
f6d50c4b88 | ||
|
|
4ef55e95c2 | ||
|
|
aef0def40a | ||
|
|
31a5185046 | ||
|
|
7a82f1f7e4 | ||
|
|
cac2f108b2 | ||
|
|
35619fdbcc | ||
|
|
c9185454fa | ||
|
|
a2d5d1ffa4 | ||
|
|
ec9ad4417f | ||
|
|
efef6ba8fa | ||
|
|
e5ab5d43a6 |
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"problemMatcher": [
|
||||||
|
{
|
||||||
|
"owner": "ruff-check",
|
||||||
|
"pattern": [
|
||||||
|
{
|
||||||
|
"code": 4,
|
||||||
|
"column": 3,
|
||||||
|
"file": 1,
|
||||||
|
"line": 2,
|
||||||
|
"message": 5,
|
||||||
|
"regexp": "^Error: (.*):(\\d+):(\\d+): (\\w+) (.*)$"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"problemMatcher": [
|
||||||
|
{
|
||||||
|
"owner": "ruff-format",
|
||||||
|
"pattern": [
|
||||||
|
{
|
||||||
|
"code": 2,
|
||||||
|
"column": 5,
|
||||||
|
"endColumn": 7,
|
||||||
|
"endLine": 6,
|
||||||
|
"file": 3,
|
||||||
|
"line": 4,
|
||||||
|
"message": 8,
|
||||||
|
"regexp": "^(?:(error|warning|notice))\\s+title=([^,]+),file=([^,]+),line=(\\d+),col=(\\d+)(?:,endLine=(\\d+))?(?:,endColumn=(\\d+))?::(.+)$",
|
||||||
|
"severity": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import * as fs from "node:fs";
|
||||||
|
import * as yaml from "js-yaml";
|
||||||
|
|
||||||
|
interface WorkflowJob {
|
||||||
|
needs?: string[];
|
||||||
|
[key: string]: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Workflow {
|
||||||
|
jobs: Record<string, WorkflowJob>;
|
||||||
|
[key: string]: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
const workflow = yaml.load(
|
||||||
|
fs.readFileSync("../workflows/test.yml", "utf8"),
|
||||||
|
) as Workflow;
|
||||||
|
const jobs = Object.keys(workflow.jobs);
|
||||||
|
const allTestsPassed = workflow.jobs["all-tests-passed"];
|
||||||
|
const needs: string[] = allTestsPassed.needs || [];
|
||||||
|
|
||||||
|
const expectedNeeds = jobs.filter((j) => j !== "all-tests-passed");
|
||||||
|
const missing = expectedNeeds.filter((j) => !needs.includes(j));
|
||||||
|
|
||||||
|
if (missing.length > 0) {
|
||||||
|
console.error(
|
||||||
|
`Missing jobs in all-tests-passed needs: ${missing.join(", ")}`,
|
||||||
|
);
|
||||||
|
console.info(
|
||||||
|
"Please add the missing jobs to the needs section of all-tests-passed in test.yml.",
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
console.log(
|
||||||
|
"All jobs in test.yml are in the needs section of all-tests-passed.",
|
||||||
|
);
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "nodenext",
|
||||||
|
"moduleResolution": "nodenext",
|
||||||
|
"target": "es2022",
|
||||||
|
"types": ["node"]
|
||||||
|
},
|
||||||
|
"include": ["check-all-tests-passed-needs.ts"]
|
||||||
|
}
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
# `dist/index.js` is a special file in Actions.
|
|
||||||
# When you reference an action with `uses:` in a workflow,
|
|
||||||
# `index.js` is the code that will run.
|
|
||||||
# For our project, we generate this file through a build process from other source files.
|
|
||||||
# We need to make sure the checked-in `index.js` actually matches what we expect it to be.
|
|
||||||
name: Check dist/
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
pull_request:
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
check-dist:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Node.js 20
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 20
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: npm ci
|
|
||||||
|
|
||||||
- name: Rebuild the dist/ directory
|
|
||||||
run: |
|
|
||||||
npm run build
|
|
||||||
npm run package
|
|
||||||
|
|
||||||
- name: Compare the expected and actual dist/ directories
|
|
||||||
run: |
|
|
||||||
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
|
|
||||||
echo "Detected uncommitted changes after build. See status below:"
|
|
||||||
git diff --text -v
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
id: diff
|
|
||||||
|
|
||||||
# If index.js was different than expected, upload the expected version as an artifact
|
|
||||||
- uses: actions/upload-artifact@v4
|
|
||||||
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
|
||||||
with:
|
|
||||||
name: dist
|
|
||||||
path: dist/
|
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
name: "CodeQL"
|
name: "CodeQL"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
pull_request:
|
pull_request:
|
||||||
@@ -38,11 +39,13 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
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@v3
|
uses: github/codeql-action/init@b20883b0cd1f46c72ae0ba6d1090936928f9fa30 # v4.32.0
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
source-root: src
|
source-root: src
|
||||||
@@ -54,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@v3
|
uses: github/codeql-action/autobuild@b20883b0cd1f46c72ae0ba6d1090936928f9fa30 # v4.32.0
|
||||||
|
|
||||||
# ℹ️ 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
|
||||||
@@ -68,4 +71,4 @@ jobs:
|
|||||||
# make release
|
# make release
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v3
|
uses: github/codeql-action/analyze@b20883b0cd1f46c72ae0ba6d1090936928f9fa30 # v4.32.0
|
||||||
|
|||||||
@@ -3,17 +3,20 @@ name: Release Drafter
|
|||||||
|
|
||||||
# yamllint disable-line rule:truthy
|
# yamllint disable-line rule:truthy
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
update_release_draft:
|
update_release_draft:
|
||||||
name: ✏️ Draft release
|
name: ✏️ Draft release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
pull-requests: read
|
||||||
steps:
|
steps:
|
||||||
- name: 🚀 Run Release Drafter
|
- name: 🚀 Run Release Drafter
|
||||||
uses: release-drafter/release-drafter@v6.0.0
|
uses: release-drafter/release-drafter@5de93583980a40bd78603b6dfdcda5b4df377b32 # v7.2.0
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
version:
|
||||||
|
description: "Release version (e.g., 8.1.0)"
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
name: Release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
environment: release
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Validate version
|
||||||
|
env:
|
||||||
|
VERSION: ${{ inputs.version }}
|
||||||
|
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
|
||||||
|
|
||||||
|
- name: Publish release
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
TAG: v${{ inputs.version }}
|
||||||
|
run: |
|
||||||
|
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
|
||||||
|
|
||||||
|
echo "Publishing draft release $TAG"
|
||||||
|
gh release edit "$TAG" --draft=false
|
||||||
+381
-32
@@ -1,7 +1,7 @@
|
|||||||
name: "test"
|
name: "test"
|
||||||
on:
|
on:
|
||||||
pull_request:
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
pull_request:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
@@ -10,51 +10,282 @@ concurrency:
|
|||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
security-events: write # for zizmor
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
- name: Actionlint
|
|
||||||
uses: eifinger/actionlint-action@bdc2a242a53ae50e609e29f8eeb0d05d792edc09 # v1.7.0
|
|
||||||
continue-on-error: true # Until https://github.com/rhysd/actionlint/pull/485 is released
|
|
||||||
- uses: actions/setup-node@v4
|
|
||||||
with:
|
with:
|
||||||
node-version: "20"
|
persist-credentials: false
|
||||||
|
- name: Actionlint
|
||||||
|
uses: eifinger/actionlint-action@1fc89649be682d16ec5cf65ea16e269eb88d3982 # v1.10.2
|
||||||
|
- name: Run zizmor
|
||||||
|
uses: zizmorcore/zizmor-action@71321a20a9ded102f6e9ce5718a2fcec2c4f70d8 # v0.5.2
|
||||||
|
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
|
||||||
|
with:
|
||||||
|
node-version-file: .nvmrc
|
||||||
|
cache: npm
|
||||||
- run: |
|
- run: |
|
||||||
npm install
|
npm ci --ignore-scripts
|
||||||
- run: |
|
- run: |
|
||||||
npm run all
|
npm run all
|
||||||
|
- name: Check all jobs are in all-tests-passed.needs
|
||||||
|
run: |
|
||||||
|
tsc -p tsconfig.json
|
||||||
|
node check-all-tests-passed-needs.js
|
||||||
|
working-directory: .github/scripts
|
||||||
- name: Make sure no changes from linters are detected
|
- name: Make sure no changes from linters are detected
|
||||||
run: |
|
run: |
|
||||||
git diff --exit-code
|
git diff --exit-code || (echo "::error::Please run 'npm run all' to fix the issues" && exit 1)
|
||||||
test-default-version:
|
test-latest-version:
|
||||||
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-14, windows-latest]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
- name: Use default version
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Use latest version
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
src: __tests__/fixtures/python-project
|
src: __tests__/fixtures/python-project
|
||||||
|
version: latest
|
||||||
test-specific-version:
|
test-specific-version:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
ruff-version: ["0.7.4", "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 ]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Use version ${{ matrix.ruff-version }}
|
- name: Use version ${{ matrix.ruff-version }}
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
version: ${{ matrix.ruff-version }}
|
version: ${{ matrix.ruff-version }}
|
||||||
src: __tests__/fixtures/python-project
|
src: __tests__/fixtures/python-project
|
||||||
|
test-unsupported-version:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Try install old version
|
||||||
|
id: install
|
||||||
|
continue-on-error: true
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
version: 0.0.246
|
||||||
|
src: __tests__/fixtures/python-project
|
||||||
|
- name: Check if the action failed
|
||||||
|
run: |
|
||||||
|
if [ "${INSTALL_OUTCOME}" == "success" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
env:
|
||||||
|
INSTALL_OUTCOME: ${{ steps.install.outcome }}
|
||||||
|
test-version-from-version-file-pyproject:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- 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:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Use default version from pyproject.toml
|
||||||
|
id: ruff-action
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
src: __tests__/fixtures/python-project
|
||||||
|
- name: Correct version gets installed
|
||||||
|
run: |
|
||||||
|
if [ "$RUFF_VERSION" != "0.6.2" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
env:
|
||||||
|
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
||||||
|
test-default-version-from-pyproject-dev-group:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Use default version from pyproject.toml dev group
|
||||||
|
id: ruff-action
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
src: __tests__/fixtures/pyproject-dependency-dev-project
|
||||||
|
version-file: __tests__/fixtures/pyproject-dependency-dev-project/pyproject.toml
|
||||||
|
- name: Correct version gets installed
|
||||||
|
run: |
|
||||||
|
if [ "$RUFF_VERSION" != "0.8.3" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
env:
|
||||||
|
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
||||||
|
test-default-version-from-pyproject-dependency-groups:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Use default version from pyproject.toml dependency groups
|
||||||
|
id: ruff-action
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
src: __tests__/fixtures/pyproject-dependency-groups-project
|
||||||
|
version-file: __tests__/fixtures/pyproject-dependency-groups-project/pyproject.toml
|
||||||
|
- name: Correct version gets installed
|
||||||
|
run: |
|
||||||
|
if [ "$RUFF_VERSION" != "0.8.3" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
env:
|
||||||
|
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
||||||
|
test-default-version-from-pyproject-dependency-groups-with-env-marker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Use default version from pyproject.toml with environment marker
|
||||||
|
id: ruff-action
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
src: __tests__/fixtures/python-project
|
||||||
|
version-file: __tests__/fixtures/pyproject-dependency-groups-with-env-marker/pyproject.toml
|
||||||
|
- name: Correct version gets installed
|
||||||
|
run: |
|
||||||
|
if [ "$RUFF_VERSION" != "0.13.3" ]; then
|
||||||
|
echo "Expected version 0.13.3 but got $RUFF_VERSION"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
env:
|
||||||
|
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
||||||
|
test-default-version-from-pyproject-poetry-groups:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Use default version from pyproject.toml poetry group dependencies
|
||||||
|
id: ruff-action
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
src: __tests__/fixtures/pyproject-dependency-poetry-grouped-project
|
||||||
|
version-file: __tests__/fixtures/pyproject-dependency-poetry-grouped-project/pyproject.toml
|
||||||
|
- name: Correct version gets installed
|
||||||
|
run: |
|
||||||
|
if [ "$RUFF_VERSION" != "0.8.3" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
env:
|
||||||
|
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
||||||
|
test-default-version-from-pyproject-poetry:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Use default version from pyproject.toml poetry dependencies
|
||||||
|
id: ruff-action
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
src: __tests__/fixtures/pyproject-dependency-poetry-project
|
||||||
|
version-file: __tests__/fixtures/pyproject-dependency-poetry-project/pyproject.toml
|
||||||
|
- name: Correct version gets installed
|
||||||
|
run: |
|
||||||
|
if [ "$RUFF_VERSION" != "0.8.6" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
env:
|
||||||
|
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
||||||
|
test-default-version-from-pyproject-optional-dependencies:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Use default version from pyproject.toml optional dependencies
|
||||||
|
id: ruff-action
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
src: __tests__/fixtures/pyproject-optional-dependencies-project
|
||||||
|
version-file: __tests__/fixtures/pyproject-optional-dependencies-project/pyproject.toml
|
||||||
|
- name: Correct version gets installed
|
||||||
|
run: |
|
||||||
|
if [ "$RUFF_VERSION" != "0.8.3" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
env:
|
||||||
|
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
||||||
|
test-default-version-from-requirements:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Use default version from requirements.txt
|
||||||
|
id: ruff-action
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
src: __tests__/fixtures/python-project
|
||||||
|
version-file: __tests__/fixtures/requirements.txt
|
||||||
|
- name: Correct version gets installed
|
||||||
|
run: |
|
||||||
|
if [ "$RUFF_VERSION" != "0.9.0" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
env:
|
||||||
|
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
||||||
|
test-default-version-from-requirements-with-hash:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Use default version from requirements-with-hash.txt
|
||||||
|
id: ruff-action
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
src: __tests__/fixtures/python-project
|
||||||
|
version-file: __tests__/fixtures/requirements-with-hash.txt
|
||||||
|
- name: Correct version gets installed
|
||||||
|
run: |
|
||||||
|
if [ "$RUFF_VERSION" != "0.9.0" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
env:
|
||||||
|
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
||||||
test-semver-range:
|
test-semver-range:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Use version 0.7
|
- name: Use version 0.7
|
||||||
id: ruff-action
|
id: ruff-action
|
||||||
uses: ./
|
uses: ./
|
||||||
@@ -68,31 +299,50 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
env:
|
env:
|
||||||
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
||||||
|
test-pep440-version-specifier:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Install version 0.9.10
|
||||||
|
id: ruff-action
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
version: ">=0.9.9,<0.10.0"
|
||||||
|
src: __tests__/fixtures/python-project
|
||||||
|
- name: Correct version gets installed
|
||||||
|
run: |
|
||||||
|
if [ "$RUFF_VERSION" != "0.9.10" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
env:
|
||||||
|
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
||||||
test-checksum:
|
test-checksum:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.inputs.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, macos-latest]
|
inputs:
|
||||||
checksum:
|
- os: ubuntu-latest
|
||||||
["0de731c669b9ece77e799ac3f4a160c30849752714d9775c94cc4cfaf326860c"]
|
|
||||||
exclude:
|
|
||||||
- os: macos-latest
|
|
||||||
checksum: "0de731c669b9ece77e799ac3f4a160c30849752714d9775c94cc4cfaf326860c"
|
checksum: "0de731c669b9ece77e799ac3f4a160c30849752714d9775c94cc4cfaf326860c"
|
||||||
include:
|
|
||||||
- os: macos-latest
|
- os: macos-latest
|
||||||
checksum: "af9583bff12afbca5d5670334e0187dd60c4d91bc71317d1b2dde70cb1200ba9"
|
checksum: "af9583bff12afbca5d5670334e0187dd60c4d91bc71317d1b2dde70cb1200ba9"
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Checksum matches expected
|
- name: Checksum matches expected
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
version: "0.7.4"
|
version: "0.7.4"
|
||||||
checksum: ${{ matrix.checksum }}
|
checksum: ${{ matrix.inputs.checksum }}
|
||||||
src: __tests__/fixtures/python-project
|
src: __tests__/fixtures/python-project
|
||||||
test-with-explicit-token:
|
test-with-explicit-token:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Use default version
|
- name: Use default version
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -104,7 +354,9 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest]
|
os: [ubuntu-latest, windows-latest]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Use args
|
- name: Use args
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -113,9 +365,11 @@ jobs:
|
|||||||
test-failure:
|
test-failure:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
- name: Use args
|
with:
|
||||||
id: should-fail
|
persist-credentials: false
|
||||||
|
- name: Format should fail
|
||||||
|
id: format-should-fail
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -123,16 +377,33 @@ jobs:
|
|||||||
src: __tests__/fixtures/malformed-python-project
|
src: __tests__/fixtures/malformed-python-project
|
||||||
- name: Check if the action failed
|
- name: Check if the action failed
|
||||||
run: |
|
run: |
|
||||||
if [ ${{ steps.should-fail.outcome }} == "success" ]; then
|
if [ "${FORMAT_SHOULD_FAIL_OUTCOME}" == "success" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
env:
|
||||||
|
FORMAT_SHOULD_FAIL_OUTCOME: ${{ steps.format-should-fail.outcome }}
|
||||||
|
- name: Check should fail
|
||||||
|
id: check-should-fail
|
||||||
|
continue-on-error: true
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
src: __tests__/fixtures/malformed-python-project
|
||||||
|
- name: Check if the action failed
|
||||||
|
run: |
|
||||||
|
if [ "${CHECK_SHOULD_FAIL_OUTCOME}" == "success" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
env:
|
||||||
|
CHECK_SHOULD_FAIL_OUTCOME: ${{ steps.check-should-fail.outcome }}
|
||||||
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@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
- name: Use args
|
- name: Use args
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -140,3 +411,81 @@ jobs:
|
|||||||
src: >-
|
src: >-
|
||||||
__tests__/fixtures/python-project/src/python_project/__init__.py
|
__tests__/fixtures/python-project/src/python_project/__init__.py
|
||||||
__tests__/fixtures/python-project/src/python_project/hello_world.py
|
__tests__/fixtures/python-project/src/python_project/hello_world.py
|
||||||
|
test-parent-directory-pyproject:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Use version from parent directory pyproject.toml
|
||||||
|
id: ruff-action
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
src: __tests__/fixtures/parent-config-project/subproject
|
||||||
|
- name: Correct version gets installed
|
||||||
|
run: |
|
||||||
|
if [ "$RUFF_VERSION" != "0.10.0" ]; then
|
||||||
|
echo "Expected version 0.10.0 but got $RUFF_VERSION"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
env:
|
||||||
|
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
||||||
|
|
||||||
|
test-custom-manifest-file:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Create test src
|
||||||
|
run: |
|
||||||
|
mkdir -p "${{ runner.temp }}/ruff-manifest-test"
|
||||||
|
printf 'print("hello")\n' > "${{ runner.temp }}/ruff-manifest-test/hello.py"
|
||||||
|
- name: Install from custom manifest file
|
||||||
|
id: ruff-action
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
src: ${{ runner.temp }}/ruff-manifest-test
|
||||||
|
manifest-file: "https://raw.githubusercontent.com/astral-sh/ruff-action/${{ github.ref }}/__tests__/download/custom-manifest.ndjson"
|
||||||
|
- name: Correct version gets installed
|
||||||
|
run: |
|
||||||
|
if [ "$RUFF_VERSION" != "0.15.10" ]; then
|
||||||
|
echo "Wrong ruff version: $RUFF_VERSION"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
env:
|
||||||
|
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
|
||||||
|
|
||||||
|
all-tests-passed:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs:
|
||||||
|
- lint
|
||||||
|
- test-latest-version
|
||||||
|
- test-specific-version
|
||||||
|
- test-unsupported-version
|
||||||
|
- test-version-from-version-file-pyproject
|
||||||
|
- test-default-version-from-pyproject
|
||||||
|
- test-default-version-from-pyproject-dev-group
|
||||||
|
- test-default-version-from-pyproject-dependency-groups
|
||||||
|
- test-default-version-from-pyproject-dependency-groups-with-env-marker
|
||||||
|
- test-default-version-from-pyproject-poetry-groups
|
||||||
|
- test-default-version-from-pyproject-poetry
|
||||||
|
- test-default-version-from-pyproject-optional-dependencies
|
||||||
|
- test-default-version-from-requirements
|
||||||
|
- test-default-version-from-requirements-with-hash
|
||||||
|
- test-semver-range
|
||||||
|
- test-pep440-version-specifier
|
||||||
|
- test-checksum
|
||||||
|
- test-with-explicit-token
|
||||||
|
- test-args
|
||||||
|
- test-failure
|
||||||
|
- test-multiple-src
|
||||||
|
- test-parent-directory-pyproject
|
||||||
|
- test-custom-manifest-file
|
||||||
|
if: always()
|
||||||
|
steps:
|
||||||
|
- name: All tests passed
|
||||||
|
run: |
|
||||||
|
echo "All jobs passed: ${{ !(contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) }}"
|
||||||
|
# shellcheck disable=SC2242
|
||||||
|
exit ${{ (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) && 1 || 0 }}
|
||||||
|
|||||||
@@ -1,23 +1,31 @@
|
|||||||
name: "Update known checksums"
|
name: "Update known checksums"
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
schedule:
|
||||||
|
- cron: "0 4 * * *" # Run every day at 4am UTC
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
pull-requests: write
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
- uses: actions/setup-node@v4
|
|
||||||
with:
|
with:
|
||||||
node-version: "20"
|
persist-credentials: false
|
||||||
|
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
|
||||||
|
with:
|
||||||
|
node-version-file: .nvmrc
|
||||||
|
cache: npm
|
||||||
- name: Update known checksums
|
- name: Update known checksums
|
||||||
id: update-known-checksums
|
id: update-known-checksums
|
||||||
run:
|
run:
|
||||||
node dist/update-known-checksums/index.js
|
node dist/update-known-checksums/index.cjs
|
||||||
src/download/checksum/known-checksums.ts ${{ secrets.GITHUB_TOKEN }}
|
src/download/checksum/known-checksums.ts ${{ secrets.GITHUB_TOKEN }}
|
||||||
- run: npm install && npm run all
|
- run: npm ci --ignore-scripts && npm run all
|
||||||
- name: Create Pull Request
|
- name: Create Pull Request
|
||||||
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5
|
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
|
||||||
with:
|
with:
|
||||||
commit-message: "chore: update known checksums"
|
commit-message: "chore: update known checksums"
|
||||||
title:
|
title:
|
||||||
|
|||||||
@@ -13,7 +13,38 @@ jobs:
|
|||||||
update_major_minor_tags:
|
update_major_minor_tags:
|
||||||
name: Make sure major and minor tags are up to date on a patch release
|
name: Make sure major and minor tags are up to date on a patch release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
- name: Run Update semver
|
with:
|
||||||
uses: haya14busa/action-update-semver@v1.2.1
|
persist-credentials: true
|
||||||
|
- name: Update Major Minor Tags
|
||||||
|
run: |
|
||||||
|
set -x
|
||||||
|
|
||||||
|
cd "${GITHUB_WORKSPACE}" || exit
|
||||||
|
|
||||||
|
# Set up variables.
|
||||||
|
TAG="${GITHUB_REF#refs/tags/}" # v1.2.3
|
||||||
|
MINOR="${TAG%.*}" # v1.2
|
||||||
|
MAJOR="${MINOR%.*}" # v1
|
||||||
|
|
||||||
|
if [ "${GITHUB_REF}" = "${TAG}" ]; then
|
||||||
|
echo "This workflow is not triggered by tag push: GITHUB_REF=${GITHUB_REF}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
MESSAGE="Release ${TAG}"
|
||||||
|
|
||||||
|
# Set up Git.
|
||||||
|
git config user.name "${GITHUB_ACTOR}"
|
||||||
|
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
|
||||||
|
|
||||||
|
# Update MAJOR/MINOR tag
|
||||||
|
git tag -fa "${MAJOR}" -m "${MESSAGE}"
|
||||||
|
git tag -fa "${MINOR}" -m "${MESSAGE}"
|
||||||
|
|
||||||
|
# Push
|
||||||
|
git push --force origin "${MINOR}"
|
||||||
|
git push --force origin "${MAJOR}"
|
||||||
|
|||||||
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"recommendations": ["biomejs.biome"]
|
||||||
|
}
|
||||||
Vendored
+16
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"editor.codeActionsOnSave": {
|
||||||
|
"source.action.useSortedAttributes.biome": "explicit",
|
||||||
|
"source.action.useSortedKeys.biome": "explicit",
|
||||||
|
"source.fixAll.biome": "explicit"
|
||||||
|
},
|
||||||
|
"editor.defaultFormatter": "biomejs.biome",
|
||||||
|
"editor.formatOnSave": true,
|
||||||
|
"explorer.excludeGitIgnore": false,
|
||||||
|
"search.defaultViewMode": "list",
|
||||||
|
"search.exclude": {
|
||||||
|
"**/node_modules": true
|
||||||
|
},
|
||||||
|
"typescript.enablePromptUseWorkspaceTsdk": true,
|
||||||
|
"typescript.tsdk": "node_modules/typescript/lib"
|
||||||
|
}
|
||||||
@@ -4,8 +4,8 @@ A GitHub Action to run [ruff](https://github.com/astral-sh/ruff).
|
|||||||
|
|
||||||
This action is commonly used as a pass/fail test to ensure your repository stays
|
This action is commonly used as a pass/fail test to ensure your repository stays
|
||||||
clean, abiding the [rules](https://docs.astral.sh/ruff/rules/) specified in your
|
clean, abiding the [rules](https://docs.astral.sh/ruff/rules/) specified in your
|
||||||
configuration. Though it runs `ruff`, the action can do anything `ruff` can (ex,
|
configuration. Though it runs `ruff check` by default, the action can do
|
||||||
fix).
|
anything `ruff` can (ex, fix).
|
||||||
|
|
||||||
## Contents
|
## Contents
|
||||||
|
|
||||||
@@ -16,33 +16,40 @@ fix).
|
|||||||
- [Use to install ruff](#use-to-install-ruff)
|
- [Use to install ruff](#use-to-install-ruff)
|
||||||
- [Use `ruff format`](#use-ruff-format)
|
- [Use `ruff format`](#use-ruff-format)
|
||||||
- [Install specific versions](#install-specific-versions)
|
- [Install specific versions](#install-specific-versions)
|
||||||
- [Install the latest version (default)](#install-the-latest-version-default)
|
- [Install the latest version](#install-the-latest-version)
|
||||||
- [Install a specific version](#install-a-specific-version)
|
- [Install a specific version](#install-a-specific-version)
|
||||||
- [Install a version by supplying a semver range](#install-a-version-by-supplying-a-semver-range)
|
- [Install a version by supplying a semver range or pep440 specifier](#install-a-version-by-supplying-a-semver-range-or-pep440-specifier)
|
||||||
|
- [Install a version from a specified version file](#install-a-version-from-a-specified-version-file)
|
||||||
|
- [Install using a custom manifest URL](#install-using-a-custom-manifest-url)
|
||||||
- [Validate checksum](#validate-checksum)
|
- [Validate checksum](#validate-checksum)
|
||||||
- [GitHub authentication token](#github-authentication-token)
|
- [GitHub authentication token](#github-authentication-token)
|
||||||
- [Outputs](#outputs)
|
- [Outputs](#outputs)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
| Input | Description | Default |
|
| Input | Description | Default |
|
||||||
|----------------|---------------------------------------------------------------------------------------------|--------------------|
|
|-----------------|--------------------------------------------------------------------------------------------------------------------------------------------|--------------------|
|
||||||
| `version` | The version of Ruff to install. See [Install specific versions](#install-specific-versions) | `latest` |
|
| `version` | The version of Ruff to install. See [Install specific versions](#install-specific-versions) | discovered from `pyproject.toml`, else `latest` |
|
||||||
| `args` | The arguments to pass to the `ruff` command. See [Configuring Ruff] | `check` |
|
| `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 |
|
||||||
| `src` | The directory or single files to run `ruff` on. | [github.workspace] |
|
| `manifest-file` | URL to a custom Ruff manifest in the `astral-sh/versions` format. | None |
|
||||||
| `checksum` | The sha256 checksum of the downloaded executable. | None |
|
| `args` | The arguments to pass to the `ruff` command. See [Configuring Ruff] | `check` |
|
||||||
| `github-token` | The GitHub token to use for authentication. | `GITHUB_TOKEN` |
|
| `src` | The directory or single files to run `ruff` on. | [github.workspace] |
|
||||||
|
| `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` |
|
||||||
|
|
||||||
|
By default, Ruff version metadata is resolved from the
|
||||||
|
[`astral-sh/versions` Ruff manifest](https://github.com/astral-sh/versions/blob/main/v1/ruff.ndjson).
|
||||||
|
|
||||||
### Basic
|
### Basic
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: astral-sh/ruff-action@v2
|
- uses: astral-sh/ruff-action@v3
|
||||||
```
|
```
|
||||||
|
|
||||||
### Specify a different source directory
|
### Specify a different source directory
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: astral-sh/ruff-action@v1
|
- uses: astral-sh/ruff-action@v3
|
||||||
with:
|
with:
|
||||||
src: "./src"
|
src: "./src"
|
||||||
```
|
```
|
||||||
@@ -50,7 +57,7 @@ fix).
|
|||||||
### Specify multiple files
|
### Specify multiple files
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: astral-sh/ruff-action@v1
|
- uses: astral-sh/ruff-action@v3
|
||||||
with:
|
with:
|
||||||
src: >-
|
src: >-
|
||||||
path/to/file1.py
|
path/to/file1.py
|
||||||
@@ -62,64 +69,118 @@ fix).
|
|||||||
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@v1
|
- uses: astral-sh/ruff-action@v3
|
||||||
- run: ruff check --fix
|
- run: ruff check --fix
|
||||||
- run: ruff format
|
- run: ruff format
|
||||||
```
|
```
|
||||||
|
|
||||||
|
By default, this action runs `ruff check` after installation.
|
||||||
|
If you do not want to run any `ruff` command but only install it,
|
||||||
|
you can use the `args` input to overwrite the default value (`check`):
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- name: Install ruff without running check or format
|
||||||
|
uses: astral-sh/ruff-action@v3
|
||||||
|
with:
|
||||||
|
args: "--version"
|
||||||
|
```
|
||||||
|
|
||||||
### Use `ruff format`
|
### Use `ruff format`
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: astral-sh/ruff-action@v1
|
- uses: astral-sh/ruff-action@v3
|
||||||
with:
|
with:
|
||||||
args: "format --check"
|
args: "format --check --diff"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Install specific versions
|
### Install specific versions
|
||||||
|
|
||||||
#### Install the latest version (default)
|
By default this action searches upward from `src` until the workspace root to find the nearest
|
||||||
|
`pyproject.toml` and determine the Ruff version to install. If no `pyproject.toml` file is found,
|
||||||
|
or no Ruff version is defined in `project.dependencies`, `project.optional-dependencies`,
|
||||||
|
`dependency-groups`, or supported Poetry dependency tables, the latest version is installed.
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> This action does only support ruff versions v0.0.247 and above.
|
||||||
|
|
||||||
|
#### Install the latest version
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Install the latest version of ruff
|
- name: Install the latest version of ruff
|
||||||
uses: astral-sh/ruff-action@v2
|
uses: astral-sh/ruff-action@v3
|
||||||
with:
|
with:
|
||||||
version: "latest"
|
version: "latest"
|
||||||
```
|
```
|
||||||
|
|
||||||
> [!TIP]
|
#### Install a specific version
|
||||||
>
|
|
||||||
> Using `latest` requires to download the ruff executable on every run, which incurs a cost
|
|
||||||
> (especially on self-hosted runners). As a best practice, consider pinning the version to a
|
|
||||||
> specific release.
|
|
||||||
|
|
||||||
### Install a specific version
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Install a specific version of ruff
|
- name: Install a specific version of ruff
|
||||||
uses: astral-sh/ruff-action@v2
|
uses: astral-sh/ruff-action@v3
|
||||||
with:
|
with:
|
||||||
version: "0.4.4"
|
version: "0.4.4"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Install a version by supplying a semver range
|
#### Install a version by supplying a semver range or pep440 specifier
|
||||||
|
|
||||||
You can specify a [semver range](https://github.com/npm/node-semver?tab=readme-ov-file#ranges)
|
You can specify a [semver range](https://github.com/npm/node-semver?tab=readme-ov-file#ranges)
|
||||||
|
or [pep440 specifier](https://peps.python.org/pep-0440/#version-specifiers)
|
||||||
to install the latest version that satisfies the range.
|
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@v2
|
uses: astral-sh/ruff-action@v3
|
||||||
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@v2
|
uses: astral-sh/ruff-action@v3
|
||||||
with:
|
with:
|
||||||
version: "0.4.x"
|
version: "0.4.x"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- name: Install a pep440-specifier-satisfying version of ruff
|
||||||
|
uses: astral-sh/ruff-action@v3
|
||||||
|
with:
|
||||||
|
version: ">=0.11.10,<0.12.0"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Install a version from a specified version file
|
||||||
|
|
||||||
|
You can specify a file to read the version from.
|
||||||
|
Currently `pyproject.toml` and `requirements.txt` are supported. If the file cannot be parsed
|
||||||
|
or does not contain a Ruff version, the action warns and falls back to `latest`.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- name: Install a version from a specified version file
|
||||||
|
uses: astral-sh/ruff-action@v3
|
||||||
|
with:
|
||||||
|
version-file: "my-path/to/pyproject.toml-or-requirements.txt"
|
||||||
|
```
|
||||||
|
|
||||||
|
Version resolution precedence is:
|
||||||
|
|
||||||
|
1. `version`
|
||||||
|
2. `version-file`
|
||||||
|
3. nearest discoverable `pyproject.toml` found by searching upward from `src`
|
||||||
|
4. `latest`
|
||||||
|
|
||||||
|
#### Install using a custom manifest URL
|
||||||
|
|
||||||
|
You can override the default `astral-sh/versions` manifest with `manifest-file`.
|
||||||
|
This affects both version resolution and artifact selection.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- name: Install Ruff from a custom manifest
|
||||||
|
uses: astral-sh/ruff-action@v3
|
||||||
|
with:
|
||||||
|
version: "latest"
|
||||||
|
manifest-file: "https://example.com/ruff.ndjson"
|
||||||
|
```
|
||||||
|
|
||||||
### Validate checksum
|
### Validate checksum
|
||||||
|
|
||||||
You can specify a checksum to validate the downloaded executable. Checksums up to the default version
|
You can specify a checksum to validate the downloaded executable. Checksums up to the default version
|
||||||
@@ -128,7 +189,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@v2
|
uses: astral-sh/ruff-action@v3
|
||||||
with:
|
with:
|
||||||
version: "0.7.4"
|
version: "0.7.4"
|
||||||
checksum: "0de731c669b9ece77e799ac3f4a160c30849752714d9775c94cc4cfaf326860c"
|
checksum: "0de731c669b9ece77e799ac3f4a160c30849752714d9775c94cc4cfaf326860c"
|
||||||
@@ -136,9 +197,11 @@ are automatically verified by this action. The sha256 hashes can be found on the
|
|||||||
|
|
||||||
### GitHub authentication token
|
### GitHub authentication token
|
||||||
|
|
||||||
This action uses the GitHub API to fetch the ruff release artifacts. To avoid hitting the GitHub API
|
By default, this action resolves available uv versions from
|
||||||
rate limit too quickly, an authentication token can be provided via the `github-token` input. By
|
[`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.
|
||||||
default, the `GITHUB_TOKEN` secret is used, which is automatically provided by GitHub Actions.
|
|
||||||
|
You can provide a token via `github-token` to authenticate those downloads. By default, the
|
||||||
|
`GITHUB_TOKEN` secret is used, which is automatically provided by GitHub Actions.
|
||||||
|
|
||||||
If the default
|
If the default
|
||||||
[permissions for the GitHub token](https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#permissions-for-the-github_token)
|
[permissions for the GitHub token](https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#permissions-for-the-github_token)
|
||||||
@@ -146,7 +209,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@v2
|
uses: astral-sh/ruff-action@v3
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
|
github-token: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
{"version":"0.15.10","artifacts":[{"platform":"x86_64-unknown-linux-gnu","variant":"default","url":"https://github.com/astral-sh/ruff/releases/download/0.15.10/ruff-x86_64-unknown-linux-gnu.tar.gz","archive_format":"tar.gz","sha256":"e3e9e5c791542f00d95edc74a506e1ac24efc0af9574de01ab338187bf1ff9f6"}]}
|
||||||
@@ -0,0 +1,511 @@
|
|||||||
|
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
|
||||||
|
import * as semver from "semver";
|
||||||
|
|
||||||
|
const mockInfo = jest.fn();
|
||||||
|
const mockWarning = jest.fn();
|
||||||
|
|
||||||
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
|
debug: jest.fn(),
|
||||||
|
info: mockInfo,
|
||||||
|
warning: mockWarning,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const mockDownloadTool = jest.fn();
|
||||||
|
const mockExtractTar = jest.fn();
|
||||||
|
const mockExtractZip = jest.fn();
|
||||||
|
const mockCacheDir = jest.fn();
|
||||||
|
|
||||||
|
jest.unstable_mockModule("@actions/tool-cache", () => ({
|
||||||
|
cacheDir: mockCacheDir,
|
||||||
|
downloadTool: mockDownloadTool,
|
||||||
|
evaluateVersions: (versions: string[], range: string) =>
|
||||||
|
semver.maxSatisfying(versions, range) ?? "",
|
||||||
|
extractTar: mockExtractTar,
|
||||||
|
extractZip: mockExtractZip,
|
||||||
|
find: () => "",
|
||||||
|
findAllVersions: () => [],
|
||||||
|
isExplicitVersion: (version: string) => semver.valid(version) !== null,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const mockGetLatestVersion = jest.fn();
|
||||||
|
const mockGetAllVersions = jest.fn();
|
||||||
|
const mockGetArtifact = jest.fn();
|
||||||
|
|
||||||
|
jest.unstable_mockModule("../../src/download/manifest", () => ({
|
||||||
|
getAllVersions: mockGetAllVersions,
|
||||||
|
getArtifact: mockGetArtifact,
|
||||||
|
getLatestVersion: mockGetLatestVersion,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const mockValidateChecksum = jest.fn();
|
||||||
|
|
||||||
|
jest.unstable_mockModule("../../src/download/checksum/checksum", () => ({
|
||||||
|
validateChecksum: mockValidateChecksum,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const mockCopyFile = jest.fn();
|
||||||
|
const mockReaddir = jest.fn();
|
||||||
|
|
||||||
|
jest.unstable_mockModule("node:fs", () => ({
|
||||||
|
default: {},
|
||||||
|
promises: {
|
||||||
|
copyFile: mockCopyFile,
|
||||||
|
readdir: mockReaddir,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
const { downloadVersion, rewriteToMirror } = await import(
|
||||||
|
"../../src/download/download-version"
|
||||||
|
);
|
||||||
|
const { resolveVersion } = await import("../../src/version/resolve");
|
||||||
|
|
||||||
|
describe("download-version", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mockInfo.mockReset();
|
||||||
|
mockWarning.mockReset();
|
||||||
|
mockDownloadTool.mockReset();
|
||||||
|
mockExtractTar.mockReset();
|
||||||
|
mockExtractZip.mockReset();
|
||||||
|
mockCacheDir.mockReset();
|
||||||
|
mockGetLatestVersion.mockReset();
|
||||||
|
mockGetAllVersions.mockReset();
|
||||||
|
mockGetArtifact.mockReset();
|
||||||
|
mockValidateChecksum.mockReset();
|
||||||
|
mockCopyFile.mockReset();
|
||||||
|
mockReaddir.mockReset();
|
||||||
|
|
||||||
|
mockDownloadTool.mockResolvedValue("/tmp/downloaded");
|
||||||
|
mockExtractTar.mockResolvedValue("/tmp/extracted");
|
||||||
|
mockExtractZip.mockResolvedValue("/tmp/extracted");
|
||||||
|
mockCacheDir.mockResolvedValue("/tmp/cached");
|
||||||
|
mockReaddir.mockResolvedValue(["ruff"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("resolveVersion", () => {
|
||||||
|
it("uses the default manifest to resolve latest", async () => {
|
||||||
|
mockGetLatestVersion.mockResolvedValue("0.15.8");
|
||||||
|
|
||||||
|
const version = await resolveVersion("latest", undefined);
|
||||||
|
|
||||||
|
expect(version).toBe("0.15.8");
|
||||||
|
expect(mockGetLatestVersion).toHaveBeenCalledTimes(1);
|
||||||
|
expect(mockGetLatestVersion).toHaveBeenCalledWith(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses the default manifest to resolve available versions", async () => {
|
||||||
|
mockGetAllVersions.mockResolvedValue(["0.15.8", "0.15.7"]);
|
||||||
|
|
||||||
|
const version = await resolveVersion("0.15.x", undefined);
|
||||||
|
|
||||||
|
expect(version).toBe("0.15.8");
|
||||||
|
expect(mockGetAllVersions).toHaveBeenCalledTimes(1);
|
||||||
|
expect(mockGetAllVersions).toHaveBeenCalledWith(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses manifest-file when provided", async () => {
|
||||||
|
mockGetAllVersions.mockResolvedValue(["0.15.8", "0.15.7"]);
|
||||||
|
|
||||||
|
const version = await resolveVersion(
|
||||||
|
"0.15.x",
|
||||||
|
"https://example.com/custom.ndjson",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(version).toBe("0.15.8");
|
||||||
|
expect(mockGetAllVersions).toHaveBeenCalledWith(
|
||||||
|
"https://example.com/custom.ndjson",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("downloadVersion", () => {
|
||||||
|
it("fails when manifest lookup fails", async () => {
|
||||||
|
mockGetArtifact.mockRejectedValue(new Error("manifest unavailable"));
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
downloadVersion(
|
||||||
|
"unknown-linux-gnu",
|
||||||
|
"x86_64",
|
||||||
|
"0.15.8",
|
||||||
|
undefined,
|
||||||
|
"token",
|
||||||
|
),
|
||||||
|
).rejects.toThrow("manifest unavailable");
|
||||||
|
|
||||||
|
expect(mockDownloadTool).not.toHaveBeenCalled();
|
||||||
|
expect(mockValidateChecksum).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("fails when no matching artifact exists in the default manifest", async () => {
|
||||||
|
mockGetArtifact.mockResolvedValue(undefined);
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
downloadVersion(
|
||||||
|
"unknown-linux-gnu",
|
||||||
|
"x86_64",
|
||||||
|
"0.15.8",
|
||||||
|
undefined,
|
||||||
|
"token",
|
||||||
|
),
|
||||||
|
).rejects.toThrow(
|
||||||
|
"Could not find artifact for version 0.15.8, arch x86_64, platform unknown-linux-gnu in https://raw.githubusercontent.com/astral-sh/versions/main/v1/ruff.ndjson .",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(mockDownloadTool).not.toHaveBeenCalled();
|
||||||
|
expect(mockValidateChecksum).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses built-in checksums for default manifest downloads", async () => {
|
||||||
|
mockGetArtifact.mockResolvedValue({
|
||||||
|
archiveFormat: "tar.gz",
|
||||||
|
checksum: "manifest-checksum-that-should-be-ignored",
|
||||||
|
downloadUrl: "https://example.com/ruff.tar.gz",
|
||||||
|
});
|
||||||
|
|
||||||
|
await downloadVersion(
|
||||||
|
"unknown-linux-gnu",
|
||||||
|
"x86_64",
|
||||||
|
"0.15.8",
|
||||||
|
undefined,
|
||||||
|
"token",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(mockValidateChecksum).toHaveBeenCalledWith(
|
||||||
|
undefined,
|
||||||
|
"/tmp/downloaded",
|
||||||
|
"x86_64",
|
||||||
|
"unknown-linux-gnu",
|
||||||
|
"0.15.8",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("rewrites GitHub Releases URLs to the Astral mirror", 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",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(mockDownloadTool).toHaveBeenCalledWith(
|
||||||
|
"https://releases.astral.sh/github/ruff/releases/download/0.15.8/ruff-x86_64-unknown-linux-gnu.tar.gz",
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not rewrite non-GitHub URLs", async () => {
|
||||||
|
mockGetArtifact.mockResolvedValue({
|
||||||
|
archiveFormat: "tar.gz",
|
||||||
|
checksum: "abc123",
|
||||||
|
downloadUrl: "https://example.com/ruff.tar.gz",
|
||||||
|
});
|
||||||
|
|
||||||
|
await downloadVersion(
|
||||||
|
"unknown-linux-gnu",
|
||||||
|
"x86_64",
|
||||||
|
"0.15.8",
|
||||||
|
undefined,
|
||||||
|
"token",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(mockDownloadTool).toHaveBeenCalledWith(
|
||||||
|
"https://example.com/ruff.tar.gz",
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("falls back to GitHub Releases when the mirror download fails", 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",
|
||||||
|
});
|
||||||
|
|
||||||
|
mockDownloadTool
|
||||||
|
.mockRejectedValueOnce(new Error("mirror unavailable"))
|
||||||
|
.mockResolvedValueOnce("/tmp/downloaded");
|
||||||
|
|
||||||
|
await downloadVersion(
|
||||||
|
"unknown-linux-gnu",
|
||||||
|
"x86_64",
|
||||||
|
"0.15.8",
|
||||||
|
undefined,
|
||||||
|
"token",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(mockDownloadTool).toHaveBeenCalledTimes(2);
|
||||||
|
expect(mockDownloadTool).toHaveBeenNthCalledWith(
|
||||||
|
1,
|
||||||
|
"https://releases.astral.sh/github/ruff/releases/download/0.15.8/ruff-x86_64-unknown-linux-gnu.tar.gz",
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
|
expect(mockDownloadTool).toHaveBeenNthCalledWith(
|
||||||
|
2,
|
||||||
|
"https://github.com/astral-sh/ruff/releases/download/0.15.8/ruff-x86_64-unknown-linux-gnu.tar.gz",
|
||||||
|
undefined,
|
||||||
|
"token",
|
||||||
|
);
|
||||||
|
expect(mockWarning).toHaveBeenCalledWith(
|
||||||
|
"Failed to download from mirror, falling back to GitHub Releases: mirror unavailable",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("falls back to the canonical old GitHub Releases URL", async () => {
|
||||||
|
mockGetArtifact.mockResolvedValue({
|
||||||
|
archiveFormat: "tar.gz",
|
||||||
|
checksum: "abc123",
|
||||||
|
downloadUrl:
|
||||||
|
"https://github.com/astral-sh/ruff/releases/download/0.4.7/ruff-x86_64-unknown-linux-gnu.tar.gz",
|
||||||
|
});
|
||||||
|
|
||||||
|
mockDownloadTool
|
||||||
|
.mockRejectedValueOnce(new Error("mirror unavailable"))
|
||||||
|
.mockResolvedValueOnce("/tmp/downloaded");
|
||||||
|
|
||||||
|
await downloadVersion(
|
||||||
|
"unknown-linux-gnu",
|
||||||
|
"x86_64",
|
||||||
|
"0.4.7",
|
||||||
|
undefined,
|
||||||
|
"token",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(mockDownloadTool).toHaveBeenNthCalledWith(
|
||||||
|
2,
|
||||||
|
"https://github.com/astral-sh/ruff/releases/download/v0.4.7/ruff-0.4.7-x86_64-unknown-linux-gnu.tar.gz",
|
||||||
|
undefined,
|
||||||
|
"token",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not fall back when checksum validation fails", 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",
|
||||||
|
});
|
||||||
|
mockValidateChecksum.mockRejectedValue(new Error("bad checksum"));
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
downloadVersion(
|
||||||
|
"unknown-linux-gnu",
|
||||||
|
"x86_64",
|
||||||
|
"0.15.8",
|
||||||
|
undefined,
|
||||||
|
"token",
|
||||||
|
),
|
||||||
|
).rejects.toThrow("bad checksum");
|
||||||
|
|
||||||
|
expect(mockDownloadTool).toHaveBeenCalledTimes(1);
|
||||||
|
expect(mockWarning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not fall back when extraction fails", 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",
|
||||||
|
});
|
||||||
|
mockExtractTar.mockRejectedValue(new Error("extract failed"));
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
downloadVersion(
|
||||||
|
"unknown-linux-gnu",
|
||||||
|
"x86_64",
|
||||||
|
"0.15.8",
|
||||||
|
undefined,
|
||||||
|
"token",
|
||||||
|
),
|
||||||
|
).rejects.toThrow("extract failed");
|
||||||
|
|
||||||
|
expect(mockDownloadTool).toHaveBeenCalledTimes(1);
|
||||||
|
expect(mockWarning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not fall back for non-GitHub URLs", async () => {
|
||||||
|
mockGetArtifact.mockResolvedValue({
|
||||||
|
archiveFormat: "tar.gz",
|
||||||
|
checksum: "abc123",
|
||||||
|
downloadUrl: "https://example.com/ruff.tar.gz",
|
||||||
|
});
|
||||||
|
|
||||||
|
mockDownloadTool.mockRejectedValue(new Error("download failed"));
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
downloadVersion(
|
||||||
|
"unknown-linux-gnu",
|
||||||
|
"x86_64",
|
||||||
|
"0.15.8",
|
||||||
|
undefined,
|
||||||
|
"token",
|
||||||
|
),
|
||||||
|
).rejects.toThrow("download failed");
|
||||||
|
|
||||||
|
expect(mockDownloadTool).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses manifest-file checksum metadata when checksum input is unset", async () => {
|
||||||
|
mockGetArtifact.mockResolvedValue({
|
||||||
|
archiveFormat: "tar.gz",
|
||||||
|
checksum: "manifest-checksum",
|
||||||
|
downloadUrl: "https://example.com/custom-ruff.tar.gz",
|
||||||
|
});
|
||||||
|
|
||||||
|
await downloadVersion(
|
||||||
|
"unknown-linux-gnu",
|
||||||
|
"x86_64",
|
||||||
|
"0.15.8",
|
||||||
|
"",
|
||||||
|
"token",
|
||||||
|
"https://example.com/custom.ndjson",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(mockValidateChecksum).toHaveBeenCalledWith(
|
||||||
|
"manifest-checksum",
|
||||||
|
"/tmp/downloaded",
|
||||||
|
"x86_64",
|
||||||
|
"unknown-linux-gnu",
|
||||||
|
"0.15.8",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("prefers checksum input over manifest-file checksum metadata", async () => {
|
||||||
|
mockGetArtifact.mockResolvedValue({
|
||||||
|
archiveFormat: "tar.gz",
|
||||||
|
checksum: "manifest-checksum",
|
||||||
|
downloadUrl: "https://example.com/custom-ruff.tar.gz",
|
||||||
|
});
|
||||||
|
|
||||||
|
await downloadVersion(
|
||||||
|
"unknown-linux-gnu",
|
||||||
|
"x86_64",
|
||||||
|
"0.15.8",
|
||||||
|
"user-checksum",
|
||||||
|
"token",
|
||||||
|
"https://example.com/custom.ndjson",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(mockValidateChecksum).toHaveBeenCalledWith(
|
||||||
|
"user-checksum",
|
||||||
|
"/tmp/downloaded",
|
||||||
|
"x86_64",
|
||||||
|
"unknown-linux-gnu",
|
||||||
|
"0.15.8",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("preserves tar extraction behavior for newer versions", async () => {
|
||||||
|
mockGetArtifact.mockResolvedValue({
|
||||||
|
archiveFormat: "tar.gz",
|
||||||
|
checksum: "abc123",
|
||||||
|
downloadUrl: "https://example.com/ruff.tar.gz",
|
||||||
|
});
|
||||||
|
|
||||||
|
await downloadVersion(
|
||||||
|
"unknown-linux-gnu",
|
||||||
|
"x86_64",
|
||||||
|
"0.15.8",
|
||||||
|
"user-checksum",
|
||||||
|
"token",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(mockExtractTar).toHaveBeenCalledWith("/tmp/downloaded");
|
||||||
|
expect(mockCacheDir).toHaveBeenCalledWith(
|
||||||
|
"/tmp/extracted/ruff-x86_64-unknown-linux-gnu",
|
||||||
|
"ruff",
|
||||||
|
"0.15.8",
|
||||||
|
"x86_64",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("preserves tar extraction behavior for older versions", async () => {
|
||||||
|
mockGetArtifact.mockResolvedValue({
|
||||||
|
archiveFormat: "tar.gz",
|
||||||
|
checksum: "abc123",
|
||||||
|
downloadUrl: "https://example.com/ruff.tar.gz",
|
||||||
|
});
|
||||||
|
|
||||||
|
await downloadVersion(
|
||||||
|
"unknown-linux-gnu",
|
||||||
|
"x86_64",
|
||||||
|
"0.4.10",
|
||||||
|
undefined,
|
||||||
|
"token",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(mockCacheDir).toHaveBeenCalledWith(
|
||||||
|
"/tmp/extracted",
|
||||||
|
"ruff",
|
||||||
|
"0.4.10",
|
||||||
|
"x86_64",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("preserves zip extraction behavior on Windows", async () => {
|
||||||
|
mockGetArtifact.mockResolvedValue({
|
||||||
|
archiveFormat: "zip",
|
||||||
|
checksum: "abc123",
|
||||||
|
downloadUrl: "https://example.com/ruff.zip",
|
||||||
|
});
|
||||||
|
|
||||||
|
await downloadVersion(
|
||||||
|
"pc-windows-msvc",
|
||||||
|
"x86_64",
|
||||||
|
"0.15.8",
|
||||||
|
undefined,
|
||||||
|
"token",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(mockCopyFile).toHaveBeenCalledWith(
|
||||||
|
"/tmp/downloaded",
|
||||||
|
"/tmp/downloaded.zip",
|
||||||
|
);
|
||||||
|
expect(mockExtractZip).toHaveBeenCalledWith("/tmp/downloaded.zip");
|
||||||
|
expect(mockCacheDir).toHaveBeenCalledWith(
|
||||||
|
"/tmp/extracted",
|
||||||
|
"ruff",
|
||||||
|
"0.15.8",
|
||||||
|
"x86_64",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("rewriteToMirror", () => {
|
||||||
|
it("rewrites a GitHub Releases URL to the Astral mirror", () => {
|
||||||
|
expect(
|
||||||
|
rewriteToMirror(
|
||||||
|
"https://github.com/astral-sh/ruff/releases/download/0.15.8/ruff-x86_64-unknown-linux-gnu.tar.gz",
|
||||||
|
),
|
||||||
|
).toBe(
|
||||||
|
"https://releases.astral.sh/github/ruff/releases/download/0.15.8/ruff-x86_64-unknown-linux-gnu.tar.gz",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns undefined for non-GitHub URLs", () => {
|
||||||
|
expect(
|
||||||
|
rewriteToMirror("https://example.com/ruff.tar.gz"),
|
||||||
|
).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns undefined for a different GitHub repo", () => {
|
||||||
|
expect(
|
||||||
|
rewriteToMirror(
|
||||||
|
"https://github.com/other/repo/releases/download/v1.0/file.tar.gz",
|
||||||
|
),
|
||||||
|
).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,196 @@
|
|||||||
|
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
|
||||||
|
|
||||||
|
const mockFetch = jest.fn();
|
||||||
|
|
||||||
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
|
debug: jest.fn(),
|
||||||
|
info: jest.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
jest.unstable_mockModule("../../src/utils/fetch", () => ({
|
||||||
|
fetch: mockFetch,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const {
|
||||||
|
clearManifestCache,
|
||||||
|
fetchManifest,
|
||||||
|
getAllVersions,
|
||||||
|
getArtifact,
|
||||||
|
getLatestVersion,
|
||||||
|
parseManifest,
|
||||||
|
} = await import("../../src/download/manifest");
|
||||||
|
|
||||||
|
const sampleManifestResponse = `{"version":"0.15.8","artifacts":[{"platform":"aarch64-apple-darwin","variant":"default","url":"https://github.com/astral-sh/ruff/releases/download/0.15.8/ruff-aarch64-apple-darwin.tar.gz","archive_format":"tar.gz","sha256":"fcf0a9ea6599c6ae28a4c854ac6da76f2c889354d7c36ce136ef071f7ab9721f"},{"platform":"x86_64-pc-windows-msvc","variant":"default","url":"https://github.com/astral-sh/ruff/releases/download/0.15.8/ruff-x86_64-pc-windows-msvc.zip","archive_format":"zip","sha256":"eb02fd95d8e0eed462b4a67ecdd320d865b38c560bffcda9a0b87ec944bdf036"}]}
|
||||||
|
{"version":"0.15.7","artifacts":[{"platform":"aarch64-apple-darwin","variant":"default","url":"https://github.com/astral-sh/ruff/releases/download/0.15.7/ruff-aarch64-apple-darwin.tar.gz","archive_format":"tar.gz","sha256":"606b3c6949d971709f2526fa0d9f0fd23ccf60e09f117999b406b424af18a6a6"}]}`;
|
||||||
|
|
||||||
|
const multiVariantManifestResponse = `{"version":"0.15.8","artifacts":[{"platform":"aarch64-apple-darwin","variant":"python-managed","url":"https://github.com/astral-sh/ruff/releases/download/0.15.8/ruff-aarch64-apple-darwin-managed.tar.gz","archive_format":"tar.gz","sha256":"managed-checksum"},{"platform":"aarch64-apple-darwin","variant":"default","url":"https://github.com/astral-sh/ruff/releases/download/0.15.8/ruff-aarch64-apple-darwin.zip","archive_format":"zip","sha256":"default-checksum"}]}`;
|
||||||
|
|
||||||
|
const oldVersionManifestResponse = `{"version":"v0.4.7","artifacts":[{"platform":"0.4.7-aarch64-apple-darwin","variant":"default","url":"https://github.com/astral-sh/ruff/releases/download/v0.4.7/ruff-0.4.7-aarch64-apple-darwin.tar.gz","archive_format":"tar.gz","sha256":"old-checksum"}]}`;
|
||||||
|
|
||||||
|
function createMockResponse(
|
||||||
|
ok: boolean,
|
||||||
|
status: number,
|
||||||
|
statusText: string,
|
||||||
|
data: string,
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
ok,
|
||||||
|
status,
|
||||||
|
statusText,
|
||||||
|
text: async () => data,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("manifest", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
clearManifestCache();
|
||||||
|
mockFetch.mockReset();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("fetchManifest", () => {
|
||||||
|
it("fetches and parses manifest data", async () => {
|
||||||
|
mockFetch.mockResolvedValue(
|
||||||
|
createMockResponse(true, 200, "OK", sampleManifestResponse),
|
||||||
|
);
|
||||||
|
|
||||||
|
const versions = await fetchManifest();
|
||||||
|
|
||||||
|
expect(versions).toHaveLength(2);
|
||||||
|
expect(versions[0]?.version).toBe("0.15.8");
|
||||||
|
expect(versions[1]?.version).toBe("0.15.7");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("throws on a failed fetch", async () => {
|
||||||
|
mockFetch.mockResolvedValue(
|
||||||
|
createMockResponse(false, 500, "Internal Server Error", ""),
|
||||||
|
);
|
||||||
|
|
||||||
|
await expect(fetchManifest()).rejects.toThrow(
|
||||||
|
"Failed to fetch manifest data: 500 Internal Server Error",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("caches results per URL", async () => {
|
||||||
|
mockFetch.mockResolvedValue(
|
||||||
|
createMockResponse(true, 200, "OK", sampleManifestResponse),
|
||||||
|
);
|
||||||
|
|
||||||
|
await fetchManifest("https://example.com/custom.ndjson");
|
||||||
|
await fetchManifest("https://example.com/custom.ndjson");
|
||||||
|
|
||||||
|
expect(mockFetch).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("getAllVersions", () => {
|
||||||
|
it("returns all version strings", async () => {
|
||||||
|
mockFetch.mockResolvedValue(
|
||||||
|
createMockResponse(true, 200, "OK", sampleManifestResponse),
|
||||||
|
);
|
||||||
|
|
||||||
|
const versions = await getAllVersions(
|
||||||
|
"https://example.com/custom.ndjson",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(versions).toEqual(["0.15.8", "0.15.7"]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("getLatestVersion", () => {
|
||||||
|
it("returns the first version string", async () => {
|
||||||
|
mockFetch.mockResolvedValue(
|
||||||
|
createMockResponse(true, 200, "OK", sampleManifestResponse),
|
||||||
|
);
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
getLatestVersion("https://example.com/custom.ndjson"),
|
||||||
|
).resolves.toBe("0.15.8");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("getArtifact", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mockFetch.mockResolvedValue(
|
||||||
|
createMockResponse(true, 200, "OK", sampleManifestResponse),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("finds an artifact by version and platform", async () => {
|
||||||
|
const artifact = await getArtifact("0.15.8", "aarch64", "apple-darwin");
|
||||||
|
|
||||||
|
expect(artifact).toEqual({
|
||||||
|
archiveFormat: "tar.gz",
|
||||||
|
checksum:
|
||||||
|
"fcf0a9ea6599c6ae28a4c854ac6da76f2c889354d7c36ce136ef071f7ab9721f",
|
||||||
|
downloadUrl:
|
||||||
|
"https://github.com/astral-sh/ruff/releases/download/0.15.8/ruff-aarch64-apple-darwin.tar.gz",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("finds a windows artifact", async () => {
|
||||||
|
const artifact = await getArtifact("0.15.8", "x86_64", "pc-windows-msvc");
|
||||||
|
|
||||||
|
expect(artifact).toEqual({
|
||||||
|
archiveFormat: "zip",
|
||||||
|
checksum:
|
||||||
|
"eb02fd95d8e0eed462b4a67ecdd320d865b38c560bffcda9a0b87ec944bdf036",
|
||||||
|
downloadUrl:
|
||||||
|
"https://github.com/astral-sh/ruff/releases/download/0.15.8/ruff-x86_64-pc-windows-msvc.zip",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("prefers the default variant when multiple artifacts share a platform", async () => {
|
||||||
|
mockFetch.mockResolvedValue(
|
||||||
|
createMockResponse(true, 200, "OK", multiVariantManifestResponse),
|
||||||
|
);
|
||||||
|
|
||||||
|
const artifact = await getArtifact("0.15.8", "aarch64", "apple-darwin");
|
||||||
|
|
||||||
|
expect(artifact).toEqual({
|
||||||
|
archiveFormat: "zip",
|
||||||
|
checksum: "default-checksum",
|
||||||
|
downloadUrl:
|
||||||
|
"https://github.com/astral-sh/ruff/releases/download/0.15.8/ruff-aarch64-apple-darwin.zip",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("finds an old artifact when the manifest version has a v prefix", async () => {
|
||||||
|
mockFetch.mockResolvedValue(
|
||||||
|
createMockResponse(true, 200, "OK", oldVersionManifestResponse),
|
||||||
|
);
|
||||||
|
|
||||||
|
const artifact = await getArtifact("0.4.7", "aarch64", "apple-darwin");
|
||||||
|
|
||||||
|
expect(artifact).toEqual({
|
||||||
|
archiveFormat: "tar.gz",
|
||||||
|
checksum: "old-checksum",
|
||||||
|
downloadUrl:
|
||||||
|
"https://github.com/astral-sh/ruff/releases/download/v0.4.7/ruff-0.4.7-aarch64-apple-darwin.tar.gz",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns undefined for an unknown version", async () => {
|
||||||
|
const artifact = await getArtifact("0.0.1", "aarch64", "apple-darwin");
|
||||||
|
|
||||||
|
expect(artifact).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns undefined for an unknown platform", async () => {
|
||||||
|
const artifact = await getArtifact(
|
||||||
|
"0.15.8",
|
||||||
|
"aarch64",
|
||||||
|
"unknown-linux-musl",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(artifact).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("parseManifest", () => {
|
||||||
|
it("throws for malformed manifest data", () => {
|
||||||
|
expect(() => parseManifest('{"version":"0.1.0"', "test-source")).toThrow(
|
||||||
|
"Failed to parse manifest data from test-source",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
+2
@@ -1,2 +1,4 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
print("Hello world!")
|
print("Hello world!")
|
||||||
print('How are you?')
|
print('How are you?')
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
[project]
|
||||||
|
name = "parent-config-project"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Test fixture for parent directory pyproject.toml search"
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.12"
|
||||||
|
dependencies = [
|
||||||
|
"ruff==0.10.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["hatchling"]
|
||||||
|
build-backend = "hatchling.build"
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
"""Hello world example."""
|
||||||
|
|
||||||
|
print("Hello, world!")
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
[project]
|
||||||
|
name = "pyproject-dependency-dev-project"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Add your description here"
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.12"
|
||||||
|
|
||||||
|
[dependency-groups]
|
||||||
|
dev = [
|
||||||
|
"ruff==0.8.3"
|
||||||
|
]
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["hatchling"]
|
||||||
|
build-backend = "hatchling.build"
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
def hello() -> str:
|
||||||
|
return "Hello from python-project!"
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
print("Hello world!")
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
[project]
|
||||||
|
name = "pyproject-dependency-groups-project"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Add your description here"
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.12"
|
||||||
|
|
||||||
|
[dependency-groups]
|
||||||
|
dev = [
|
||||||
|
{ include-group = "docs" },
|
||||||
|
{ include-group = "lint" },
|
||||||
|
]
|
||||||
|
docs = [
|
||||||
|
"sphinx",
|
||||||
|
]
|
||||||
|
lint = [
|
||||||
|
"ruff==0.8.3",
|
||||||
|
]
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["hatchling"]
|
||||||
|
build-backend = "hatchling.build"
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
def hello() -> str:
|
||||||
|
return "Hello from python-project!"
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
print("Hello world!")
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
[project]
|
||||||
|
name = "pyproject-dependency-groups-with-env-marker"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Test fixture for issue #256 - environment markers"
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.12"
|
||||||
|
|
||||||
|
[dependency-groups]
|
||||||
|
dev = [
|
||||||
|
"ruff~=0.13 ; python_version >= '3.11'",
|
||||||
|
]
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["hatchling"]
|
||||||
|
build-backend = "hatchling.build"
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
[project]
|
||||||
|
name = "pyproject-dependency-poetry-grouped-project"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Add your description here"
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.12"
|
||||||
|
|
||||||
|
[tool.poetry.group.dev.dependencies]
|
||||||
|
sphinx = "*"
|
||||||
|
ruff = "0.8.3"
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
||||||
|
build-backend = "poetry.core.masonry.api"
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
def hello() -> str:
|
||||||
|
return "Hello from python-project!"
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
print("Hello world!")
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
[project]
|
||||||
|
name = "pyproject-dependency-poetry-project"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Add your description here"
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.12"
|
||||||
|
|
||||||
|
[tool.poetry.dependencies]
|
||||||
|
sphinx = "*"
|
||||||
|
ruff = "~0.8.2"
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
||||||
|
build-backend = "poetry.core.masonry.api"
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
def hello() -> str:
|
||||||
|
return "Hello from python-project!"
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
print("Hello world!")
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
[project]
|
||||||
|
name = "pyproject-optional-dependencies-project"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Add your description here"
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.12"
|
||||||
|
|
||||||
|
[project.optional-dependencies]
|
||||||
|
lint = [
|
||||||
|
"ruff==0.8.3",
|
||||||
|
]
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["hatchling"]
|
||||||
|
build-backend = "hatchling.build"
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
def hello() -> str:
|
||||||
|
return "Hello from python-project!"
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
print("Hello world!")
|
||||||
@@ -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"
|
||||||
@@ -5,7 +5,7 @@ description = "Add your description here"
|
|||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ruff>=0.6.2",
|
"ruff==0.6.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
ruff==0.9.0 \
|
||||||
|
--hash=sha256:badc0de
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
ruff==0.9.0
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
import path from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
|
||||||
|
|
||||||
|
const debug = jest.fn();
|
||||||
|
const info = jest.fn();
|
||||||
|
|
||||||
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
|
debug,
|
||||||
|
info,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const { findPyprojectToml } = await import("../../src/utils/pyproject-finder");
|
||||||
|
|
||||||
|
const testFilePath = fileURLToPath(import.meta.url);
|
||||||
|
const testDir = path.dirname(testFilePath);
|
||||||
|
const repoRoot = path.resolve(testDir, "..", "..");
|
||||||
|
const fixturesDir = path.join(repoRoot, "__tests__", "fixtures");
|
||||||
|
|
||||||
|
describe("findPyprojectToml", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
debug.mockReset();
|
||||||
|
info.mockReset();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when pyproject.toml exists in src directory", () => {
|
||||||
|
it("should return the exact path", () => {
|
||||||
|
const result = findPyprojectToml(fixturesDir, repoRoot);
|
||||||
|
|
||||||
|
expect(result).toContain("pyproject.toml");
|
||||||
|
expect(result).toContain("fixtures");
|
||||||
|
expect(info).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when pyproject.toml exists only in parent directory", () => {
|
||||||
|
it("should search upwards and find the parent's pyproject.toml", () => {
|
||||||
|
const subprojectDir = path.join(
|
||||||
|
fixturesDir,
|
||||||
|
"parent-config-project",
|
||||||
|
"subproject",
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = findPyprojectToml(subprojectDir, repoRoot);
|
||||||
|
|
||||||
|
expect(result).toBeTruthy();
|
||||||
|
expect(result).toContain("pyproject.toml");
|
||||||
|
expect(result).toContain("parent-config-project");
|
||||||
|
expect(info).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("boundary conditions", () => {
|
||||||
|
it("should stop searching at workspace root and return undefined when not found", () => {
|
||||||
|
const nodeModulesDir = path.join(repoRoot, "node_modules", "@actions");
|
||||||
|
|
||||||
|
const result = findPyprojectToml(nodeModulesDir, repoRoot);
|
||||||
|
|
||||||
|
expect(result).toBeUndefined();
|
||||||
|
expect(info).not.toHaveBeenCalledWith(
|
||||||
|
expect.stringContaining("Found pyproject.toml"),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should find pyproject.toml when it exists at workspace root", () => {
|
||||||
|
const parentConfigProjectDir = path.join(
|
||||||
|
fixturesDir,
|
||||||
|
"parent-config-project",
|
||||||
|
);
|
||||||
|
const subprojectDir = path.join(parentConfigProjectDir, "subproject");
|
||||||
|
|
||||||
|
const result = findPyprojectToml(subprojectDir, parentConfigProjectDir);
|
||||||
|
|
||||||
|
expect(result).toBeTruthy();
|
||||||
|
expect(result).toContain("pyproject.toml");
|
||||||
|
expect(result).toContain("parent-config-project");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should stop at workspace root even if searching from it", () => {
|
||||||
|
const result = findPyprojectToml(fixturesDir, fixturesDir);
|
||||||
|
|
||||||
|
expect(result).toBeTruthy();
|
||||||
|
expect(result).toContain("pyproject.toml");
|
||||||
|
expect(result).toContain("fixtures");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("edge cases", () => {
|
||||||
|
it("should handle relative paths", () => {
|
||||||
|
const result = findPyprojectToml("./__tests__/fixtures", ".");
|
||||||
|
|
||||||
|
expect(result).toBeTruthy();
|
||||||
|
expect(result).toContain("pyproject.toml");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle when src equals workspace root", () => {
|
||||||
|
const result = findPyprojectToml(fixturesDir, fixturesDir);
|
||||||
|
|
||||||
|
expect(result).toBeTruthy();
|
||||||
|
expect(result).toContain("pyproject.toml");
|
||||||
|
expect(result).toContain("fixtures");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should log debug messages for each checked path", () => {
|
||||||
|
const pythonProjectDir = path.join(fixturesDir, "python-project");
|
||||||
|
|
||||||
|
findPyprojectToml(pythonProjectDir, repoRoot);
|
||||||
|
|
||||||
|
expect(debug).toHaveBeenCalled();
|
||||||
|
expect(debug.mock.calls.length).toBeGreaterThan(0);
|
||||||
|
expect(debug.mock.calls[0][0]).toContain("Checking for");
|
||||||
|
expect(debug.mock.calls[0][0]).toContain("python-project");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle paths with trailing slashes", () => {
|
||||||
|
const result = findPyprojectToml(`${fixturesDir}/`, repoRoot);
|
||||||
|
|
||||||
|
expect(result).toBeTruthy();
|
||||||
|
expect(result).toContain("pyproject.toml");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
|
||||||
|
|
||||||
|
const info = jest.fn();
|
||||||
|
const warning = jest.fn();
|
||||||
|
|
||||||
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
|
debug: jest.fn(),
|
||||||
|
info,
|
||||||
|
warning,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const { findRuffVersionInSpec, getRuffVersionFromFile } = await import(
|
||||||
|
"../../src/version/file-parser"
|
||||||
|
);
|
||||||
|
|
||||||
|
describe("file-parser", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
info.mockReset();
|
||||||
|
warning.mockReset();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("findRuffVersionInSpec", () => {
|
||||||
|
it("extracts version from 'ruff==0.9.3'", () => {
|
||||||
|
const result = findRuffVersionInSpec("ruff==0.9.3");
|
||||||
|
expect(result).toBe("0.9.3");
|
||||||
|
expect(info).toHaveBeenCalledWith(
|
||||||
|
"Found ruff version in requirements file: 0.9.3",
|
||||||
|
);
|
||||||
|
expect(warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("extracts version from 'ruff>=0.14'", () => {
|
||||||
|
const result = findRuffVersionInSpec("ruff>=0.14");
|
||||||
|
expect(result).toBe(">=0.14");
|
||||||
|
expect(warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("extracts version from 'ruff ~=1.0.0'", () => {
|
||||||
|
const result = findRuffVersionInSpec("ruff ~=1.0.0");
|
||||||
|
expect(result).toBe("~=1.0.0");
|
||||||
|
expect(warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("extracts version from 'ruff>=0.14,<1.0'", () => {
|
||||||
|
const result = findRuffVersionInSpec("ruff>=0.14,<1.0");
|
||||||
|
expect(result).toBe(">=0.14,<1.0");
|
||||||
|
expect(warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("extracts version from 'ruff>=0.14,<2.0,!=1.5.0'", () => {
|
||||||
|
const result = findRuffVersionInSpec("ruff>=0.14,<2.0,!=1.5.0");
|
||||||
|
expect(result).toBe(">=0.14,<2.0,!=1.5.0");
|
||||||
|
expect(warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns undefined for non-ruff dependencies", () => {
|
||||||
|
const result = findRuffVersionInSpec("another-dep==0.1.6");
|
||||||
|
expect(result).toBeUndefined();
|
||||||
|
expect(info).not.toHaveBeenCalled();
|
||||||
|
expect(warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("strips trailing backslash", () => {
|
||||||
|
const result = findRuffVersionInSpec("ruff==0.9.3 \\");
|
||||||
|
expect(result).toBe("0.9.3");
|
||||||
|
expect(info).toHaveBeenCalledWith(
|
||||||
|
"Found ruff version in requirements file: 0.9.3",
|
||||||
|
);
|
||||||
|
expect(warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("strips environment markers and warns", () => {
|
||||||
|
const result = findRuffVersionInSpec(
|
||||||
|
'ruff>=0.14 ; python_version >= "3.11"',
|
||||||
|
);
|
||||||
|
expect(result).toBe(">=0.14");
|
||||||
|
expect(info).toHaveBeenCalledWith(
|
||||||
|
"Found ruff version in requirements file: >=0.14",
|
||||||
|
);
|
||||||
|
expect(warning).toHaveBeenCalledWith(
|
||||||
|
"Environment markers are ignored. ruff is a standalone tool that works independently of Python version.",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("handles whitespace", () => {
|
||||||
|
const result = findRuffVersionInSpec(" ruff >=0.14 ");
|
||||||
|
expect(result).toBe(">=0.14");
|
||||||
|
expect(warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns undefined for empty strings", () => {
|
||||||
|
const result = findRuffVersionInSpec("");
|
||||||
|
expect(result).toBeUndefined();
|
||||||
|
expect(info).not.toHaveBeenCalled();
|
||||||
|
expect(warning).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("getRuffVersionFromFile", () => {
|
||||||
|
it("reads the version from requirements.txt", () => {
|
||||||
|
const result = getRuffVersionFromFile(
|
||||||
|
"__tests__/fixtures/requirements.txt",
|
||||||
|
);
|
||||||
|
expect(result).toBe("0.9.0");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reads the version from requirements files with hashes", () => {
|
||||||
|
const result = getRuffVersionFromFile(
|
||||||
|
"__tests__/fixtures/requirements-with-hash.txt",
|
||||||
|
);
|
||||||
|
expect(result).toBe("0.9.0");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reads the version from pyproject.toml dependencies", () => {
|
||||||
|
const result = getRuffVersionFromFile(
|
||||||
|
"__tests__/fixtures/pyproject.toml",
|
||||||
|
);
|
||||||
|
expect(result).toBe("0.9.3");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reads the version from Poetry dependencies", () => {
|
||||||
|
const result = getRuffVersionFromFile(
|
||||||
|
"__tests__/fixtures/pyproject-dependency-poetry-project/pyproject.toml",
|
||||||
|
);
|
||||||
|
expect(result).toBe("~0.8.2");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,164 @@
|
|||||||
|
import fs from "node:fs";
|
||||||
|
import os from "node:os";
|
||||||
|
import path from "node:path";
|
||||||
|
import {
|
||||||
|
afterEach,
|
||||||
|
beforeEach,
|
||||||
|
describe,
|
||||||
|
expect,
|
||||||
|
it,
|
||||||
|
jest,
|
||||||
|
} from "@jest/globals";
|
||||||
|
|
||||||
|
const debug = jest.fn();
|
||||||
|
const info = jest.fn();
|
||||||
|
const warning = jest.fn();
|
||||||
|
|
||||||
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
|
debug,
|
||||||
|
info,
|
||||||
|
warning,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const { resolveVersionRequest } = await import(
|
||||||
|
"../../src/version/version-request-resolver"
|
||||||
|
);
|
||||||
|
|
||||||
|
const tempDirs: string[] = [];
|
||||||
|
|
||||||
|
function createTempProject(files: Record<string, string> = {}): string {
|
||||||
|
const dir = fs.mkdtempSync(
|
||||||
|
path.join(os.tmpdir(), "ruff-action-version-test-"),
|
||||||
|
);
|
||||||
|
tempDirs.push(dir);
|
||||||
|
|
||||||
|
for (const [relativePath, content] of Object.entries(files)) {
|
||||||
|
const filePath = path.join(dir, relativePath);
|
||||||
|
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
||||||
|
fs.writeFileSync(filePath, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
for (const dir of tempDirs.splice(0)) {
|
||||||
|
fs.rmSync(dir, { force: true, recursive: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("resolveVersionRequest", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
debug.mockReset();
|
||||||
|
info.mockReset();
|
||||||
|
warning.mockReset();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("prefers explicit input over workspace discovery", () => {
|
||||||
|
const workspaceRoot = createTempProject({
|
||||||
|
"pyproject.toml": `[project]\ndependencies = ["ruff==0.5.14"]\n`,
|
||||||
|
});
|
||||||
|
|
||||||
|
const request = resolveVersionRequest({
|
||||||
|
sourceDirectory: workspaceRoot,
|
||||||
|
version: "==0.6.0",
|
||||||
|
workspaceRoot,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(request).toEqual({
|
||||||
|
source: "input",
|
||||||
|
specifier: "0.6.0",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses requirements.txt when it is passed via version-file", () => {
|
||||||
|
const workspaceRoot = createTempProject({
|
||||||
|
"requirements.txt": "ruff==0.6.17\nruff-api==0.1.0\n",
|
||||||
|
});
|
||||||
|
|
||||||
|
const request = resolveVersionRequest({
|
||||||
|
sourceDirectory: workspaceRoot,
|
||||||
|
versionFile: path.join(workspaceRoot, "requirements.txt"),
|
||||||
|
workspaceRoot,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(request).toEqual({
|
||||||
|
format: "requirements",
|
||||||
|
source: "version-file",
|
||||||
|
sourcePath: path.join(workspaceRoot, "requirements.txt"),
|
||||||
|
specifier: "0.6.17",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("warns and falls back to latest when version-file does not resolve a version", () => {
|
||||||
|
const workspaceRoot = createTempProject({
|
||||||
|
"requirements.txt": "ruff-api==0.1.0\n",
|
||||||
|
});
|
||||||
|
|
||||||
|
const request = resolveVersionRequest({
|
||||||
|
sourceDirectory: workspaceRoot,
|
||||||
|
versionFile: path.join(workspaceRoot, "requirements.txt"),
|
||||||
|
workspaceRoot,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(request).toEqual({
|
||||||
|
source: "default",
|
||||||
|
specifier: "latest",
|
||||||
|
});
|
||||||
|
expect(warning).toHaveBeenCalledWith(
|
||||||
|
`Could not parse version from ${path.join(workspaceRoot, "requirements.txt")}. Using latest version.`,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("discovers pyproject.toml by searching upward from src", () => {
|
||||||
|
const workspaceRoot = createTempProject({
|
||||||
|
"pyproject.toml": `[project]\ndependencies = ["ruff==0.10.0"]\n`,
|
||||||
|
"subproject/nested/example.py": 'print("hello")\n',
|
||||||
|
});
|
||||||
|
const sourceDirectory = path.join(workspaceRoot, "subproject", "nested");
|
||||||
|
|
||||||
|
const request = resolveVersionRequest({
|
||||||
|
sourceDirectory,
|
||||||
|
workspaceRoot,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(request).toEqual({
|
||||||
|
format: "pyproject.toml",
|
||||||
|
source: "pyproject.toml",
|
||||||
|
sourcePath: path.join(workspaceRoot, "pyproject.toml"),
|
||||||
|
specifier: "0.10.0",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("falls back to latest when no workspace version source is found", () => {
|
||||||
|
const workspaceRoot = createTempProject({
|
||||||
|
"subproject/example.py": 'print("hello")\n',
|
||||||
|
});
|
||||||
|
|
||||||
|
const request = resolveVersionRequest({
|
||||||
|
sourceDirectory: path.join(workspaceRoot, "subproject"),
|
||||||
|
workspaceRoot,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(request).toEqual({
|
||||||
|
source: "default",
|
||||||
|
specifier: "latest",
|
||||||
|
});
|
||||||
|
expect(info).toHaveBeenCalledWith(
|
||||||
|
"Could not find pyproject.toml. Using latest version.",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("throws when both version and version-file are specified", () => {
|
||||||
|
const workspaceRoot = createTempProject();
|
||||||
|
|
||||||
|
expect(() =>
|
||||||
|
resolveVersionRequest({
|
||||||
|
sourceDirectory: workspaceRoot,
|
||||||
|
version: "0.6.0",
|
||||||
|
versionFile: path.join(workspaceRoot, "requirements.txt"),
|
||||||
|
workspaceRoot,
|
||||||
|
}),
|
||||||
|
).toThrow("It is not allowed to specify both version and version-file");
|
||||||
|
});
|
||||||
|
});
|
||||||
+11
-6
@@ -11,24 +11,29 @@ inputs:
|
|||||||
required: false
|
required: false
|
||||||
default: ${{ github.workspace }}
|
default: ${{ github.workspace }}
|
||||||
version:
|
version:
|
||||||
description: "The version of Ruff to use, e.g., `0.6.0` Defaults to the latest version."
|
description: "The version of Ruff to use, e.g., `0.6.0`. Defaults to the first discoverable version in pyproject.toml searched upward from `src`, or `latest`."
|
||||||
|
required: false
|
||||||
|
default: ""
|
||||||
|
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`."
|
||||||
required: false
|
required: false
|
||||||
default: "latest"
|
|
||||||
checksum:
|
checksum:
|
||||||
description: "The checksum of the ruff version to install"
|
description: "The checksum of the ruff version to install"
|
||||||
required: false
|
required: false
|
||||||
|
manifest-file:
|
||||||
|
description: "URL to a custom manifest file in the astral-sh/versions format."
|
||||||
|
required: false
|
||||||
github-token:
|
github-token:
|
||||||
description:
|
description:
|
||||||
"Used to increase the rate limit when retrieving versions and downloading
|
"Used for authenticated downloads of Ruff release artifacts from GitHub."
|
||||||
ruff."
|
|
||||||
required: false
|
required: false
|
||||||
default: ${{ github.token }}
|
default: ${{ github.token }}
|
||||||
outputs:
|
outputs:
|
||||||
ruff-version:
|
ruff-version:
|
||||||
description: "The installed ruff version. Useful when using latest."
|
description: "The installed ruff version. Useful when using latest."
|
||||||
runs:
|
runs:
|
||||||
using: "node20"
|
using: "node24"
|
||||||
main: "dist/ruff-action/index.js"
|
main: "dist/ruff-action/index.cjs"
|
||||||
branding:
|
branding:
|
||||||
icon: "code"
|
icon: "code"
|
||||||
color: "black"
|
color: "black"
|
||||||
|
|||||||
+27
-13
@@ -1,20 +1,35 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://biomejs.dev/schemas/1.9.2/schema.json",
|
"$schema": "https://biomejs.dev/schemas/2.4.9/schema.json",
|
||||||
"vcs": {
|
"assist": {
|
||||||
"enabled": true,
|
"actions": {
|
||||||
"clientKind": "git",
|
"source": {
|
||||||
"useIgnoreFile": false
|
"organizeImports": "on",
|
||||||
|
"useSortedAttributes": "on",
|
||||||
|
"useSortedKeys": "on"
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"files": {
|
"files": {
|
||||||
"ignoreUnknown": false,
|
"ignoreUnknown": false,
|
||||||
"ignore": ["dist", "lib", "node_modules"]
|
"includes": [
|
||||||
|
"**",
|
||||||
|
"!**/coverage",
|
||||||
|
"!**/dist",
|
||||||
|
"!**/lib",
|
||||||
|
"!**/node_modules",
|
||||||
|
"!**/package*.json",
|
||||||
|
"!**/known-checksums.*"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"formatter": {
|
"formatter": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"indentStyle": "space"
|
"indentStyle": "space"
|
||||||
},
|
},
|
||||||
"organizeImports": {
|
"javascript": {
|
||||||
"enabled": true
|
"formatter": {
|
||||||
|
"quoteStyle": "double",
|
||||||
|
"trailingCommas": "all"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"linter": {
|
"linter": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
@@ -22,10 +37,9 @@
|
|||||||
"recommended": true
|
"recommended": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"javascript": {
|
"vcs": {
|
||||||
"formatter": {
|
"clientKind": "git",
|
||||||
"quoteStyle": "double",
|
"enabled": true,
|
||||||
"trailingCommas": "all"
|
"useIgnoreFile": false
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+29363
File diff suppressed because one or more lines are too long
-36692
File diff suppressed because one or more lines are too long
+29544
File diff suppressed because one or more lines are too long
-36430
File diff suppressed because one or more lines are too long
@@ -0,0 +1,12 @@
|
|||||||
|
import { createDefaultEsmPreset } from "ts-jest";
|
||||||
|
|
||||||
|
const preset = createDefaultEsmPreset();
|
||||||
|
|
||||||
|
/** @type {import('jest').Config} */
|
||||||
|
export default {
|
||||||
|
...preset,
|
||||||
|
collectCoverageFrom: ["src/**/*.ts", "!src/**/*.d.ts"],
|
||||||
|
moduleFileExtensions: ["ts", "js", "mjs"],
|
||||||
|
testEnvironment: "node",
|
||||||
|
testMatch: ["<rootDir>/__tests__/**/*.test.ts"],
|
||||||
|
};
|
||||||
Generated
+7991
-249
File diff suppressed because it is too large
Load Diff
+34
-19
@@ -2,37 +2,52 @@
|
|||||||
"name": "ruff-action",
|
"name": "ruff-action",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
"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.js",
|
"main": "dist/ruff-action/index.cjs",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc --noEmit",
|
||||||
"format": "biome format --fix",
|
"check": "biome check --write",
|
||||||
"format-check": "biome format",
|
"package": "node scripts/build-dist.mjs",
|
||||||
"lint": "biome lint --fix",
|
|
||||||
"package": "ncc build -o dist/ruff-action src/ruff-action.ts && ncc build -o dist/update-known-checksums src/update-known-checksums.ts",
|
|
||||||
"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.js 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.ts \"$(gh auth token)\"",
|
||||||
"all": "npm run build && npm run format && npm run lint && npm run package"
|
"test:unit": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js",
|
||||||
|
"test": "npm run build && npm run test:unit",
|
||||||
|
"all": "npm run build && npm run check && npm run package && npm run test:unit"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/astral-sh/ruff-action.git"
|
"url": "git+https://github.com/astral-sh/ruff-action.git"
|
||||||
},
|
},
|
||||||
"keywords": ["actions", "python", "ruff", "action"],
|
"keywords": [
|
||||||
|
"actions",
|
||||||
|
"python",
|
||||||
|
"ruff",
|
||||||
|
"action"
|
||||||
|
],
|
||||||
"author": "@eifinger",
|
"author": "@eifinger",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.11.1",
|
"@actions/core": "^3.0.0",
|
||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^3.0.0",
|
||||||
"@actions/github": "^6.0.0",
|
"@actions/tool-cache": "^4.0.0",
|
||||||
"@actions/tool-cache": "^2.0.1"
|
"@octokit/core": "^7.0.3",
|
||||||
|
"@octokit/plugin-paginate-rest": "^13.1.1",
|
||||||
|
"@octokit/plugin-rest-endpoint-methods": "^16.0.0",
|
||||||
|
"@renovatebot/pep440": "^4.2.1",
|
||||||
|
"smol-toml": "^1.6.0",
|
||||||
|
"undici": "^6.24.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "1.9.4",
|
"@biomejs/biome": "^2.4.7",
|
||||||
"@types/node": "^22.9.1",
|
"@types/jest": "^29.5.14",
|
||||||
"@types/semver": "^7.5.8",
|
"@types/js-yaml": "^4.0.9",
|
||||||
"@vercel/ncc": "^0.38.3",
|
"@types/node": "^25.5.0",
|
||||||
"js-yaml": "^4.1.0",
|
"@types/semver": "^7.7.1",
|
||||||
"typescript": "^5.6.3"
|
"esbuild": "^0.27.4",
|
||||||
|
"jest": "^30.3.0",
|
||||||
|
"js-yaml": "^4.1.1",
|
||||||
|
"ts-jest": "^29.4.6",
|
||||||
|
"typescript": "^5.9.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import { mkdir, rm } from "node:fs/promises";
|
||||||
|
import path from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
import { build } from "esbuild";
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
const repoRoot = path.resolve(__dirname, "..");
|
||||||
|
|
||||||
|
const builds = [
|
||||||
|
{
|
||||||
|
entryPoint: path.join(repoRoot, "src", "ruff-action.ts"),
|
||||||
|
outfile: path.join(repoRoot, "dist", "ruff-action", "index.cjs"),
|
||||||
|
staleOutfile: path.join(repoRoot, "dist", "ruff-action", "index.js"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
entryPoint: path.join(repoRoot, "src", "update-known-checksums.ts"),
|
||||||
|
outfile: path.join(repoRoot, "dist", "update-known-checksums", "index.cjs"),
|
||||||
|
staleOutfile: path.join(
|
||||||
|
repoRoot,
|
||||||
|
"dist",
|
||||||
|
"update-known-checksums",
|
||||||
|
"index.js",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
|
builds.map(async ({ entryPoint, outfile, staleOutfile }) => {
|
||||||
|
await rm(staleOutfile, { force: true });
|
||||||
|
await mkdir(path.dirname(outfile), { recursive: true });
|
||||||
|
await build({
|
||||||
|
bundle: true,
|
||||||
|
entryPoints: [entryPoint],
|
||||||
|
format: "cjs",
|
||||||
|
outfile,
|
||||||
|
platform: "node",
|
||||||
|
target: "node24",
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
);
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import * as fs from "node:fs";
|
|
||||||
import * as crypto from "node:crypto";
|
import * as crypto from "node:crypto";
|
||||||
|
import * as fs from "node:fs";
|
||||||
|
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import { KNOWN_CHECKSUMS } from "./known-checksums";
|
|
||||||
import type { Architecture, Platform } from "../../utils/platforms";
|
import type { Architecture, Platform } from "../../utils/platforms";
|
||||||
|
import { KNOWN_CHECKSUMS } from "./known-checksums";
|
||||||
|
|
||||||
export async function validateChecksum(
|
export async function validateChecksum(
|
||||||
checkSum: string | undefined,
|
checkSum: string | undefined,
|
||||||
@@ -12,7 +12,7 @@ export async function validateChecksum(
|
|||||||
platform: Platform,
|
platform: Platform,
|
||||||
version: string,
|
version: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
let isValid: boolean | undefined = undefined;
|
let isValid: boolean | undefined;
|
||||||
if (checkSum !== undefined && checkSum !== "") {
|
if (checkSum !== undefined && checkSum !== "") {
|
||||||
isValid = await validateFileCheckSum(downloadPath, checkSum);
|
isValid = await validateFileCheckSum(downloadPath, checkSum);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,11 +1,17 @@
|
|||||||
|
import { promises as fs } from "node:fs";
|
||||||
|
import * as path from "node:path";
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import * as tc from "@actions/tool-cache";
|
import * as tc from "@actions/tool-cache";
|
||||||
import * as path from "node:path";
|
import * as semver from "semver";
|
||||||
import { promises as fs } from "node:fs";
|
import {
|
||||||
import { OWNER, REPO, TOOL_CACHE_NAME } from "../utils/constants";
|
ASTRAL_MIRROR_PREFIX,
|
||||||
|
GITHUB_RELEASES_PREFIX,
|
||||||
|
TOOL_CACHE_NAME,
|
||||||
|
VERSIONS_MANIFEST_URL,
|
||||||
|
} from "../utils/constants";
|
||||||
import type { Architecture, Platform } from "../utils/platforms";
|
import type { Architecture, Platform } from "../utils/platforms";
|
||||||
import { validateChecksum } from "./checksum/checksum";
|
import { validateChecksum } from "./checksum/checksum";
|
||||||
import * as github from "@actions/github";
|
import { getArtifact } from "./manifest";
|
||||||
|
|
||||||
export function tryGetFromToolCache(
|
export function tryGetFromToolCache(
|
||||||
arch: Architecture,
|
arch: Architecture,
|
||||||
@@ -19,97 +25,193 @@ export function tryGetFromToolCache(
|
|||||||
resolvedVersion = version;
|
resolvedVersion = version;
|
||||||
}
|
}
|
||||||
const installedPath = tc.find(TOOL_CACHE_NAME, resolvedVersion, arch);
|
const installedPath = tc.find(TOOL_CACHE_NAME, resolvedVersion, arch);
|
||||||
return { version: resolvedVersion, installedPath };
|
return { installedPath, version: resolvedVersion };
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function downloadVersion(
|
export async function downloadVersion(
|
||||||
platform: Platform,
|
platform: Platform,
|
||||||
arch: Architecture,
|
arch: Architecture,
|
||||||
version: string,
|
version: string,
|
||||||
checkSum: string | undefined,
|
checksum: string | undefined,
|
||||||
githubToken: string,
|
githubToken: string,
|
||||||
|
manifestUrl?: string,
|
||||||
): Promise<{ version: string; cachedToolDir: string }> {
|
): Promise<{ version: string; cachedToolDir: string }> {
|
||||||
const resolvedVersion = await resolveVersion(version, githubToken);
|
const artifact = await getArtifact(version, arch, platform, manifestUrl);
|
||||||
const artifact = `ruff-${arch}-${platform}`;
|
|
||||||
let extension = ".tar.gz";
|
|
||||||
if (platform === "pc-windows-msvc") {
|
|
||||||
extension = ".zip";
|
|
||||||
}
|
|
||||||
const downloadUrl = `https://github.com/${OWNER}/${REPO}/releases/download/${resolvedVersion}/${artifact}${extension}`;
|
|
||||||
core.info(`Downloading ruff from "${downloadUrl}" ...`);
|
|
||||||
|
|
||||||
|
if (!artifact) {
|
||||||
|
throw new Error(
|
||||||
|
getMissingArtifactMessage(version, arch, platform, manifestUrl),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// For the default astral-sh/versions source, checksum validation relies on
|
||||||
|
// user input or the built-in KNOWN_CHECKSUMS table, not manifest sha256 values.
|
||||||
|
const resolvedChecksum =
|
||||||
|
manifestUrl === undefined
|
||||||
|
? checksum
|
||||||
|
: resolveChecksum(checksum, artifact.checksum);
|
||||||
|
|
||||||
|
const downloadPath = await downloadArtifact(
|
||||||
|
artifact.downloadUrl,
|
||||||
|
platform,
|
||||||
|
arch,
|
||||||
|
version,
|
||||||
|
getDownloadToken(artifact.downloadUrl, githubToken),
|
||||||
|
);
|
||||||
|
await validateChecksum(
|
||||||
|
resolvedChecksum,
|
||||||
|
downloadPath,
|
||||||
|
arch,
|
||||||
|
platform,
|
||||||
|
version,
|
||||||
|
);
|
||||||
|
|
||||||
|
const extractedDir = await extractDownloadedArtifact(
|
||||||
|
version,
|
||||||
|
downloadPath,
|
||||||
|
getExtension(platform),
|
||||||
|
platform,
|
||||||
|
`ruff-${arch}-${platform}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const cachedToolDir = await tc.cacheDir(
|
||||||
|
extractedDir,
|
||||||
|
TOOL_CACHE_NAME,
|
||||||
|
version,
|
||||||
|
arch,
|
||||||
|
);
|
||||||
|
return { cachedToolDir, version };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function rewriteToMirror(url: string): string | undefined {
|
||||||
|
if (!url.startsWith(GITHUB_RELEASES_PREFIX)) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ASTRAL_MIRROR_PREFIX + url.slice(GITHUB_RELEASES_PREFIX.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function downloadArtifact(
|
||||||
|
downloadUrl: string,
|
||||||
|
platform: Platform,
|
||||||
|
arch: Architecture,
|
||||||
|
version: string,
|
||||||
|
githubToken: string | undefined,
|
||||||
|
): Promise<string> {
|
||||||
|
const mirrorUrl = rewriteToMirror(downloadUrl);
|
||||||
|
const resolvedDownloadUrl = mirrorUrl ?? downloadUrl;
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await downloadFile(
|
||||||
|
resolvedDownloadUrl,
|
||||||
|
mirrorUrl !== undefined ? undefined : githubToken,
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
if (mirrorUrl === undefined) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
core.warning(
|
||||||
|
`Failed to download from mirror, falling back to GitHub Releases: ${(err as Error).message}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
return await downloadFile(
|
||||||
|
constructDownloadUrl(version, platform, arch),
|
||||||
|
githubToken,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function downloadFile(
|
||||||
|
downloadUrl: string,
|
||||||
|
githubToken: string | undefined,
|
||||||
|
): Promise<string> {
|
||||||
|
core.info(`Downloading ruff from "${downloadUrl}" ...`);
|
||||||
const downloadPath = await tc.downloadTool(
|
const downloadPath = await tc.downloadTool(
|
||||||
downloadUrl,
|
downloadUrl,
|
||||||
undefined,
|
undefined,
|
||||||
githubToken,
|
githubToken,
|
||||||
);
|
);
|
||||||
await validateChecksum(
|
core.debug(`Downloaded ruff to "${downloadPath}"`);
|
||||||
checkSum,
|
return downloadPath;
|
||||||
downloadPath,
|
}
|
||||||
arch,
|
|
||||||
platform,
|
|
||||||
resolvedVersion,
|
|
||||||
);
|
|
||||||
|
|
||||||
|
async function extractDownloadedArtifact(
|
||||||
|
version: string,
|
||||||
|
downloadPath: string,
|
||||||
|
extension: string,
|
||||||
|
platform: Platform,
|
||||||
|
artifact: string,
|
||||||
|
): Promise<string> {
|
||||||
let ruffDir: string;
|
let ruffDir: string;
|
||||||
if (platform === "pc-windows-msvc") {
|
if (platform === "pc-windows-msvc") {
|
||||||
const fullPathWithExtension = `${downloadPath}${extension}`;
|
const fullPathWithExtension = `${downloadPath}${extension}`;
|
||||||
await fs.copyFile(downloadPath, fullPathWithExtension);
|
await fs.copyFile(downloadPath, fullPathWithExtension);
|
||||||
ruffDir = await tc.extractZip(fullPathWithExtension);
|
ruffDir = await tc.extractZip(fullPathWithExtension);
|
||||||
// On windows extracting the zip does not create an intermediate directory
|
// On windows extracting the zip does not create an intermediate directory.
|
||||||
} else {
|
} else {
|
||||||
const extractedDir = await tc.extractTar(downloadPath);
|
ruffDir = await tc.extractTar(downloadPath);
|
||||||
ruffDir = path.join(extractedDir, artifact);
|
if (semver.gte(version, "v0.5.0")) {
|
||||||
|
// Since v0.5.0 an intermediate directory is created
|
||||||
|
ruffDir = path.join(ruffDir, artifact);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const cachedToolDir = await tc.cacheDir(
|
const files = await fs.readdir(ruffDir);
|
||||||
ruffDir,
|
core.debug(`Contents of ${ruffDir}: ${files.join(", ")}`);
|
||||||
TOOL_CACHE_NAME,
|
return ruffDir;
|
||||||
resolvedVersion,
|
|
||||||
arch,
|
|
||||||
);
|
|
||||||
return { version: resolvedVersion, cachedToolDir };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function resolveVersion(
|
function getMissingArtifactMessage(
|
||||||
versionInput: string,
|
version: string,
|
||||||
|
arch: Architecture,
|
||||||
|
platform: Platform,
|
||||||
|
manifestUrl?: string,
|
||||||
|
): string {
|
||||||
|
if (manifestUrl === undefined) {
|
||||||
|
return `Could not find artifact for version ${version}, arch ${arch}, platform ${platform} in ${VERSIONS_MANIFEST_URL} .`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `manifest-file does not contain version ${version}, arch ${arch}, platform ${platform}.`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveChecksum(
|
||||||
|
checksum: string | undefined,
|
||||||
|
manifestChecksum: string,
|
||||||
|
): string {
|
||||||
|
return checksum !== undefined && checksum !== ""
|
||||||
|
? checksum
|
||||||
|
: manifestChecksum;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDownloadToken(
|
||||||
|
downloadUrl: string,
|
||||||
githubToken: string,
|
githubToken: string,
|
||||||
): Promise<string> {
|
): string | undefined {
|
||||||
const version =
|
return downloadUrl.startsWith(GITHUB_RELEASES_PREFIX)
|
||||||
versionInput === "latest"
|
? githubToken
|
||||||
? await getLatestVersion(githubToken)
|
: undefined;
|
||||||
: versionInput;
|
|
||||||
if (tc.isExplicitVersion(version)) {
|
|
||||||
core.debug(`Version ${version} is an explicit version.`);
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
const availableVersions = await getAvailableVersions(githubToken);
|
|
||||||
const resolvedVersion = tc.evaluateVersions(availableVersions, version);
|
|
||||||
if (resolvedVersion === "") {
|
|
||||||
throw new Error(`No version found for ${version}`);
|
|
||||||
}
|
|
||||||
return resolvedVersion;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAvailableVersions(githubToken: string): Promise<string[]> {
|
function constructDownloadUrl(
|
||||||
const octokit = github.getOctokit(githubToken);
|
version: string,
|
||||||
|
platform: Platform,
|
||||||
|
arch: Architecture,
|
||||||
|
): string {
|
||||||
|
const normalizedVersion = stripVersionPrefix(version);
|
||||||
|
const artifactVersionSuffix =
|
||||||
|
semver.lte(version, "v0.4.10") && semver.gte(version, "v0.1.8")
|
||||||
|
? `-${normalizedVersion}`
|
||||||
|
: "";
|
||||||
|
const artifact = `ruff${artifactVersionSuffix}-${arch}-${platform}`;
|
||||||
|
const versionPrefix = semver.lte(version, "v0.4.10") ? "v" : "";
|
||||||
|
|
||||||
const response = await octokit.paginate(octokit.rest.repos.listReleases, {
|
return `${GITHUB_RELEASES_PREFIX}${versionPrefix}${normalizedVersion}/${artifact}${getExtension(platform)}`;
|
||||||
owner: OWNER,
|
|
||||||
repo: REPO,
|
|
||||||
});
|
|
||||||
return response.map((release) => release.tag_name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getLatestVersion(githubToken: string) {
|
function stripVersionPrefix(version: string): string {
|
||||||
const octokit = github.getOctokit(githubToken);
|
return version.startsWith("v") ? version.slice(1) : version;
|
||||||
|
}
|
||||||
|
|
||||||
const { data: latestRelease } = await octokit.rest.repos.getLatestRelease({
|
function getExtension(platform: Platform): string {
|
||||||
owner: OWNER,
|
return platform === "pc-windows-msvc" ? ".zip" : ".tar.gz";
|
||||||
repo: REPO,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!latestRelease) {
|
|
||||||
throw new Error("Could not determine latest release.");
|
|
||||||
}
|
|
||||||
return latestRelease.tag_name;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,243 @@
|
|||||||
|
import * as core from "@actions/core";
|
||||||
|
import { VERSIONS_MANIFEST_URL } from "../utils/constants";
|
||||||
|
import { fetch } from "../utils/fetch";
|
||||||
|
import { selectDefaultVariant } from "./variant-selection";
|
||||||
|
|
||||||
|
export interface ManifestArtifact {
|
||||||
|
platform: string;
|
||||||
|
variant?: string;
|
||||||
|
url: string;
|
||||||
|
archive_format: string;
|
||||||
|
sha256: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ManifestVersion {
|
||||||
|
version: string;
|
||||||
|
artifacts: ManifestArtifact[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ArtifactResult {
|
||||||
|
archiveFormat: string;
|
||||||
|
checksum: string;
|
||||||
|
downloadUrl: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cachedManifestData = new Map<string, ManifestVersion[]>();
|
||||||
|
|
||||||
|
export async function fetchManifest(
|
||||||
|
manifestUrl: string = VERSIONS_MANIFEST_URL,
|
||||||
|
): Promise<ManifestVersion[]> {
|
||||||
|
const cachedVersions = cachedManifestData.get(manifestUrl);
|
||||||
|
if (cachedVersions !== undefined) {
|
||||||
|
core.debug(`Using cached manifest data from ${manifestUrl}`);
|
||||||
|
return cachedVersions;
|
||||||
|
}
|
||||||
|
|
||||||
|
core.info(`Fetching manifest data from ${manifestUrl} ...`);
|
||||||
|
const response = await fetch(manifestUrl, {});
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to fetch manifest data: ${response.status} ${response.statusText}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = await response.text();
|
||||||
|
const versions = parseManifest(body, manifestUrl);
|
||||||
|
cachedManifestData.set(manifestUrl, versions);
|
||||||
|
return versions;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseManifest(
|
||||||
|
data: string,
|
||||||
|
sourceDescription: string,
|
||||||
|
): ManifestVersion[] {
|
||||||
|
const trimmed = data.trim();
|
||||||
|
if (trimmed === "") {
|
||||||
|
throw new Error(`Manifest at ${sourceDescription} is empty.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trimmed.startsWith("[")) {
|
||||||
|
throw new Error(
|
||||||
|
`Legacy JSON array manifests are no longer supported in ${sourceDescription}. Use the astral-sh/versions manifest format instead.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const versions: ManifestVersion[] = [];
|
||||||
|
|
||||||
|
for (const [index, line] of data.split("\n").entries()) {
|
||||||
|
const record = line.trim();
|
||||||
|
if (record === "") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let parsed: unknown;
|
||||||
|
try {
|
||||||
|
parsed = JSON.parse(record);
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to parse manifest data from ${sourceDescription} at line ${index + 1}: ${(error as Error).message}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isManifestVersion(parsed)) {
|
||||||
|
throw new Error(
|
||||||
|
`Invalid manifest record in ${sourceDescription} at line ${index + 1}.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
versions.push(parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (versions.length === 0) {
|
||||||
|
throw new Error(`No manifest data found in ${sourceDescription}.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return versions;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getLatestVersion(
|
||||||
|
manifestUrl: string = VERSIONS_MANIFEST_URL,
|
||||||
|
): Promise<string> {
|
||||||
|
const latestVersion = (await fetchManifest(manifestUrl))[0]?.version;
|
||||||
|
|
||||||
|
if (latestVersion === undefined) {
|
||||||
|
throw new Error("No versions found in manifest data");
|
||||||
|
}
|
||||||
|
|
||||||
|
core.debug(`Latest version from manifest: ${latestVersion}`);
|
||||||
|
return latestVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getAllVersions(
|
||||||
|
manifestUrl: string = VERSIONS_MANIFEST_URL,
|
||||||
|
): Promise<string[]> {
|
||||||
|
core.info(
|
||||||
|
`Getting available versions from ${manifestSource(manifestUrl)} ...`,
|
||||||
|
);
|
||||||
|
const versions = await fetchManifest(manifestUrl);
|
||||||
|
return versions.map((versionData) => versionData.version);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getArtifact(
|
||||||
|
version: string,
|
||||||
|
arch: string,
|
||||||
|
platform: string,
|
||||||
|
manifestUrl: string = VERSIONS_MANIFEST_URL,
|
||||||
|
): Promise<ArtifactResult | undefined> {
|
||||||
|
const versions = await fetchManifest(manifestUrl);
|
||||||
|
const versionData = versions.find((candidate) =>
|
||||||
|
matchesManifestVersion(candidate.version, version),
|
||||||
|
);
|
||||||
|
if (!versionData) {
|
||||||
|
core.debug(`Version ${version} not found in manifest ${manifestUrl}`);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const targetPlatforms = getTargetPlatforms(
|
||||||
|
versionData.version,
|
||||||
|
arch,
|
||||||
|
platform,
|
||||||
|
);
|
||||||
|
const matchingArtifacts = versionData.artifacts.filter((candidate) =>
|
||||||
|
targetPlatforms.includes(candidate.platform),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (matchingArtifacts.length === 0) {
|
||||||
|
core.debug(
|
||||||
|
`Artifact for ${targetPlatforms.join(" or ")} not found in version ${version}. Available platforms: ${versionData.artifacts
|
||||||
|
.map((candidate) => candidate.platform)
|
||||||
|
.join(", ")}`,
|
||||||
|
);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const artifact = selectDefaultVariant(
|
||||||
|
matchingArtifacts,
|
||||||
|
`Multiple artifacts found for ${targetPlatforms.join(" or ")} in version ${version}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
archiveFormat: artifact.archive_format,
|
||||||
|
checksum: artifact.sha256,
|
||||||
|
downloadUrl: artifact.url,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearManifestCache(manifestUrl?: string): void {
|
||||||
|
if (manifestUrl === undefined) {
|
||||||
|
cachedManifestData.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cachedManifestData.delete(manifestUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
function manifestSource(manifestUrl: string): string {
|
||||||
|
if (manifestUrl === VERSIONS_MANIFEST_URL) {
|
||||||
|
return VERSIONS_MANIFEST_URL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `manifest-file ${manifestUrl}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function matchesManifestVersion(
|
||||||
|
manifestVersion: string,
|
||||||
|
requestedVersion: string,
|
||||||
|
): boolean {
|
||||||
|
return (
|
||||||
|
manifestVersion === requestedVersion ||
|
||||||
|
manifestVersion === withVersionPrefix(requestedVersion)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTargetPlatforms(
|
||||||
|
manifestVersion: string,
|
||||||
|
arch: string,
|
||||||
|
platform: string,
|
||||||
|
): string[] {
|
||||||
|
const targetPlatform = `${arch}-${platform}`;
|
||||||
|
const versionPrefixedTargetPlatform = `${stripVersionPrefix(manifestVersion)}-${targetPlatform}`;
|
||||||
|
|
||||||
|
return [targetPlatform, versionPrefixedTargetPlatform];
|
||||||
|
}
|
||||||
|
|
||||||
|
function withVersionPrefix(version: string): string {
|
||||||
|
return version.startsWith("v") ? version : `v${version}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function stripVersionPrefix(version: string): string {
|
||||||
|
return version.startsWith("v") ? version.slice(1) : version;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isManifestVersion(value: unknown): value is ManifestVersion {
|
||||||
|
if (!isRecord(value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof value.version !== "string" || !Array.isArray(value.artifacts)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value.artifacts.every(isManifestArtifact);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isManifestArtifact(value: unknown): value is ManifestArtifact {
|
||||||
|
if (!isRecord(value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const variantIsValid =
|
||||||
|
typeof value.variant === "string" || value.variant === undefined;
|
||||||
|
|
||||||
|
return (
|
||||||
|
typeof value.archive_format === "string" &&
|
||||||
|
typeof value.platform === "string" &&
|
||||||
|
typeof value.sha256 === "string" &&
|
||||||
|
typeof value.url === "string" &&
|
||||||
|
variantIsValid
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||||
|
return typeof value === "object" && value !== null;
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
interface VariantAwareEntry {
|
||||||
|
variant?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function selectDefaultVariant<T extends VariantAwareEntry>(
|
||||||
|
entries: T[],
|
||||||
|
duplicateEntryDescription: string,
|
||||||
|
): T {
|
||||||
|
const firstEntry = entries[0];
|
||||||
|
if (firstEntry === undefined) {
|
||||||
|
throw new Error("selectDefaultVariant requires at least one candidate.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entries.length === 1) {
|
||||||
|
return firstEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultEntries = entries.filter((entry) =>
|
||||||
|
isDefaultVariant(entry.variant),
|
||||||
|
);
|
||||||
|
if (defaultEntries.length === 1) {
|
||||||
|
return defaultEntries[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
`${duplicateEntryDescription} with variants ${formatVariants(entries)}. ruff-action currently requires a single default variant for duplicate platform entries.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isDefaultVariant(variant: string | undefined): boolean {
|
||||||
|
return variant === undefined || variant === "default";
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatVariants<T extends VariantAwareEntry>(entries: T[]): string {
|
||||||
|
return entries
|
||||||
|
.map((entry) => entry.variant ?? "default")
|
||||||
|
.sort((left, right) => left.localeCompare(right))
|
||||||
|
.join(", ");
|
||||||
|
}
|
||||||
+50
-13
@@ -1,19 +1,27 @@
|
|||||||
|
import * as path from "node:path";
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import * as exec from "@actions/exec";
|
import * as exec from "@actions/exec";
|
||||||
import * as path from "node:path";
|
import * as semver from "semver";
|
||||||
import {
|
import {
|
||||||
downloadVersion,
|
downloadVersion,
|
||||||
resolveVersion,
|
|
||||||
tryGetFromToolCache,
|
tryGetFromToolCache,
|
||||||
} from "./download/download-version";
|
} from "./download/download-version";
|
||||||
|
import {
|
||||||
|
args,
|
||||||
|
checkSum,
|
||||||
|
githubToken,
|
||||||
|
manifestFile,
|
||||||
|
src,
|
||||||
|
version,
|
||||||
|
versionFile as versionFileInput,
|
||||||
|
} from "./utils/inputs";
|
||||||
import {
|
import {
|
||||||
type Architecture,
|
type Architecture,
|
||||||
getArch,
|
getArch,
|
||||||
getPlatform,
|
getPlatform,
|
||||||
type Platform,
|
type Platform,
|
||||||
} from "./utils/platforms";
|
} from "./utils/platforms";
|
||||||
import { args, checkSum, githubToken, src, version } from "./utils/inputs";
|
import { resolveRuffVersion } from "./version/resolve";
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
const platform = getPlatform();
|
const platform = getPlatform();
|
||||||
@@ -26,15 +34,11 @@ 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(
|
const setupResult = await setupRuff(platform, arch, checkSum, githubToken);
|
||||||
platform,
|
|
||||||
arch,
|
|
||||||
version,
|
|
||||||
checkSum,
|
|
||||||
githubToken,
|
|
||||||
);
|
|
||||||
|
|
||||||
addRuffToPath(setupResult.ruffDir);
|
addRuffToPath(setupResult.ruffDir);
|
||||||
|
setOutputFormat();
|
||||||
|
addMatchers();
|
||||||
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}`);
|
||||||
|
|
||||||
@@ -53,11 +57,16 @@ async function run(): Promise<void> {
|
|||||||
async function setupRuff(
|
async function setupRuff(
|
||||||
platform: Platform,
|
platform: Platform,
|
||||||
arch: Architecture,
|
arch: Architecture,
|
||||||
versionInput: string,
|
|
||||||
checkSum: string | undefined,
|
checkSum: string | undefined,
|
||||||
githubToken: string,
|
githubToken: string,
|
||||||
): Promise<{ ruffDir: string; version: string }> {
|
): Promise<{ ruffDir: string; version: string }> {
|
||||||
const resolvedVersion = await resolveVersion(versionInput, githubToken);
|
const resolvedVersion = await determineVersion();
|
||||||
|
const manifestUrl = manifestFile || undefined;
|
||||||
|
if (semver.lt(resolvedVersion, "v0.0.247")) {
|
||||||
|
throw Error(
|
||||||
|
"This action does not support ruff versions older than 0.0.247",
|
||||||
|
);
|
||||||
|
}
|
||||||
const toolCacheResult = tryGetFromToolCache(arch, resolvedVersion);
|
const toolCacheResult = tryGetFromToolCache(arch, resolvedVersion);
|
||||||
if (toolCacheResult.installedPath) {
|
if (toolCacheResult.installedPath) {
|
||||||
core.info(`Found ruffDir in tool-cache for ${toolCacheResult.version}`);
|
core.info(`Found ruffDir in tool-cache for ${toolCacheResult.version}`);
|
||||||
@@ -73,6 +82,7 @@ async function setupRuff(
|
|||||||
resolvedVersion,
|
resolvedVersion,
|
||||||
checkSum,
|
checkSum,
|
||||||
githubToken,
|
githubToken,
|
||||||
|
manifestUrl,
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -81,11 +91,38 @@ async function setupRuff(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function determineVersion(): Promise<string> {
|
||||||
|
return await resolveRuffVersion({
|
||||||
|
manifestFile: manifestFile || undefined,
|
||||||
|
sourceDirectory: src,
|
||||||
|
version,
|
||||||
|
versionFile: versionFileInput,
|
||||||
|
workspaceRoot: process.env.GITHUB_WORKSPACE || ".",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function addRuffToPath(cachedPath: string): void {
|
function addRuffToPath(cachedPath: string): void {
|
||||||
core.addPath(cachedPath);
|
core.addPath(cachedPath);
|
||||||
core.info(`Added ${cachedPath} to the path`);
|
core.info(`Added ${cachedPath} to the path`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setOutputFormat() {
|
||||||
|
core.exportVariable("RUFF_OUTPUT_FORMAT", "github");
|
||||||
|
core.info("Set RUFF_OUTPUT_FORMAT to github");
|
||||||
|
}
|
||||||
|
|
||||||
|
function addMatchers(): void {
|
||||||
|
const actionRoot = getActionRoot();
|
||||||
|
const matchersPath = path.join(actionRoot, ".github", "matchers");
|
||||||
|
core.info(`##[add-matcher]${path.join(matchersPath, "check.json")}`);
|
||||||
|
core.info(`##[add-matcher]${path.join(matchersPath, "format.json")}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getActionRoot(): string {
|
||||||
|
const entrypoint = process.argv[1] ?? process.cwd();
|
||||||
|
return path.resolve(path.dirname(entrypoint), "..", "..");
|
||||||
|
}
|
||||||
|
|
||||||
async function runRuff(
|
async function runRuff(
|
||||||
ruffExecutablePath: string,
|
ruffExecutablePath: string,
|
||||||
args: string[],
|
args: string[],
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
import * as github from "@actions/github";
|
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
|
import { Octokit } from "@octokit/core";
|
||||||
import { OWNER, REPO } from "./utils/constants";
|
import { paginateRest } from "@octokit/plugin-paginate-rest";
|
||||||
|
import { restEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
|
||||||
import * as semver from "semver";
|
import * as semver from "semver";
|
||||||
|
|
||||||
import { updateChecksums } from "./download/checksum/update-known-checksums";
|
import { updateChecksums } from "./download/checksum/update-known-checksums";
|
||||||
|
import { OWNER, REPO } from "./utils/constants";
|
||||||
|
|
||||||
|
const PaginatingOctokit = Octokit.plugin(paginateRest, restEndpointMethods);
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
const checksumFilePath = process.argv.slice(2)[0];
|
const checksumFilePath = process.argv.slice(2)[0];
|
||||||
const github_token = process.argv.slice(2)[1];
|
const githubToken = process.argv.slice(2)[1];
|
||||||
|
|
||||||
const octokit = github.getOctokit(github_token);
|
const octokit = new PaginatingOctokit({ auth: githubToken });
|
||||||
|
|
||||||
const response = await octokit.paginate(octokit.rest.repos.listReleases, {
|
const response = await octokit.paginate(octokit.rest.repos.listReleases, {
|
||||||
owner: OWNER,
|
owner: OWNER,
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
export const REPO = "ruff";
|
export const REPO = "ruff";
|
||||||
export const OWNER = "astral-sh";
|
export const OWNER = "astral-sh";
|
||||||
export const TOOL_CACHE_NAME = "ruff";
|
export const TOOL_CACHE_NAME = "ruff";
|
||||||
|
export const VERSIONS_MANIFEST_URL =
|
||||||
|
"https://raw.githubusercontent.com/astral-sh/versions/main/v1/ruff.ndjson";
|
||||||
|
export const GITHUB_RELEASES_PREFIX =
|
||||||
|
"https://github.com/astral-sh/ruff/releases/download/";
|
||||||
|
export const ASTRAL_MIRROR_PREFIX =
|
||||||
|
"https://releases.astral.sh/github/ruff/releases/download/";
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { ProxyAgent, type RequestInit, fetch as undiciFetch } from "undici";
|
||||||
|
|
||||||
|
export function getProxyAgent() {
|
||||||
|
const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy;
|
||||||
|
if (httpProxy) {
|
||||||
|
return new ProxyAgent(httpProxy);
|
||||||
|
}
|
||||||
|
|
||||||
|
const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy;
|
||||||
|
if (httpsProxy) {
|
||||||
|
return new ProxyAgent(httpsProxy);
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const fetch = async (url: string, opts: RequestInit) =>
|
||||||
|
await undiciFetch(url, {
|
||||||
|
dispatcher: getProxyAgent(),
|
||||||
|
...opts,
|
||||||
|
});
|
||||||
@@ -5,3 +5,5 @@ export const checkSum = core.getInput("checksum");
|
|||||||
export const githubToken = core.getInput("github-token");
|
export const githubToken = core.getInput("github-token");
|
||||||
export const args = core.getInput("args");
|
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 manifestFile = core.getInput("manifest-file");
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ export type Architecture = "i686" | "x86_64" | "aarch64";
|
|||||||
export function getArch(): Architecture | undefined {
|
export function getArch(): Architecture | undefined {
|
||||||
const arch = process.arch;
|
const arch = process.arch;
|
||||||
const archMapping: { [key: string]: Architecture } = {
|
const archMapping: { [key: string]: Architecture } = {
|
||||||
|
arm64: "aarch64",
|
||||||
ia32: "i686",
|
ia32: "i686",
|
||||||
x64: "x86_64",
|
x64: "x86_64",
|
||||||
arm64: "aarch64",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (arch in archMapping) {
|
if (arch in archMapping) {
|
||||||
@@ -22,8 +22,8 @@ export function getArch(): Architecture | undefined {
|
|||||||
export function getPlatform(): Platform | undefined {
|
export function getPlatform(): Platform | undefined {
|
||||||
const platform = process.platform;
|
const platform = process.platform;
|
||||||
const platformMapping: { [key: string]: Platform } = {
|
const platformMapping: { [key: string]: Platform } = {
|
||||||
linux: "unknown-linux-gnu",
|
|
||||||
darwin: "apple-darwin",
|
darwin: "apple-darwin",
|
||||||
|
linux: "unknown-linux-gnu",
|
||||||
win32: "pc-windows-msvc",
|
win32: "pc-windows-msvc",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import * as fs from "node:fs";
|
||||||
|
import * as path from "node:path";
|
||||||
|
import * as core from "@actions/core";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search for a pyproject.toml file starting from the given directory
|
||||||
|
* and traversing upwards through parent directories until reaching
|
||||||
|
* the GitHub workspace root.
|
||||||
|
*
|
||||||
|
* @param startDir The directory to start the search from (e.g., the src input)
|
||||||
|
* @param workspaceRoot The GitHub workspace directory (GITHUB_WORKSPACE)
|
||||||
|
* @returns The path to the found pyproject.toml, or undefined if not found
|
||||||
|
*/
|
||||||
|
export function findPyprojectToml(
|
||||||
|
startDir: string,
|
||||||
|
workspaceRoot: string,
|
||||||
|
): string | undefined {
|
||||||
|
let currentDir = path.resolve(startDir);
|
||||||
|
const resolvedWorkspaceRoot = path.resolve(workspaceRoot);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
const pyprojectPath = path.join(currentDir, "pyproject.toml");
|
||||||
|
core.debug(`Checking for ${pyprojectPath}`);
|
||||||
|
|
||||||
|
if (fs.existsSync(pyprojectPath)) {
|
||||||
|
core.info(`Found pyproject.toml at ${pyprojectPath}`);
|
||||||
|
return pyprojectPath;
|
||||||
|
}
|
||||||
|
if (currentDir === resolvedWorkspaceRoot) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parentDir = path.dirname(currentDir);
|
||||||
|
if (
|
||||||
|
parentDir === currentDir ||
|
||||||
|
!isPathWithinWorkspace(parentDir, resolvedWorkspaceRoot)
|
||||||
|
) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentDir = parentDir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a given path is within or equal to the workspace root.
|
||||||
|
*
|
||||||
|
* @param checkPath The path to check
|
||||||
|
* @param workspaceRoot The workspace root directory
|
||||||
|
* @returns true if within or equal to workspace, false if outside, undefined if can't determine
|
||||||
|
*/
|
||||||
|
function isPathWithinWorkspace(
|
||||||
|
checkPath: string,
|
||||||
|
workspaceRoot: string,
|
||||||
|
): boolean {
|
||||||
|
const relativePath = path.relative(workspaceRoot, checkPath);
|
||||||
|
return !relativePath.startsWith("..") && !path.isAbsolute(relativePath);
|
||||||
|
}
|
||||||
@@ -0,0 +1,185 @@
|
|||||||
|
import fs from "node:fs";
|
||||||
|
import * as core from "@actions/core";
|
||||||
|
import * as toml from "smol-toml";
|
||||||
|
import { normalizeVersionSpecifier } from "./specifier";
|
||||||
|
import type { ParsedVersionFile, VersionFileFormat } from "./types";
|
||||||
|
|
||||||
|
interface VersionFileParser {
|
||||||
|
format: VersionFileFormat;
|
||||||
|
parse(filePath: string): string | undefined;
|
||||||
|
supports(filePath: string): boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Pyproject {
|
||||||
|
project?: {
|
||||||
|
dependencies?: string[];
|
||||||
|
"optional-dependencies"?: Record<string, string[]>;
|
||||||
|
};
|
||||||
|
"dependency-groups"?: Record<string, Array<string | object>>;
|
||||||
|
tool?: {
|
||||||
|
poetry?: {
|
||||||
|
dependencies?: Record<string, string | object>;
|
||||||
|
group?: Record<string, { dependencies: Record<string, string | object> }>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const VERSION_FILE_PARSERS: VersionFileParser[] = [
|
||||||
|
{
|
||||||
|
format: "pyproject.toml",
|
||||||
|
parse: (filePath) => {
|
||||||
|
const fileContent = fs.readFileSync(filePath, "utf-8");
|
||||||
|
return getRuffVersionFromPyprojectContent(fileContent);
|
||||||
|
},
|
||||||
|
supports: (filePath) => filePath.endsWith("pyproject.toml"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
format: "requirements",
|
||||||
|
parse: (filePath) => {
|
||||||
|
const fileContent = fs.readFileSync(filePath, "utf-8");
|
||||||
|
return getRuffVersionFromRequirementsText(fileContent);
|
||||||
|
},
|
||||||
|
supports: (filePath) => filePath.endsWith(".txt"),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export function getParsedVersionFile(
|
||||||
|
filePath: string,
|
||||||
|
): ParsedVersionFile | undefined {
|
||||||
|
core.info(`Trying to find version for ruff in: ${filePath}`);
|
||||||
|
|
||||||
|
if (!fs.existsSync(filePath)) {
|
||||||
|
core.warning(`Could not find file: ${filePath}`);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parser = getVersionFileParser(filePath);
|
||||||
|
if (parser === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const specifier = parser.parse(filePath);
|
||||||
|
if (specifier === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalizedSpecifier = normalizeVersionSpecifier(specifier);
|
||||||
|
core.info(`Found version for ruff in ${filePath}: ${normalizedSpecifier}`);
|
||||||
|
return {
|
||||||
|
format: parser.format,
|
||||||
|
specifier: normalizedSpecifier,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
core.warning(
|
||||||
|
`Error while parsing ${filePath}: ${(error as Error).message}`,
|
||||||
|
);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getRuffVersionFromFile(filePath: string): string | undefined {
|
||||||
|
return getParsedVersionFile(filePath)?.specifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function findRuffVersionInSpec(spec: string): string | undefined {
|
||||||
|
const trimmedSpec = spec.trim();
|
||||||
|
|
||||||
|
if (!trimmedSpec.startsWith("ruff")) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
let versionSpec = trimmedSpec.slice("ruff".length);
|
||||||
|
if (!versionSpec.match(/^(?:\s+|[=<>~!])/)) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
versionSpec = versionSpec.replace(/\\$/, "").trim();
|
||||||
|
|
||||||
|
const match = versionSpec.match(/^([^;]+)(?:;.*)?$/);
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
let version = match[1].trim();
|
||||||
|
if (version) {
|
||||||
|
version = normalizeVersionSpecifier(version);
|
||||||
|
if (trimmedSpec.includes(";")) {
|
||||||
|
core.warning(
|
||||||
|
"Environment markers are ignored. ruff is a standalone tool that works independently of Python version.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
core.info(`Found ruff version in requirements file: ${version}`);
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getRuffVersionFromRequirementsText(
|
||||||
|
fileContent: string,
|
||||||
|
): string | undefined {
|
||||||
|
return getRuffVersionFromAllDependencies(fileContent.split("\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getRuffVersionFromPyprojectContent(
|
||||||
|
pyprojectContent: string,
|
||||||
|
): string | undefined {
|
||||||
|
const pyproject = parsePyprojectContent(pyprojectContent);
|
||||||
|
return getRuffVersionFromParsedPyproject(pyproject);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parsePyprojectContent(pyprojectContent: string): Pyproject {
|
||||||
|
return toml.parse(pyprojectContent) as Pyproject;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getVersionFileParser(filePath: string): VersionFileParser | undefined {
|
||||||
|
return VERSION_FILE_PARSERS.find((parser) => parser.supports(filePath));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRuffVersionFromParsedPyproject(
|
||||||
|
pyproject: Pyproject,
|
||||||
|
): string | undefined {
|
||||||
|
const dependencies: string[] = pyproject.project?.dependencies || [];
|
||||||
|
const optionalDependencies: string[] = Object.values(
|
||||||
|
pyproject.project?.["optional-dependencies"] || {},
|
||||||
|
).flat();
|
||||||
|
const devDependencies: string[] = Object.values(
|
||||||
|
pyproject["dependency-groups"] || {},
|
||||||
|
)
|
||||||
|
.flat()
|
||||||
|
.filter((item: string | object) => typeof item === "string");
|
||||||
|
|
||||||
|
return (
|
||||||
|
getRuffVersionFromAllDependencies(
|
||||||
|
dependencies.concat(optionalDependencies, devDependencies),
|
||||||
|
) || getRuffVersionFromPoetryGroups(pyproject)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRuffVersionFromPoetryGroups(
|
||||||
|
pyproject: Pyproject,
|
||||||
|
): string | undefined {
|
||||||
|
const poetry = pyproject.tool?.poetry || {};
|
||||||
|
const poetryGroups = Object.values(poetry.group || {});
|
||||||
|
if (poetry.dependencies) {
|
||||||
|
poetryGroups.unshift({ dependencies: poetry.dependencies });
|
||||||
|
}
|
||||||
|
|
||||||
|
return poetryGroups
|
||||||
|
.flatMap((group) => Object.entries(group.dependencies))
|
||||||
|
.map(([name, spec]) => {
|
||||||
|
if (typeof spec === "string") {
|
||||||
|
return findRuffVersionInSpec(`${name} ${spec}`);
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
})
|
||||||
|
.find((version) => version !== undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRuffVersionFromAllDependencies(
|
||||||
|
allDependencies: string[],
|
||||||
|
): string | undefined {
|
||||||
|
return allDependencies
|
||||||
|
.map((dependency) => findRuffVersionInSpec(dependency))
|
||||||
|
.find((version) => version !== undefined);
|
||||||
|
}
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
import * as core from "@actions/core";
|
||||||
|
import * as tc from "@actions/tool-cache";
|
||||||
|
import * as pep440 from "@renovatebot/pep440";
|
||||||
|
import { getAllVersions, getLatestVersion } from "../download/manifest";
|
||||||
|
import {
|
||||||
|
type ParsedVersionSpecifier,
|
||||||
|
parseVersionSpecifier,
|
||||||
|
} from "./specifier";
|
||||||
|
import type { ResolveRuffVersionOptions } from "./types";
|
||||||
|
import { resolveVersionRequest } from "./version-request-resolver";
|
||||||
|
|
||||||
|
interface ConcreteVersionResolutionContext {
|
||||||
|
manifestUrl?: string;
|
||||||
|
parsedSpecifier: ParsedVersionSpecifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ConcreteVersionResolver {
|
||||||
|
resolve(
|
||||||
|
context: ConcreteVersionResolutionContext,
|
||||||
|
): Promise<string | undefined>;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ExactVersionResolver implements ConcreteVersionResolver {
|
||||||
|
async resolve(
|
||||||
|
context: ConcreteVersionResolutionContext,
|
||||||
|
): Promise<string | undefined> {
|
||||||
|
if (context.parsedSpecifier.kind !== "exact") {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
core.debug(
|
||||||
|
`Version ${context.parsedSpecifier.normalized} is an explicit version.`,
|
||||||
|
);
|
||||||
|
return context.parsedSpecifier.normalized;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class LatestVersionResolver implements ConcreteVersionResolver {
|
||||||
|
async resolve(
|
||||||
|
context: ConcreteVersionResolutionContext,
|
||||||
|
): Promise<string | undefined> {
|
||||||
|
if (context.parsedSpecifier.kind !== "latest") {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return await getLatestVersion(context.manifestUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RangeVersionResolver implements ConcreteVersionResolver {
|
||||||
|
async resolve(
|
||||||
|
context: ConcreteVersionResolutionContext,
|
||||||
|
): Promise<string | undefined> {
|
||||||
|
if (context.parsedSpecifier.kind !== "range") {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const availableVersions = await getAllVersions(context.manifestUrl);
|
||||||
|
const resolvedVersion = maxSatisfying(
|
||||||
|
availableVersions,
|
||||||
|
context.parsedSpecifier.normalized,
|
||||||
|
);
|
||||||
|
if (resolvedVersion === undefined) {
|
||||||
|
throw new Error(`No version found for ${context.parsedSpecifier.raw}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
core.debug(`Resolved version: ${resolvedVersion}`);
|
||||||
|
return resolvedVersion;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const CONCRETE_VERSION_RESOLVERS: ConcreteVersionResolver[] = [
|
||||||
|
new ExactVersionResolver(),
|
||||||
|
new LatestVersionResolver(),
|
||||||
|
new RangeVersionResolver(),
|
||||||
|
];
|
||||||
|
|
||||||
|
export async function resolveRuffVersion(
|
||||||
|
options: ResolveRuffVersionOptions,
|
||||||
|
): Promise<string> {
|
||||||
|
const request = resolveVersionRequest(options);
|
||||||
|
return await resolveVersion(request.specifier, options.manifestFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function resolveVersion(
|
||||||
|
versionInput: string,
|
||||||
|
manifestUrl?: string,
|
||||||
|
): Promise<string> {
|
||||||
|
core.debug(`Resolving ${versionInput}...`);
|
||||||
|
|
||||||
|
const context: ConcreteVersionResolutionContext = {
|
||||||
|
manifestUrl,
|
||||||
|
parsedSpecifier: parseVersionSpecifier(versionInput),
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const resolver of CONCRETE_VERSION_RESOLVERS) {
|
||||||
|
const version = await resolver.resolve(context);
|
||||||
|
if (version !== undefined) {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(`No version found for ${versionInput}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function maxSatisfying(
|
||||||
|
versions: string[],
|
||||||
|
version: string,
|
||||||
|
): string | undefined {
|
||||||
|
const maxSemver = tc.evaluateVersions(versions, version);
|
||||||
|
if (maxSemver !== "") {
|
||||||
|
core.debug(`Found a version that satisfies the semver range: ${maxSemver}`);
|
||||||
|
return maxSemver;
|
||||||
|
}
|
||||||
|
|
||||||
|
const maxPep440 = pep440.maxSatisfying(versions, version);
|
||||||
|
if (maxPep440 !== null) {
|
||||||
|
core.debug(
|
||||||
|
`Found a version that satisfies the pep440 specifier: ${maxPep440}`,
|
||||||
|
);
|
||||||
|
return maxPep440;
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import * as tc from "@actions/tool-cache";
|
||||||
|
|
||||||
|
export type ParsedVersionSpecifier =
|
||||||
|
| {
|
||||||
|
kind: "exact";
|
||||||
|
normalized: string;
|
||||||
|
raw: string;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
kind: "latest";
|
||||||
|
normalized: "latest";
|
||||||
|
raw: string;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
kind: "range";
|
||||||
|
normalized: string;
|
||||||
|
raw: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function normalizeVersionSpecifier(specifier: string): string {
|
||||||
|
const trimmedSpecifier = specifier.trim();
|
||||||
|
|
||||||
|
if (trimmedSpecifier.startsWith("==")) {
|
||||||
|
return trimmedSpecifier.slice(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return trimmedSpecifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseVersionSpecifier(
|
||||||
|
specifier: string,
|
||||||
|
): ParsedVersionSpecifier {
|
||||||
|
const raw = specifier.trim();
|
||||||
|
const normalized = normalizeVersionSpecifier(raw);
|
||||||
|
|
||||||
|
if (normalized === "latest") {
|
||||||
|
return {
|
||||||
|
kind: "latest",
|
||||||
|
normalized: "latest",
|
||||||
|
raw,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tc.isExplicitVersion(normalized)) {
|
||||||
|
return {
|
||||||
|
kind: "exact",
|
||||||
|
normalized,
|
||||||
|
raw,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
kind: "range",
|
||||||
|
normalized,
|
||||||
|
raw,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
export type VersionSource =
|
||||||
|
| "input"
|
||||||
|
| "version-file"
|
||||||
|
| "pyproject.toml"
|
||||||
|
| "default";
|
||||||
|
|
||||||
|
export type VersionFileFormat = "pyproject.toml" | "requirements";
|
||||||
|
|
||||||
|
export interface ParsedVersionFile {
|
||||||
|
format: VersionFileFormat;
|
||||||
|
specifier: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ResolveRuffVersionOptions {
|
||||||
|
manifestFile?: string;
|
||||||
|
sourceDirectory: string;
|
||||||
|
version?: string;
|
||||||
|
versionFile?: string;
|
||||||
|
workspaceRoot: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface VersionRequest {
|
||||||
|
format?: VersionFileFormat;
|
||||||
|
source: VersionSource;
|
||||||
|
sourcePath?: string;
|
||||||
|
specifier: string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
import * as core from "@actions/core";
|
||||||
|
import { findPyprojectToml } from "../utils/pyproject-finder";
|
||||||
|
import { getParsedVersionFile } from "./file-parser";
|
||||||
|
import { normalizeVersionSpecifier } from "./specifier";
|
||||||
|
import type {
|
||||||
|
ParsedVersionFile,
|
||||||
|
ResolveRuffVersionOptions,
|
||||||
|
VersionRequest,
|
||||||
|
} from "./types";
|
||||||
|
|
||||||
|
export interface VersionRequestResolver {
|
||||||
|
resolve(context: VersionRequestContext): VersionRequest | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class VersionRequestContext {
|
||||||
|
readonly sourceDirectory: string;
|
||||||
|
readonly version: string | undefined;
|
||||||
|
readonly versionFile: string | undefined;
|
||||||
|
readonly workspaceRoot: string;
|
||||||
|
|
||||||
|
private readonly parsedFiles = new Map<
|
||||||
|
string,
|
||||||
|
ParsedVersionFile | undefined
|
||||||
|
>();
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
version: string | undefined,
|
||||||
|
versionFile: string | undefined,
|
||||||
|
sourceDirectory: string,
|
||||||
|
workspaceRoot: string,
|
||||||
|
) {
|
||||||
|
this.version = version;
|
||||||
|
this.versionFile = versionFile;
|
||||||
|
this.sourceDirectory = sourceDirectory;
|
||||||
|
this.workspaceRoot = workspaceRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
getVersionFile(filePath: string): ParsedVersionFile | undefined {
|
||||||
|
const cachedResult = this.parsedFiles.get(filePath);
|
||||||
|
if (cachedResult !== undefined || this.parsedFiles.has(filePath)) {
|
||||||
|
return cachedResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = getParsedVersionFile(filePath);
|
||||||
|
this.parsedFiles.set(filePath, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
getWorkspacePyprojectPath(): string | undefined {
|
||||||
|
return findPyprojectToml(this.sourceDirectory, this.workspaceRoot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ExplicitInputVersionResolver implements VersionRequestResolver {
|
||||||
|
resolve(context: VersionRequestContext): VersionRequest | undefined {
|
||||||
|
if (context.version === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
source: "input",
|
||||||
|
specifier: normalizeVersionSpecifier(context.version),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class VersionFileVersionResolver implements VersionRequestResolver {
|
||||||
|
resolve(context: VersionRequestContext): VersionRequest | undefined {
|
||||||
|
if (context.versionFile === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const versionFile = context.getVersionFile(context.versionFile);
|
||||||
|
if (versionFile === undefined) {
|
||||||
|
core.warning(
|
||||||
|
`Could not parse version from ${context.versionFile}. Using latest version.`,
|
||||||
|
);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
format: versionFile.format,
|
||||||
|
source: "version-file",
|
||||||
|
sourcePath: context.versionFile,
|
||||||
|
specifier: versionFile.specifier,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class WorkspaceVersionResolver implements VersionRequestResolver {
|
||||||
|
resolve(context: VersionRequestContext): VersionRequest | undefined {
|
||||||
|
const pyprojectPath = context.getWorkspacePyprojectPath();
|
||||||
|
if (!pyprojectPath) {
|
||||||
|
core.info("Could not find pyproject.toml. Using latest version.");
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const versionFile = context.getVersionFile(pyprojectPath);
|
||||||
|
if (versionFile === undefined) {
|
||||||
|
core.info(
|
||||||
|
`Could not parse version from ${pyprojectPath}. Using latest version.`,
|
||||||
|
);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
format: versionFile.format,
|
||||||
|
source: "pyproject.toml",
|
||||||
|
sourcePath: pyprojectPath,
|
||||||
|
specifier: versionFile.specifier,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class LatestVersionResolver implements VersionRequestResolver {
|
||||||
|
resolve(): VersionRequest {
|
||||||
|
return {
|
||||||
|
source: "default",
|
||||||
|
specifier: "latest",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const VERSION_REQUEST_RESOLVERS: VersionRequestResolver[] = [
|
||||||
|
new ExplicitInputVersionResolver(),
|
||||||
|
new VersionFileVersionResolver(),
|
||||||
|
new WorkspaceVersionResolver(),
|
||||||
|
new LatestVersionResolver(),
|
||||||
|
];
|
||||||
|
|
||||||
|
export function resolveVersionRequest(
|
||||||
|
options: ResolveRuffVersionOptions,
|
||||||
|
): VersionRequest {
|
||||||
|
const version = emptyToUndefined(options.version);
|
||||||
|
const versionFile = emptyToUndefined(options.versionFile);
|
||||||
|
|
||||||
|
if (version !== undefined && versionFile !== undefined) {
|
||||||
|
throw new Error(
|
||||||
|
"It is not allowed to specify both version and version-file",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const context = new VersionRequestContext(
|
||||||
|
version,
|
||||||
|
versionFile,
|
||||||
|
options.sourceDirectory,
|
||||||
|
options.workspaceRoot,
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const resolver of VERSION_REQUEST_RESOLVERS) {
|
||||||
|
const request = resolver.resolve(context);
|
||||||
|
if (request !== undefined) {
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error("Could not resolve a requested Ruff version.");
|
||||||
|
}
|
||||||
|
|
||||||
|
function emptyToUndefined(value: string | undefined): string | undefined {
|
||||||
|
return value === undefined || value === "" ? undefined : value;
|
||||||
|
}
|
||||||
+8
-8
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
|
"esModuleInterop": true,
|
||||||
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
|
"isolatedModules": true,
|
||||||
"outDir": "./lib" /* Redirect output structure to the directory. */,
|
"module": "esnext",
|
||||||
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
|
"moduleResolution": "bundler",
|
||||||
"strict": true /* Enable all strict type-checking options. */,
|
"noImplicitAny": true,
|
||||||
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
|
"strict": true,
|
||||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
"target": "ES2022"
|
||||||
},
|
},
|
||||||
"exclude": ["node_modules", "**/*.test.ts"]
|
"include": ["src/**/*.ts"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user