Skip to content

Commit

Permalink
feat: Add support for temp environments
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Jun 26, 2024
1 parent 45fb57c commit 8fe6f54
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 12 deletions.
34 changes: 28 additions & 6 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
32 changes: 26 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
value.env = `${value.env}${prEvent.number}`;
value.name = `Temp #${prEvent.number}`;
const dir = path.dirname(value.template);
value.path = path.join(dir, value.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 };
Expand Down

0 comments on commit 8fe6f54

Please sign in to comment.