Skip to content

Commit cc38863

Browse files
chore: add front auto refresh after publish
1 parent 7dad816 commit cc38863

3 files changed

Lines changed: 88 additions & 0 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@strapi/provider-upload-aws-s3": "^5.31.2",
2121
"@strapi/strapi": "5.31.2",
2222
"better-sqlite3": "12.4.1",
23+
"node-fetch": "2",
2324
"pg": "^8.16.3",
2425
"react": "^18.0.0",
2526
"react-dom": "^18.0.0",
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"use strict";
2+
3+
const fetch = require("node-fetch");
4+
5+
async function triggerGithub() {
6+
const owner = process.env.GITHUB_OWNER;
7+
const repo = process.env.GITHUB_REPO;
8+
const token = process.env.GITHUB_TOKEN;
9+
const eventType = process.env.GITHUB_EVENT_TYPE || "rebuild_site";
10+
11+
if (!owner || !repo || !token) {
12+
strapi.log.error("GITHUB_* env vars não configuradas, não vou disparar build.");
13+
return;
14+
}
15+
16+
const url = `https://api.github.com/repos/${owner}/${repo}/dispatches`;
17+
18+
strapi.log.info(`Disparando GitHub Actions para ${owner}/${repo} (event_type=${eventType})`);
19+
20+
try {
21+
const res = await fetch(url, {
22+
method: "POST",
23+
headers: {
24+
Accept: "application/vnd.github+json",
25+
Authorization: `Bearer ${token}`,
26+
"X-GitHub-Api-Version": "2022-11-28",
27+
},
28+
body: JSON.stringify({
29+
event_type: eventType,
30+
}),
31+
});
32+
33+
if (!res.ok) {
34+
const text = await res.text();
35+
strapi.log.error(`Erro ao chamar GitHub Actions: ${res.status} - ${text}`);
36+
} else {
37+
strapi.log.info("GitHub Actions disparado com sucesso (repository_dispatch).");
38+
}
39+
} catch (err) {
40+
strapi.log.error("Erro ao chamar GitHub Actions:", err);
41+
}
42+
}
43+
44+
module.exports = {
45+
async afterCreate(event) {
46+
strapi.log.info("afterCreate(show) chamado, disparando triggerGithub()");
47+
await triggerGithub();
48+
},
49+
50+
async afterUpdate(event) {
51+
const { result } = event;
52+
53+
strapi.log.info("afterUpdate(show) chamado");
54+
55+
if (result.publishedAt) {
56+
strapi.log.info("Registro publicado, disparando triggerGithub()");
57+
await triggerGithub();
58+
} else {
59+
strapi.log.info("Registro ainda não publicado, não disparando build.");
60+
}
61+
},
62+
};

yarn.lock

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9526,6 +9526,13 @@ node-abort-controller@^3.0.1:
95269526
resolved "https://registry.yarnpkg.com/node-abort-controller/-/node-abort-controller-3.1.1.tgz#a94377e964a9a37ac3976d848cb5c765833b8548"
95279527
integrity sha512-AGK2yQKIjRuqnc6VkX2Xj5d+QW8xZ87pa1UK6yA6ouUyuxfHuMP6umE5QK7UmTeOAymo+Zx1Fxiuw9rVx8taHQ==
95289528

9529+
node-fetch@2:
9530+
version "2.7.0"
9531+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
9532+
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
9533+
dependencies:
9534+
whatwg-url "^5.0.0"
9535+
95299536
node-machine-id@1.1.12:
95309537
version "1.1.12"
95319538
resolved "https://registry.yarnpkg.com/node-machine-id/-/node-machine-id-1.1.12.tgz#37904eee1e59b320bb9c5d6c0a59f3b469cb6267"
@@ -11996,6 +12003,11 @@ touch@^3.1.0:
1199612003
resolved "https://registry.yarnpkg.com/touch/-/touch-3.1.1.tgz#097a23d7b161476435e5c1344a95c0f75b4a5694"
1199712004
integrity sha512-r0eojU4bI8MnHr8c5bNo7lJDdI2qXlWWJk6a9EAFG7vbhTjElYhBVS3/miuE0uOuoLdb8Mc/rVfsmm6eo5o9GA==
1199812005

12006+
tr46@~0.0.3:
12007+
version "0.0.3"
12008+
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
12009+
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==
12010+
1199912011
tree-kill@^1.2.2:
1200012012
version "1.2.2"
1200112013
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc"
@@ -12415,6 +12427,11 @@ wcwidth@^1.0.1:
1241512427
dependencies:
1241612428
defaults "^1.0.3"
1241712429

12430+
webidl-conversions@^3.0.0:
12431+
version "3.0.1"
12432+
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
12433+
integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==
12434+
1241812435
webpack-bundle-analyzer@^4.10.1:
1241912436
version "4.10.2"
1242012437
resolved "https://registry.yarnpkg.com/webpack-bundle-analyzer/-/webpack-bundle-analyzer-4.10.2.tgz#633af2862c213730be3dbdf40456db171b60d5bd"
@@ -12497,6 +12514,14 @@ webpack@^5.90.3:
1249712514
watchpack "^2.4.4"
1249812515
webpack-sources "^3.3.3"
1249912516

12517+
whatwg-url@^5.0.0:
12518+
version "5.0.0"
12519+
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
12520+
integrity sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==
12521+
dependencies:
12522+
tr46 "~0.0.3"
12523+
webidl-conversions "^3.0.0"
12524+
1250012525
which-pm@2.0.0:
1250112526
version "2.0.0"
1250212527
resolved "https://registry.yarnpkg.com/which-pm/-/which-pm-2.0.0.tgz#8245609ecfe64bf751d0eef2f376d83bf1ddb7ae"

0 commit comments

Comments
 (0)