@@ -172,22 +172,22 @@ function parseAndCheckAlembic(response, source_directory) {
172172 const output = response.output;
173173 if (!output) {
174174 console.log("No output found in the response.");
175- return false;
175+ return { exists: false } ;
176176 }
177- const lines = output.split("\r\n" ).filter((line) => line.trim() !== "");
178- const alembicFound = lines.some ((line) => line.includes("**** "));
179- if (alembicFound ) {
180- console.log("Alembic found!");
181- return true;
177+ const lines = output.split(/\r?\n/ ).filter((line) => line.trim() !== "");
178+ const alembicIniPath = lines.find ((line) => line.includes("alembic.ini "));
179+ if (alembicIniPath ) {
180+ console.log("Alembic configuration found!");
181+ return { exists: true, path: alembicIniPath.trim() } ;
182182 }
183183 else {
184- console.log("Alembic not found! ");
185- return false;
184+ console.log("Alembic configuration not found, skipping migrations ");
185+ return { exists: false } ;
186186 }
187187 }
188188 catch (error) {
189189 console.error(`Error during Alembic check: ${error.message}`);
190- return false;
190+ return { exists: false } ;
191191 }
192192 });
193193}
@@ -231,14 +231,55 @@ function setupWebApp(baseWebAppUrl, api_token, domain_name) {
231231 }
232232 });
233233}
234+ function checkGitPullOutput(response) {
235+ return __awaiter(this, void 0, void 0, function* () {
236+ try {
237+ const output = response.output;
238+ if (!output) {
239+ return { success: true };
240+ }
241+ const lines = output.split(/\r?\n/).filter((line) => line.trim() !== "");
242+ if (lines.some(line => line.includes("Already up to date"))) {
243+ console.log("Repository is already up to date");
244+ return { success: true };
245+ }
246+ const hasLocalChanges = lines.some(line => line.includes("Your local changes to the following files would be overwritten by merge"));
247+ const hasUntrackedFiles = lines.some(line => line.includes("untracked working tree files would be overwritten by merge"));
248+ const hasError = lines.some(line => line.startsWith("error:"));
249+ if (hasLocalChanges) {
250+ return {
251+ success: false,
252+ error: "local_changes"
253+ };
254+ }
255+ else if (hasUntrackedFiles) {
256+ return {
257+ success: false,
258+ error: "untracked_files"
259+ };
260+ }
261+ else if (hasError) {
262+ return {
263+ success: false,
264+ error: "git_error"
265+ };
266+ }
267+ return { success: true };
268+ }
269+ catch (error) {
270+ console.error(`Error during Git pull check: ${error.message}`);
271+ return { success: false, error: "unknown" };
272+ }
273+ });
274+ }
234275function run() {
235276 return __awaiter(this, void 0, void 0, function* () {
236277 try {
237278 const username = core.getInput("username", { required: true });
238279 const api_token = core.getInput("api_token", { required: true });
239280 const host = core.getInput("host", { required: true });
240281 const domain_name = core.getInput("domain_name", { required: false }) || null;
241- const framework_type = core.getInput("framework_type", { required: false }) || "flask ";
282+ const framework_type = core.getInput("framework_type", { required: false }) || "django ";
242283 const baseApiUrl = `https://${host}/api/v0/user/${username}`;
243284 const baseConsoleUrl = `${baseApiUrl}/consoles/`;
244285 const baseWebAppUrl = `${baseApiUrl}/webapps/`;
@@ -251,15 +292,37 @@ function run() {
251292 const consoleRequestUrl = `${baseApiUrl}/consoles/${consoleId}/send_input/`;
252293 // Git Pull
253294 try {
254- yield postConsoleInput(consoleRequestUrl, api_token, `git -C ${web_app.source_directory} pull\n`, "Repository Pulled.");
295+ yield postConsoleInput(consoleRequestUrl, api_token, `git -C ${web_app.source_directory} pull\n`, "Checking repository status...");
296+ const pullResponse = yield getLatestConsoleOutput(baseApiUrl, consoleId, api_token, "Git pull completed");
297+ const pullCheck = yield checkGitPullOutput(pullResponse);
298+ if (!pullCheck.success) {
299+ switch (pullCheck.error) {
300+ case "local_changes":
301+ console.error(`Git pull failed: Local changes detected in ${web_app.source_directory}. \n` +
302+ "Please either: \n1) Commit changes (git add . && git commit -m 'message'), \n" +
303+ "2) Stash them (git stash), or \n" +
304+ "3) Remove them (git reset --hard origin/main)\n");
305+ throw new Error("Git pull failed due to local changes");
306+ case "untracked_files":
307+ console.error(`Git pull failed: Untracked files detected in ${web_app.source_directory}. ` +
308+ "Please either: 1) Add files (git add .) or " +
309+ "2) Remove them (git clean -f)");
310+ throw new Error("Git pull failed due to untracked files");
311+ case "git_error":
312+ default:
313+ console.error("Git pull failed. Please check your repository configuration and try again.");
314+ throw new Error("Git pull failed");
315+ }
316+ }
317+ console.log("Repository updated successfully.");
255318 }
256319 catch (error) {
257320 if (error.message.includes("Console not yet started")) {
258321 const consoleUrl = _console.console_url;
259322 throw new Error(`Activate your terminal: ${host}${consoleUrl}`);
260323 }
261324 else {
262- throw new Error(`Error during pulling repository: ${ error.message}`) ;
325+ throw error;
263326 }
264327 }
265328 if (framework_type == 'django') {
@@ -280,15 +343,30 @@ function run() {
280343 }
281344 else if (framework_type == 'flask') {
282345 try {
283- const alembicIniPath = `${web_app.source_directory}/alembic.ini`;
284- yield postConsoleInput(consoleRequestUrl, api_token, `find ${web_app.source_directory} -type f -name "alembic.ini" -print\n`, "Alembic configuration check completed.");
285- const alembicResponse = yield getLatestConsoleOutput(baseApiUrl, consoleId, api_token, "Alembic.ini Checking.");
286- const isAlembicUsing = yield parseAndCheckAlembic(alembicResponse, web_app.source_directory);
287346 yield postConsoleInput(consoleRequestUrl, api_token, `source ${web_app.virtualenv_path}/bin/activate\n`, "Virtual Environment Activated.");
288347 yield postConsoleInput(consoleRequestUrl, api_token, `pip install -r ${web_app.source_directory}/requirements.txt\n`, "Requirements Installed.");
289- if (isAlembicUsing) {
290- console.log("Alembic migration starting...");
291- yield postConsoleInput(consoleRequestUrl, api_token, `alembic upgrade head\n`, "Alembic migrations applied.");
348+ yield postConsoleInput(consoleRequestUrl, api_token, `find ${web_app.source_directory} -type f -name "alembic.ini" -print\n`, "Checking for alembic.ini");
349+ const alembicResponse = yield getLatestConsoleOutput(baseApiUrl, consoleId, api_token, "Alembic check completed");
350+ const alembicCheck = yield parseAndCheckAlembic(alembicResponse, web_app.source_directory);
351+ if (alembicCheck.exists && alembicCheck.path) {
352+ try {
353+ console.log("Alembic configuration found, running migrations...");
354+ yield postConsoleInput(consoleRequestUrl, api_token, `cd $(dirname $(find ${web_app.source_directory} -type f -name "alembic.ini" -print -quit)) && alembic upgrade head\n`, "Checking alembic status");
355+ const alembicUpgradeResponse = yield getLatestConsoleOutput(baseApiUrl, consoleId, api_token, "");
356+ if (alembicUpgradeResponse.output && alembicUpgradeResponse.output.includes("FAILED")) {
357+ console.error("Alembic migration failed. Please check your alembic configuration.");
358+ console.error(alembicUpgradeResponse.output);
359+ }
360+ else {
361+ console.log("Alembic migrations completed successfully");
362+ }
363+ }
364+ catch (error) {
365+ console.error(`Error during alembic migration: ${error.message}`);
366+ }
367+ }
368+ else {
369+ console.log("No Alembic configuration found, skipping migrations");
292370 }
293371 }
294372 catch (error) {
0 commit comments