import { createRequire as __codeqlCreateRequire } from "module";import { fileURLToPath as __codeqlFileURLToPath } from "url";import { dirname as __codeqlDirname } from "path";var require = __codeqlCreateRequire(import.meta.url);var __filename = __codeqlFileURLToPath(import.meta.url);var __dirname = __codeqlDirname(__filename); import{e as qe}from"./chunks/chunk-NENGCOP5.js";import{c as Qe}from"./chunks/chunk-HIJVM6IW.js";import{a as Ve,b as Fe,c as Z,d as Pe,e as ke,f as z,g as Ue,h as Me}from"./chunks/chunk-2R674E4A.js";import{c as xe,e as x,f as V,g as Be,h as Ge}from"./chunks/chunk-B34OPX2S.js";import{b as Oe,d as Le,f as Ne}from"./chunks/chunk-LYJYPMC2.js";import{A as te,Ba as ue,Bb as K,C as oe,Ca as pe,Db as De,E as ae,Eb as Ee,Fb as L,Gb as Ae,Hb as ve,Ib as N,J as ie,Jb as Ce,Ka as ge,Kb as _e,L as ne,M as T,Mb as Ie,N as re,O as S,Oa as fe,S as U,Ta as me,_b as Y,bc as Te,c as k,ca as se,dc as Se,ea as q,fa as A,ga as M,h as Ke,ha as le,k as Ye,lb as ye,m as Ze,mb as H,p as ze,pa as J,qa as de,ra as ce,sa as a,ta as O,tb as we,ua as $,vb as be,xb as he,yb as Re,z as ee,zb as W}from"./chunks/chunk-V6LGBXSF.js";var o=k(Ye()),$e=k(Ze()),He=k(Ke()),X=k(ze());import*as v from"fs";import*as B from"path";var Xe="2.23.0";async function je(r,e,n){let t=await x("init","starting",r,e,await M(n),n);t!==void 0&&await V(t)}async function Je(r,e,n,t,u,i,s,R,y,w,b){let D=await x("init",xe(b),r,e,await M(w),w,b?.message,b?.stack);if(D===void 0)return;let C=a("languages"),h={...D,tools_input:a("tools")||"",tools_resolved_version:s,tools_source:i||"UNKNOWN",workflow_languages:C||""},f={};if(t?.downloadDurationMs!==void 0&&(f.tools_download_duration_ms=t.downloadDurationMs),u!==void 0&&(f.tools_feature_flags_valid=u),e!==void 0){let l=await Be(e,h,n,Math.round(await we(Object.values(e.trapCaches),w)),R,y);await V({...l,...f})}else await V({...h,...f})}async function et(r){let e=W(),n,t,u,i,s,R,y,w,b,D,C;try{ne($()),ge(),n={auth:ce("token"),externalRepoAuth:a("external-repository-token"),url:T("GITHUB_SERVER_URL"),apiURL:T("GITHUB_API_URL")};let l=await me();ie(l,e),le($(),l);let c=fe();s=ye(l,c,O(),e);let m=await tt(c,e),_=Oe();e.info(`Job run UUID is ${_}.`),o.exportVariable("JOB_RUN_UUID",_),o.exportVariable("CODEQL_ACTION_INIT_HAS_RUN","true"),u=a("config-file"),R=B.resolve(T("GITHUB_WORKSPACE"),a("source-root")||"");let g;try{g=await H(e,s)}catch(P){e.debug(`Failed to parse analysis kinds for 'starting' status report: ${A(P)}`)}if(await je(r,{analysisKinds:g},e),process.env.CODEQL_ACTION_SETUP_CODEQL_HAS_RUN==="true")throw new S("The 'init' action should not be run in the same workflow as 'setup-codeql'.");let I=await s.getEnabledDefaultCliVersions(l.type);w=I.toolsFeatureFlagsValid;let d=Y(a("languages")),F=g?.length===1&&g[0]==="code-scanning",p=await Ve(a("tools"),n,O(),l.type,I,d,F,s,e);if(i=p.codeql,y=p.toolsDownloadStatusReport,D=p.toolsVersion,b=p.toolsSource,C=p.zstdAvailability,await qe(e,i),Y(a("languages")).includes("rust")){let P="2.19.3",We="2.22.1",Q=(await i.getVersion()).version;if(X.lt(Q,P))throw new S(`Rust analysis is supported by CodeQL CLI version ${P} or higher, but found version ${Q}`);X.lt(Q,We)&&(o.exportVariable("CODEQL_ENABLE_EXPERIMENTAL_FEATURES","true"),e.info("Experimental Rust analysis enabled"))}g=await H(e,s);let E=a("debug")==="true"||o.isDebug(),j=m.orElse({}),G=await Ue(E,i,s,j);if(t=await Fe(s,{analysisKinds:g,languagesInput:a("languages"),queriesInput:a("queries"),packsInput:a("packs"),buildModeInput:a("build-mode"),ramInput:a("ram"),configFile:u,dbLocation:a("db-location"),configInput:a("config"),dependencyCachingEnabled:he(),debugMode:E,debugArtifactName:a("debug-artifact-name")||ee,debugDatabaseName:a("debug-database-name")||te,repository:c,tempDir:O(),codeql:i,workspacePath:T("GITHUB_WORKSPACE"),sourceRoot:R,githubVersion:l,apiDetails:n,features:s,repositoryProperties:j,enableFileCoverageInformation:G.enabled,logger:e}),t.languages.includes("swift")&&process.platform!=="darwin")throw new S("Swift analysis is only supported on macOS runner images. Please migrate to a macOS runner.");m.isFailure()&&L(t,N("codeql-action/repository-properties-load-failure","Failed to load repository properties",{error:A(m.value)})),G.enabledByRepositoryProperty&&L(t,N("codeql-action/file-coverage-on-prs-enabled-by-repository-property","File coverage on PRs enabled by repository property",{})),G.showDeprecationWarning&&Me(e),await ke(t.languages,i),await ot(i,s,e)}catch(l){let c=q(l);o.setFailed(c.message);let m=await x("init",c instanceof S?"user-error":"aborted",r,t,await M(e),e,c.message,c.stack);m!==void 0&&await V(m);return}let h,f;try{t.overlayDatabaseMode==="overlay"&&t.useOverlayDatabaseCaching&&await K("Checking cache for overlay-base database",async()=>{h=await Le(i,t,e),h||(t.overlayDatabaseMode="none",e.info("No overlay-base database found in cache, reverting overlay database mode to none."))}),t.overlayDatabaseMode!=="overlay"&&z(t,e),C&&await at(t,C),y&&L(t,N("codeql-action/bundle-download-telemetry","CodeQL bundle download telemetry",y));let l=process.env.GOFLAGS;if(l&&(o.exportVariable("GOFLAGS",l),o.warning("Passing the GOFLAGS env parameter to the init action is deprecated. Please move this to the analyze action.")),t.languages.includes("go")&&process.platform==="linux")try{let d=await He.which("go",!0);if((await pe(d)).includes("statically linked")&&!await i.supportsFeature("indirectTracingSupportsStaticBinaries"))try{e.debug("Applying static binary workaround for Go");let p=B.resolve(O(),"codeql-action-go-tracing","bin");v.mkdirSync(p,{recursive:!0}),o.addPath(p);let E=B.resolve(p,"go");v.writeFileSync(E,`#!/bin/bash exec ${d} "$@"`),v.chmodSync(E,"755"),o.exportVariable("CODEQL_ACTION_GO_BINARY",E)}catch(p){e.warning(`Analyzing Go on Linux, but failed to install wrapper script. Tracing custom builds may fail: ${p}`)}else o.exportVariable("CODEQL_ACTION_GO_BINARY",d)}catch(d){e.warning(`Failed to determine the location of the Go binary: ${d}`),d instanceof ue&&Ee(t,"go",De("go/workflow/file-program-unavailable","The `file` program is required on Linux, but does not appear to be installed",{markdownMessage:"CodeQL was unable to find the `file` program on this system. Ensure that the `file` program is installed on Linux runners and accessible.",visibility:{statusPage:!0,telemetry:!0,cliSummaryTable:!0},severity:"warning"}))}if(o.exportVariable("CODEQL_RAM",process.env.CODEQL_RAM||oe(a("ram"),e).toString()),o.exportVariable("CODEQL_THREADS",process.env.CODEQL_THREADS||ae(a("threads"),e).toString()),await s.getValue("disable_kotlin_analysis_enabled")&&o.exportVariable("CODEQL_EXTRACTOR_JAVA_AGENT_DISABLE_KOTLIN","true"),await U(i,"2.20.3")&&!await U(i,"2.20.4")&&o.exportVariable("CODEQL_EXTRACTOR_KOTLIN_OVERRIDE_MAXIMUM_VERSION_LIMIT","2.1.20"),be(t.dependencyCachingEnabled)){let d=await Qe(i,s,t.languages,e);f=d.statusReport,t.dependencyCachingRestoredKeys=d.restoredKeys}a("setup-python-dependencies")!==void 0&&e.warning("The setup-python-dependencies input is deprecated and no longer has any effect. We recommend removing any references from your workflows. See https://github.blog/changelog/2024-01-23-codeql-2-16-python-dependency-installation-disabled-new-queries-and-bug-fixes/ for more information."),process.env.CODEQL_ACTION_DISABLE_PYTHON_DEPENDENCY_INSTALLATION!==void 0&&e.warning("The CODEQL_ACTION_DISABLE_PYTHON_DEPENDENCY_INSTALLATION environment variable is deprecated and no longer has any effect. We recommend removing any references from your workflows. See https://github.blog/changelog/2024-01-23-codeql-2-16-python-dependency-installation-disabled-new-queries-and-bug-fixes/ for more information."),process.env.CODEQL_EXTRACTOR_JAVA_OPTION_MINIMIZE_DEPENDENCY_JARS?e.debug(`CODEQL_EXTRACTOR_JAVA_OPTION_MINIMIZE_DEPENDENCY_JARS is already set to '${process.env.CODEQL_EXTRACTOR_JAVA_OPTION_MINIMIZE_DEPENDENCY_JARS}', so the Action will not override it.`):await U(i,Xe)&&t.dependencyCachingEnabled&&t.buildMode==="none"&&t.languages.includes("java")&&o.exportVariable("CODEQL_EXTRACTOR_JAVA_OPTION_MINIMIZE_DEPENDENCY_JARS","true");let{registriesAuthTokens:m,qlconfigFile:_}=await Se(a("registries"),t.tempDir,e),g={GITHUB_TOKEN:n.auth,CODEQL_REGISTRIES_AUTH:m};await Z(g,i,t,R,"Runner.Worker.exe",_,e),t.overlayDatabaseMode!=="none"&&!await Pe(i,t,e)&&(e.info("Reverting overlay database mode to None due to incompatible packs."),t.overlayDatabaseMode="none",z(t,e,{disableExistingDirectoryWarning:!0}),await Z(g,i,t,R,"Runner.Worker.exe",_,e));let I=await Ne(i,t);if(I!==void 0)for(let[d,F]of Object.entries(I.env))o.exportVariable(d,F);if(await s.getValue("java_network_debugging")){let d=re("JAVA_TOOL_OPTIONS")||"";o.exportVariable("JAVA_TOOL_OPTIONS",`${d} -Djavax.net.debug=all`)}ve(t),await Te(t,e),o.setOutput("codeql-path",t.codeQLCmd),o.setOutput("codeql-version",(await i.getVersion()).version)}catch(l){let c=q(l);o.setFailed(c.message),await Je(r,t,void 0,y,w,b,D,h,f,e,c);return}finally{Ae()}await Je(r,t,u,y,w,b,D,h,f,e)}async function tt(r,e){let n=$e.context.payload.repository?.owner.type;if(e.debug(`Repository owner type is '${n??"unknown"}'.`),n==="User")return e.debug("Skipping loading repository properties because the repository is owned by a user and therefore cannot have repository properties."),new J({});try{return new J(await Re(e,r))}catch(t){return e.warning(`Failed to load repository properties: ${A(t)}`),new de(t)}}async function ot(r,e,n){await K("Computing PR diff ranges",async()=>{try{let t=await Ce(r,e,n);if(!t)return;let u=await Ie(t,n);if(u===void 0)return;_e(n,u);let i=new Set(u.map(s=>s.path)).size;n.info(`Persisted ${u.length} diff range(s) across ${i} file(s).`)}catch(t){n.warning(`Failed to compute and persist PR diff ranges: ${A(t)}`)}})}async function at(r,e){L(r,N("codeql-action/zstd-availability","Zstandard availability",e))}async function it(){let r=new Date,e=W();try{await et(r)}catch(n){o.setFailed(`init action failed: ${A(n)}`),await Ge("init",r,n,e)}await se()}it();export{Xe as CODEQL_VERSION_JAR_MINIMIZATION};