mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Merge pull request #1118 from izayl/feature/ci-skip
feat: add ci skip check
This commit is contained in:
98
apps/dokploy/__test__/deploy/github.test.ts
Normal file
98
apps/dokploy/__test__/deploy/github.test.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
import { extractCommitMessage } from "@/pages/api/deploy/[refreshToken]";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
describe("GitHub Webhook Skip CI", () => {
|
||||
const mockGithubHeaders = {
|
||||
"x-github-event": "push",
|
||||
};
|
||||
|
||||
const createMockBody = (message: string) => ({
|
||||
head_commit: {
|
||||
message,
|
||||
},
|
||||
});
|
||||
|
||||
const skipKeywords = [
|
||||
"[skip ci]",
|
||||
"[ci skip]",
|
||||
"[no ci]",
|
||||
"[skip actions]",
|
||||
"[actions skip]",
|
||||
];
|
||||
|
||||
it("should detect skip keywords in commit message", () => {
|
||||
for (const keyword of skipKeywords) {
|
||||
const message = `feat: add new feature ${keyword}`;
|
||||
const commitMessage = extractCommitMessage(
|
||||
mockGithubHeaders,
|
||||
createMockBody(message),
|
||||
);
|
||||
expect(commitMessage.includes(keyword)).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("should not detect skip keywords in normal commit message", () => {
|
||||
const message = "feat: add new feature";
|
||||
const commitMessage = extractCommitMessage(
|
||||
mockGithubHeaders,
|
||||
createMockBody(message),
|
||||
);
|
||||
for (const keyword of skipKeywords) {
|
||||
expect(commitMessage.includes(keyword)).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
it("should handle different webhook sources", () => {
|
||||
// GitHub
|
||||
expect(
|
||||
extractCommitMessage(
|
||||
{ "x-github-event": "push" },
|
||||
{ head_commit: { message: "[skip ci] test" } },
|
||||
),
|
||||
).toBe("[skip ci] test");
|
||||
|
||||
// GitLab
|
||||
expect(
|
||||
extractCommitMessage(
|
||||
{ "x-gitlab-event": "push" },
|
||||
{ commits: [{ message: "[skip ci] test" }] },
|
||||
),
|
||||
).toBe("[skip ci] test");
|
||||
|
||||
// Bitbucket
|
||||
expect(
|
||||
extractCommitMessage(
|
||||
{ "x-event-key": "repo:push" },
|
||||
{
|
||||
push: {
|
||||
changes: [{ new: { target: { message: "[skip ci] test" } } }],
|
||||
},
|
||||
},
|
||||
),
|
||||
).toBe("[skip ci] test");
|
||||
|
||||
// Gitea
|
||||
expect(
|
||||
extractCommitMessage(
|
||||
{ "x-gitea-event": "push" },
|
||||
{ commits: [{ message: "[skip ci] test" }] },
|
||||
),
|
||||
).toBe("[skip ci] test");
|
||||
});
|
||||
|
||||
it("should handle missing commit message", () => {
|
||||
expect(extractCommitMessage(mockGithubHeaders, {})).toBe("NEW COMMIT");
|
||||
expect(extractCommitMessage({ "x-gitlab-event": "push" }, {})).toBe(
|
||||
"NEW COMMIT",
|
||||
);
|
||||
expect(
|
||||
extractCommitMessage(
|
||||
{ "x-event-key": "repo:push" },
|
||||
{ push: { changes: [] } },
|
||||
),
|
||||
).toBe("NEW COMMIT");
|
||||
expect(extractCommitMessage({ "x-gitea-event": "push" }, {})).toBe(
|
||||
"NEW COMMIT",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -13,6 +13,7 @@ export default defineConfig({
|
||||
NODE: "test",
|
||||
},
|
||||
},
|
||||
plugins: [tsconfigPaths()],
|
||||
resolve: {
|
||||
alias: {
|
||||
"@dokploy/server": path.resolve(
|
||||
|
||||
@@ -71,6 +71,25 @@ export default async function handler(
|
||||
return;
|
||||
}
|
||||
|
||||
// skip workflow runs use keywords
|
||||
// @link https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/skipping-workflow-runs
|
||||
if (
|
||||
[
|
||||
"[skip ci]",
|
||||
"[ci skip]",
|
||||
"[no ci]",
|
||||
"[skip actions]",
|
||||
"[actions skip]",
|
||||
].find((keyword) =>
|
||||
extractCommitMessage(req.headers, req.body).includes(keyword),
|
||||
)
|
||||
) {
|
||||
res.status(200).json({
|
||||
message: "Deployment skipped: commit message contains skip keyword",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.headers["x-github-event"] === "push") {
|
||||
try {
|
||||
const branchName = githubBody?.ref?.replace("refs/heads/", "");
|
||||
|
||||
Reference in New Issue
Block a user