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

Fix #153: Prevent stdout cutoff in Azure CLI versions #154

Merged
merged 4 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Automate your GitHub workflows using Azure CLI scripts.",
"main": "src/main.js",
"scripts": {
"build": "tsc",
"build": "ncc build -C -m src/entrypoint.ts",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
Expand Down
32 changes: 16 additions & 16 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { createScriptFile, TEMP_DIRECTORY, NullOutstreamStringWritable, deleteFi
const START_SCRIPT_EXECUTION_MARKER: string = "Starting script execution via docker image mcr.microsoft.com/azure-cli:";
const AZ_CLI_VERSION_DEFAULT_VALUE = 'agentazcliversion'
const prefix = !!process.env.AZURE_HTTP_USER_AGENT ? `${process.env.AZURE_HTTP_USER_AGENT}` : "";
const AZ_CLI_TAG_lIST_URL = "https://mcr.microsoft.com/v2/azure-cli/tags/list";

export async function main() {
let usrAgentRepo = crypto.createHash('sha256').update(`${process.env.GITHUB_REPOSITORY}`).digest('hex');
Expand Down Expand Up @@ -98,28 +99,27 @@ const checkIfValidCLIVersion = async (azcliversion: string): Promise<boolean> =>
}

const getAllAzCliVersions = async (): Promise<Array<string>> => {
var outStream: string = '';
var execOptions: any = {
outStream: new NullOutstreamStringWritable({ decodeStrings: false }),
listeners: {
stdout: (data: any) => outStream += data.toString() + os.EOL, //outstream contains the list of all the az cli versions
}
};

try {
await exec.exec("curl", ["--location", "-s", "https://mcr.microsoft.com/v2/azure-cli/tags/list"], execOptions)
if (outStream && JSON.parse(outStream).tags) {
return JSON.parse(outStream).tags;
const response = await fetch(AZ_CLI_TAG_lIST_URL);
if (!response.ok) {
const errorText = await response.text();
throw new Error(`HTTP error! status: ${response.status}, errorText: ${errorText}`);
}
} catch (error) {
// if output is 404 page not found, please verify the url
core.warning(`Unable to fetch all az cli versions, please report it as an issue on https://github.com/Azure/CLI/issues. Output: ${outStream}, Error: ${error}`);
const data = await response.json();
if (data && data.tags) {
return data.tags;
}
else {
throw new Error('Response data does not contain tags.');
}
}
catch (error) {
core.warning(`Unable to fetch all az cli versions with Error: ${error}. Skipping the version check.`);
}
return [];
}
};

const executeDockerCommand = async (args: string[], continueOnError: boolean = false): Promise<void> => {

const dockerTool: string = await io.which("docker", true);
var errorStream: string = '';
var shouldOutputErrorStream: boolean = false;
Expand Down
Loading