Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Env dependant tag creation #25

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions src/commands/functions/createTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { selectWorkspaceFolder } from "../../utils/workspace";
import { ProgressMessage } from "../../utils/types";
import { Tag } from "../../appwrite";
import { activateTag } from "./activateTag";
import { execSync } from "child_process";

export async function createTag(item?: TagsTreeItem | Uri): Promise<void> {
if (item instanceof Uri) {
Expand Down Expand Up @@ -39,7 +40,7 @@ export async function createTag(item?: TagsTreeItem | Uri): Promise<void> {
if (pick.detail === undefined) {
return;
}
return await createTagFromUri(pick.detail, command, item, progress);
return await createTagFromUri(pick.detail, command, item.path, progress, "", "");
}
);
if (tag) {
Expand All @@ -64,10 +65,32 @@ export async function createTag(item?: TagsTreeItem | Uri): Promise<void> {
if (command === undefined) {
return;
}

// there is a special way to publishing a tag for .net5.0
const envPick = await window.showQuickPick(
[".net5.0", "other"],
{ placeHolder: "Select runtime" }
);
Comment on lines +69 to +73
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a good way to detect automatically if they are using .NET? If so, we might be able to skip this prompt.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we could. We could chek if there is a *.csproj in the folder. Then the prject is using .NET
Now project can be using Net3.1 or Net5.0, there we would need to read the *.csproj and find out what version it is from there :(


let customTarCreationCommand = "";
let customTarPath = "";
try {
if (envPick === ".net5.0") {
const comm = "dotnet publish --runtime linux-x64 --framework net5.0 --no-self-contained " + folder;
execSync(comm);
if (fs.statSync(folder + "/bin/Debug/net5.0/linux-x64/")) {
customTarPath = folder + "/code.tar.gz";
customTarCreationCommand = "tar -C " + folder + "/bin/Debug/net5.0/linux-x64 -zcvf " + customTarPath + " publish";
}
}
} catch (error) {
window.showErrorMessage("Error publishing .net archive.\n" + error);
}

const tag = await window.withProgress(
{ location: ProgressLocation.Notification, title: "Creating tag..." },
async (progress, _token) => {
return await createTagFromUri(func.$id, command, Uri.parse(folder), progress);
return await createTagFromUri(func.$id, command, folder, progress, customTarCreationCommand, customTarPath);
}
);

Expand Down Expand Up @@ -102,10 +125,11 @@ export async function createTag(item?: TagsTreeItem | Uri): Promise<void> {
if (command === undefined) {
return;
}

const tag = await window.withProgress(
{ location: ProgressLocation.Notification, title: "Creating tag..." },
async (progress, _token) => {
return await createTagFromUri(funcId, command, Uri.parse(folder), progress);
return await createTagFromUri(funcId, command, folder, progress, "", "");
}
);

Expand All @@ -116,7 +140,7 @@ export async function createTag(item?: TagsTreeItem | Uri): Promise<void> {
}
}

async function createTagFromUri(functionId: string, command: string, uri: Uri, progress: ProgressMessage): Promise<Tag | undefined> {
async function createTagFromUri(functionId: string, command: string, folder: string, progress: ProgressMessage, customTarCreationCommand: string, customTarPath: string): Promise<Tag | undefined> {
progress.report({ message: "Creating tarball", increment: 10 });

if (functionsClient === undefined) {
Expand All @@ -125,7 +149,17 @@ async function createTagFromUri(functionId: string, command: string, uri: Uri, p

let tarFilePath;
try {
tarFilePath = await getTarReadStream(uri);
if (customTarCreationCommand !== "") {
execSync(customTarCreationCommand);
if (fs.statSync(customTarPath)) {
tarFilePath = customTarPath;
} else {
window.showErrorMessage("Error creating tar file.\n");
}
}
else {
tarFilePath = await getTarReadStream(Uri.parse(folder));
}
} catch (e) {
window.showErrorMessage("Error creating tar file.\n" + e);
return;
Expand Down