Skip to content

Commit

Permalink
fix: docs cli download link (#859)
Browse files Browse the repository at this point in the history
## What
Right now in the docs, the list of CLI versions relies on specific
release order and sensitive to the changes in the structure of CLI
github release. After this change, it still depends on it (by name) but
the order no longer matters.

Incorrect link in the docs:
```html
<a href="https://github.com/codefresh-io/cli/releases/download/v0.87.3/codefresh-v0.87.3-macos-x64.tar.gz" target="_blank">Windows-x64</a>
```

---------

Co-authored-by: Vadim Kharin <[email protected]>
  • Loading branch information
denis-codefresh and vadim-kharin-codefresh authored Jul 18, 2024
1 parent 9e55ce6 commit b2917bc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
44 changes: 33 additions & 11 deletions docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ const createAutomatedDocs = async () => {
};

const createDownloadPage = async () => {
let links = [];
const RequestOptions = {
url: 'https://api.github.com/repos/codefresh-io/cli/releases/latest',
headers: {
Expand All @@ -351,10 +350,37 @@ const createDownloadPage = async () => {
json: true,
};
try {
const res = await rp(RequestOptions);
_.forEach(res.assets, ((asset) => {
links.push(asset.browser_download_url);
}));
// response example https://docs.github.com/en/rest/releases/releases#get-the-latest-release
const { assets = [] } = await rp(RequestOptions);

const getDownloadUrlFromAssets = (nameRegex) => assets.find((a) => a.name.match(nameRegex))?.browser_download_url;
const downloadLinks = [
{
label: 'Alpine-x64',
downloadUrl: getDownloadUrlFromAssets(/alpine-x64/),
},
{
label: 'Linux-x64',
downloadUrl: getDownloadUrlFromAssets(/linux-x64/),
},
{
label: 'Macos-x64',
downloadUrl: getDownloadUrlFromAssets(/macos-x64/),
},
{
label: 'Windows-x64',
downloadUrl: getDownloadUrlFromAssets(/win-x64/),
},
{
label: 'Alpine-arm64',
downloadUrl: getDownloadUrlFromAssets(/alpine-arm64/),
},
{
label: 'Linux-arm64',
downloadUrl: getDownloadUrlFromAssets(/linux-arm64/),
},
];

const commandFilePath = path.resolve(baseDir, './installation/download.md');
const finalContent =
'+++\n' +
Expand All @@ -368,12 +394,8 @@ const createDownloadPage = async () => {
'and download the binary that matches your operating system.<br>\n' +
'We currently support the following OS: <br>\n' +
'<ul>\n' +
' <li><a href=' + links[0] + ' target="_blank">Alpine-arm64</a></li>\n' +
' <li><a href=' + links[1] + ' target="_blank">Alpine-x64</a></li>\n' +
' <li><a href=' + links[2] + ' target="_blank">Linux-arm64</a></li>\n' +
' <li><a href=' + links[3] + ' target="_blank">Linux-x64</a></li>\n' +
' <li><a href=' + links[4] + ' target="_blank">Macos-x64</a></li>\n' +
' <li><a href=' + links[5] + ' target="_blank">Windows-x64</a></li>\n' +
downloadLinks.map(({ label, downloadUrl = 'https://github.com/codefresh-io/cli/releases' }) =>
` <li><a href='${downloadUrl}' target="_blank">${label}</a></li>`).join('\n') +
'</ul> \n' +
'\n' +
'After downloading the binary, untar or unzip it and your are good to go.<br>\n' +
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": "codefresh",
"version": "0.87.4",
"version": "0.87.5",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down

0 comments on commit b2917bc

Please sign in to comment.