import { escapeRegExp, regEx } from "../../../util/regex.js";
import { id } from "../../versioning/pep440/index.js";
import { id as id$1 } from "../../versioning/npm/index.js";
import { GithubReleasesDatasource } from "../../datasource/github-releases/index.js";
import { NpmDatasource } from "../../datasource/npm/index.js";
import { PypiDatasource } from "../../datasource/pypi/index.js";
import { id as id$2 } from "../../versioning/ruby/index.js";
import { RubyVersionDatasource } from "../../datasource/ruby-version/index.js";
import { id as id$3 } from "../../versioning/conda/index.js";
import { z } from "zod";

//#region lib/modules/manager/github-actions/community.ts
function matchAction(action) {
	return z.string().regex(regEx(`(?:https?://[^/]+/)?${escapeRegExp(action)}(?:@.+)?$`));
}
const SetupUV = z.object({
	uses: matchAction("astral-sh/setup-uv"),
	with: z.object({ version: z.string().optional() })
}).transform(({ with: val }) => {
	let skipStage;
	let skipReason;
	if (!val.version) {
		skipStage = "extract";
		skipReason = "unspecified-version";
	}
	return {
		datasource: GithubReleasesDatasource.id,
		depName: "astral-sh/uv",
		versioning: id$1,
		packageName: "astral-sh/uv",
		...skipStage && { skipStage },
		...skipReason && { skipReason },
		currentValue: val.version,
		depType: "uses-with"
	};
});
const SetupPnpm = z.object({
	uses: matchAction("pnpm/action-setup"),
	with: z.object({ version: z.string().optional() })
}).transform(({ with: val }) => {
	let skipStage;
	let skipReason;
	if (!val.version) {
		skipStage = "extract";
		skipReason = "unspecified-version";
	}
	return {
		datasource: NpmDatasource.id,
		depName: "pnpm",
		versioning: id$1,
		packageName: "pnpm",
		...skipStage && { skipStage },
		...skipReason && { skipReason },
		currentValue: val.version,
		depType: "uses-with"
	};
});
const SetupBun = z.object({
	uses: matchAction("oven-sh/setup-bun"),
	with: z.object({ "bun-version": z.string().optional() })
}).transform(({ with: val }) => {
	let skipStage;
	let skipReason;
	if (!val["bun-version"]) {
		skipStage = "extract";
		skipReason = "unspecified-version";
	}
	return {
		datasource: NpmDatasource.id,
		depName: "bun",
		versioning: id$1,
		packageName: "bun",
		...skipStage && { skipStage },
		...skipReason && { skipReason },
		currentValue: val["bun-version"],
		depType: "uses-with"
	};
});
const SetupDeno = z.object({
	uses: matchAction("denoland/setup-deno"),
	with: z.object({ "deno-version": z.string().optional() })
}).transform(({ with: val }) => {
	let skipStage;
	let skipReason;
	if (!val["deno-version"]) {
		skipStage = "extract";
		skipReason = "unspecified-version";
	}
	return {
		datasource: NpmDatasource.id,
		depName: "deno",
		versioning: id$1,
		packageName: "deno",
		...skipStage && { skipStage },
		...skipReason && { skipReason },
		currentValue: val["deno-version"],
		depType: "uses-with"
	};
});
const SetupRuby = z.object({
	uses: matchAction("ruby/setup-ruby"),
	with: z.object({ "ruby-version": z.string().optional() })
}).transform(({ with: val }) => {
	let skipStage;
	let skipReason;
	if (!val["ruby-version"]) {
		skipStage = "extract";
		skipReason = "unspecified-version";
	}
	return {
		datasource: RubyVersionDatasource.id,
		depName: "ruby",
		versioning: id$2,
		packageName: "ruby",
		...skipStage && { skipStage },
		...skipReason && { skipReason },
		currentValue: val["ruby-version"],
		depType: "uses-with"
	};
});
const SetupPDM = z.object({
	uses: matchAction("pdm-project/setup-pdm"),
	with: z.object({ version: z.string().optional() })
}).transform(({ with: val }) => {
	let skipStage;
	let skipReason;
	if (!val.version) {
		skipStage = "extract";
		skipReason = "unspecified-version";
	}
	return {
		datasource: PypiDatasource.id,
		depName: "pdm",
		versioning: id,
		packageName: "pdm",
		currentValue: val.version,
		...skipStage && { skipStage },
		...skipReason && { skipReason },
		depType: "uses-with"
	};
});
const InstallBinary = z.object({
	uses: z.union([matchAction("jaxxstorm/action-install-gh-release"), matchAction("sigoden/install-binary")]),
	with: z.object({
		repo: z.string(),
		tag: z.string()
	})
}).transform(({ with: val }) => {
	return {
		datasource: GithubReleasesDatasource.id,
		depName: val.repo,
		packageName: val.repo,
		currentValue: val.tag,
		depType: "uses-with"
	};
});
const SetupPixi = z.object({
	uses: matchAction("prefix-dev/setup-pixi"),
	with: z.object({ "pixi-version": z.string() })
}).transform(({ with: val }) => {
	return {
		datasource: GithubReleasesDatasource.id,
		versioning: id$3,
		depName: "prefix-dev/pixi",
		packageName: "prefix-dev/pixi",
		currentValue: val["pixi-version"],
		depType: "uses-with"
	};
});
const SetupHatch = z.object({
	uses: matchAction("pypa/hatch"),
	with: z.object({ version: z.string().optional() })
}).transform(({ with: val }) => {
	let skipStage;
	let skipReason;
	if (!val.version) {
		skipStage = "extract";
		skipReason = "unspecified-version";
	}
	return {
		datasource: GithubReleasesDatasource.id,
		depName: "pypa/hatch",
		packageName: "pypa/hatch",
		...skipStage && { skipStage },
		...skipReason && { skipReason },
		currentValue: val.version,
		depType: "uses-with",
		extractVersion: "^hatch-(?<version>.+)$"
	};
});
/**
* schema here should match the whole step,
* there may be some actions use env as arguments version.
*
* each type should return `PackageDependency | undefined`
*/
const CommunityActions = z.union([
	InstallBinary,
	SetupPDM,
	SetupPixi,
	SetupPnpm,
	SetupUV,
	SetupBun,
	SetupDeno,
	SetupRuby,
	SetupHatch
]);

//#endregion
export { CommunityActions };
//# sourceMappingURL=community.js.map