diff --git a/dist/index.js b/dist/index.js index 31d6d66..6777ee4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -35063,6 +35063,8 @@ var jsYaml = { /* harmony default export */ const js_yaml = (jsYaml); +// EXTERNAL MODULE: external "path" +var external_path_ = __nccwpck_require__(1017); // EXTERNAL MODULE: ./node_modules/brace-expansion/index.js var brace_expansion = __nccwpck_require__(3717); ;// CONCATENATED MODULE: ./node_modules/minimatch/dist/esm/assert-valid-pattern.js @@ -36921,6 +36923,7 @@ const parseDynamicList = (s) => { + try { const envs = js_yaml.load(core.getInput("envs")); const jobs = parseDynamicList(core.getInput("jobs")); @@ -36930,7 +36933,7 @@ try { const [, type, ref] = github.context.ref.match(/^refs\/(.+)\/(.+)$/); let count = 0; - for (const [env, value] of Object.entries(envs)) { + for (let [env, value] of Object.entries(envs)) { let patterns; let extraValues = {}; @@ -36939,12 +36942,31 @@ try { if (type !== "heads") continue; patterns = value; } else { - if (type === "heads") { - // Ref is a branch - patterns = value.branch; - } else if (type === "tags") { - // Ref is a tag - patterns = value.tag; + if (value.type === "temp") { + // Temp environments enabled + if (github.context.eventName === "pull_request") { + const prEvent = github.context.payload; + const targetLabel = value.label || prEvent.label?.name; + if ( + prEvent.action === "labeled" && + prEvent.label.name === targetLabel + ) { + patterns = ref; + env += prEvent.number; + value.name = `Temp #${prEvent.number}`; + const dir = external_path_.dirname(value.template); + value.path = external_path_.join(dir, env); + value.pr = prEvent.number; + } + } + } else { + if (type === "heads") { + // Ref is a branch + patterns = value.branch; + } else if (type === "tags") { + // Ref is a tag + patterns = value.tag; + } } extraValues = { ...value }; diff --git a/package-lock.json b/package-lock.json index 6e7d490..5a51fe2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@actions/core": "1.10.1", "@actions/github": "6.0.0", + "@octokit/webhooks-definitions": "3.67.3", "js-yaml": "4.1.0", "minimatch": "9.0.4" }, @@ -410,6 +411,12 @@ "@octokit/openapi-types": "^22.2.0" } }, + "node_modules/@octokit/webhooks-definitions": { + "version": "3.67.3", + "resolved": "https://registry.npmjs.org/@octokit/webhooks-definitions/-/webhooks-definitions-3.67.3.tgz", + "integrity": "sha512-do4Z1r2OVhuI0ihJhQ8Hg+yPWnBYEBNuFNCrvtPKoYT1w81jD7pBXgGe86lYuuNirkDHb0Nxt+zt4O5GiFJfgA==", + "deprecated": "Use @octokit/webhooks-types, @octokit/webhooks-schemas, or @octokit/webhooks-examples instead. See https://github.com/octokit/webhooks/issues/447" + }, "node_modules/@pkgr/core": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz", diff --git a/package.json b/package.json index c052439..de96b5d 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "dependencies": { "@actions/core": "1.10.1", "@actions/github": "6.0.0", + "@octokit/webhooks-definitions": "3.67.3", "js-yaml": "4.1.0", "minimatch": "9.0.4" }, diff --git a/src/index.js b/src/index.js index ce4fea3..17d7154 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,7 @@ import * as core from "@actions/core"; import * as github from "@actions/github"; import yaml from "js-yaml"; +import * as path from "path"; import { envName, matchPatterns, parseDynamicList } from "./util.js"; try { @@ -12,7 +13,7 @@ try { const [, type, ref] = github.context.ref.match(/^refs\/(.+)\/(.+)$/); let count = 0; - for (const [env, value] of Object.entries(envs)) { + for (let [env, value] of Object.entries(envs)) { let patterns; let extraValues = {}; @@ -21,12 +22,31 @@ try { if (type !== "heads") continue; patterns = value; } else { - if (type === "heads") { - // Ref is a branch - patterns = value.branch; - } else if (type === "tags") { - // Ref is a tag - patterns = value.tag; + if (value.type === "temp") { + // Temp environments enabled + if (github.context.eventName === "pull_request") { + const prEvent = github.context.payload; + const targetLabel = value.label || prEvent.label?.name; + if ( + prEvent.action === "labeled" && + prEvent.label.name === targetLabel + ) { + patterns = ref; + env += prEvent.number; + value.name = `Temp #${prEvent.number}`; + const dir = path.dirname(value.template); + value.path = path.join(dir, env); + value.pr = prEvent.number; + } + } + } else { + if (type === "heads") { + // Ref is a branch + patterns = value.branch; + } else if (type === "tags") { + // Ref is a tag + patterns = value.tag; + } } extraValues = { ...value };