Run app lint safely for fork PRs

This commit is contained in:
nmfretz committed 2026-06-19 09:38:44 +10:00
1 parent f2fd64e218
commit dfede5403a
2 files changed
+33 -6

No files matched your search

+25 -4
View File
@@ -1,7 +1,7 @@
name: Lint apps
on:
pull_request:
pull_request_target:
branches:
- master
@@ -13,13 +13,34 @@ jobs:
name: Lint apps
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
# This uses pull_request_target so fork PRs can lint without maintainer approval.
# Keep the linter code trusted: install and run tooling from the base repo only.
# The PR checkout below must be treated as app package data, not executable code.
- name: Checkout trusted lint tooling
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
with:
ref: ${{ github.base_ref }}
path: trusted
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-node@v6
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 22
cache: npm
cache-dependency-path: trusted/package-lock.json
- run: npm ci --ignore-scripts
- run: npm run lint:apps -- --changed "origin/${{ github.base_ref }}...HEAD" --check-images --format github
working-directory: trusted
- name: Checkout PR package files
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
path: submission
fetch-depth: 0
persist-credentials: false
- name: Fetch base branch for diff
run: git fetch --no-tags --depth=1 https://github.com/${{ github.repository }}.git "${{ github.base_ref }}:refs/remotes/base/${{ github.base_ref }}"
working-directory: submission
- name: Lint changed apps
run: node .tools/lint-apps.mjs --root ../submission --changed "base/${{ github.base_ref }}...HEAD" --check-images --format github
working-directory: trusted
+8 -2
View File
@@ -6,7 +6,7 @@ import path from "node:path";
import process from "node:process";
import YAML from "yaml";
const ROOT = path.resolve(import.meta.dirname, "..");
let ROOT = path.resolve(process.env.UMBREL_APP_LINT_ROOT || path.resolve(import.meta.dirname, ".."));
// Keep this list to hooks that umbrelOS actually calls for app packages.
const VALID_HOOKS = new Set([
@@ -71,6 +71,7 @@ function parseArgs(args) {
changed: null,
checkImages: false,
format: "text",
root: ROOT,
};
for (let index = 0; index < args.length; index += 1) {
@@ -85,6 +86,10 @@ function parseArgs(args) {
} else if (arg === "--format") {
options.format = args[++index];
if (!options.format) usage("Missing value for --format.");
} else if (arg === "--root") {
const root = args[++index];
if (!root) usage("Missing value for --root.");
options.root = path.resolve(root);
} else if (arg === "-h" || arg === "--help") {
usage(null, 0);
} else if (arg.startsWith("-")) {
@@ -106,7 +111,7 @@ function parseArgs(args) {
}
function usage(error, exitCode = 2) {
const message = `Usage: npm run lint:apps -- [APP ...] [--all] [--changed RANGE] [--check-images] [--format text|github|json]`;
const message = `Usage: npm run lint:apps -- [APP ...] [--all] [--changed RANGE] [--check-images] [--format text|github|json] [--root PATH]`;
if (error) console.error(error);
console.error(message);
process.exit(exitCode);
@@ -1741,5 +1746,6 @@ function escapeRegex(value) {
}
const cliOptions = parseArgs(process.argv.slice(2));
ROOT = cliOptions.root;
const cliLinter = new AppLinter(cliOptions);
process.exit(await cliLinter.run());