Skip to content

Commit

Permalink
Merge pull request #67 from aziontech/stage
Browse files Browse the repository at this point in the history
Release 1.11.0
  • Loading branch information
jotanarciso authored Nov 7, 2024
2 parents 0b3fc3f + 43ead21 commit 2ec2543
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 10 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## [1.11.0-stage.1](https://github.com/aziontech/lib/compare/v1.10.0...v1.11.0-stage.1) (2024-11-07)


### Features

* add automatic cli latest version detection ([5442afc](https://github.com/aziontech/lib/commit/5442afc2cd84796a53049ca61e675b3d0943de3c))
* update cli version ([d1f7832](https://github.com/aziontech/lib/commit/d1f78326ae2b92d0f86a7811db276e5f965383be))


### Bug Fixes

* typo ([41bbca1](https://github.com/aziontech/lib/commit/41bbca1e0cfa393951c272604210accb0b37db1d))

## [1.10.0](https://github.com/aziontech/lib/compare/v1.9.0...v1.10.0) (2024-11-06)


Expand Down
75 changes: 67 additions & 8 deletions cli/scripts/download-cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import os from 'os';
import path from 'path';
import { fileURLToPath } from 'url';

const defaultVersion = '1.39.0';
const defaultVersion = '2.2.0';
const version = process.env.AZION_CLI_VERSION || defaultVersion;

const baseUrl = `https://github.com/aziontech/azion/releases/download/${version}`;
Expand Down Expand Up @@ -171,19 +171,78 @@ function checkExistingCliVersion() {
}
}

async function getLatestVersion() {
return new Promise((resolve, reject) => {
log.info('Fetching latest version from GitHub API...');

const options = {
hostname: 'api.github.com',
path: '/repos/aziontech/azion/releases/latest',
headers: {
'User-Agent': 'Azion-CLI-Installer',
},
};

https
.get(options, (response) => {
let data = '';
response.on('data', (chunk) => (data += chunk));
response.on('end', () => {
try {
const release = JSON.parse(data);
const version = release.tag_name.replace(/^v/, '');

if (/^\d+\.\d+\.\d+$/.test(version)) {
log.success(`Latest version found from API: ${version}`);
resolve(version);
} else {
log.warning(`Invalid version format from API: ${version}`);
log.info(`Using default version: ${defaultVersion}`);
resolve(defaultVersion);
}
} catch (err) {
log.warning(`Error processing API response: ${err.message}`);
log.info(`Using default version: ${defaultVersion}`);
resolve(defaultVersion);
}
});
})
.on('error', (err) => {
log.warning(`Could not fetch latest version: ${err.message}`);
log.info(`Using default version: ${defaultVersion}`);
resolve(defaultVersion);
});
});
}

async function main() {
try {
log.highlight(`Checking Azion CLI v${version}`);
let selectedVersion;

if (process.env.AZION_CLI_VERSION) {
selectedVersion = process.env.AZION_CLI_VERSION;
log.info(`Using version from environment variable: ${selectedVersion}`);
} else {
selectedVersion = await getLatestVersion();
log.info(`Using latest version: ${selectedVersion}`);
}

// Manter a URL base original
const baseUrl = `https://github.com/aziontech/azion/releases/download/v${selectedVersion}`;

log.highlight(`Checking Azion CLI v${selectedVersion}`);
console.log();

const existingVersion = checkExistingCliVersion();
if (existingVersion) {
log.info(`Azion CLI is already installed (version ${existingVersion})`);
if (existingVersion === version) {
log.success(`Azion CLI v${version} is already installed and up to date.`);
if (existingVersion === selectedVersion) {
log.success(`Azion CLI v${selectedVersion} is already installed and up to date.`);
process.exit(0);
} else {
log.info(`Current version (${existingVersion}) differs from desired (${version}). Proceeding with update...`);
log.info(
`Current version (${existingVersion}) differs from desired (${selectedVersion}). Proceeding with update...`,
);
}
}

Expand All @@ -198,12 +257,12 @@ async function main() {
try {
const currentVersion = execSync(`"${finalPath}" -v`).toString().trim();
const versionMatch = currentVersion.match(/v(\d+\.\d+\.\d+)/);
if (versionMatch && versionMatch[1] === version) {
log.success(`Azion CLI v${version} is already installed and up to date.`);
if (versionMatch && versionMatch[1] === selectedVersion) {
log.success(`Azion CLI v${selectedVersion} is already installed and up to date.`);
process.exit(0);
} else {
log.info(
`Current version (${versionMatch ? versionMatch[1] : 'unknown'}) differs from desired (${version}). Updating...`,
`Current version (${versionMatch ? versionMatch[1] : 'unknown'}) differs from desired (${selectedVersion}). Updating...`,
);
}
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azion",
"version": "1.10.0",
"version": "1.11.0-stage.1",
"description": "Azion Packages for Edge Computing.",
"bin": {
"azion": "./bin/azion",
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export type AzionPurge = {
};

export type AzionBuild = {
/** Bunlder to be used */
/** JavaScript bundler to be used for building the application */
builder?: 'webpack' | 'esbuild';
/** Entry file for the build */
entry?: string;
Expand Down

0 comments on commit 2ec2543

Please sign in to comment.