Skip to content

Commit

Permalink
chore: update release workflow and download links
Browse files Browse the repository at this point in the history
  • Loading branch information
Conventional Changelog Action authored and leoli0605 committed Mar 16, 2024
1 parent 4641366 commit 4abd8a0
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 38 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ jobs:
- run: |
node docs/software_lists.mjs
git add README.md
git diff --cached --quiet || git commit -m "docs: update software lists"
git push origin ${{ github.ref }}
git diff --cached --quiet || (git commit -m "docs: update software lists" && git push origin ${{ github.ref }})
env:
CI: true
Expand Down Expand Up @@ -75,8 +74,7 @@ jobs:
run: |
node docs/download_links.mjs
git add README.md
git diff --cached --quiet || git commit -m "docs: update download links"
git push origin ${{ github.ref }}
git diff --cached --quiet || (git commit -m "docs: update download links" && git push origin ${{ github.ref }})
- name: Merge release branch
if: steps.release.outputs.id != ''
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/versioning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Keep the versions up-to-date

on:
release:
types: [published, edited, released]
types: [published, created, edited, released]

jobs:
actions-tagger:
Expand Down
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# 1.0.0 (2024-03-15)
## [1.0.2](https://github.com/leoli0605/npm-env-setup/compare/v1.0.0...v1.0.2) (2024-03-16)


### Bug Fixes

* update stdin from pipe to inherit to fix [#8](https://github.com/leoli0605/npm-env-setup/issues/8) issue ([4641366](https://github.com/leoli0605/npm-env-setup/commit/464136696b0ea1c894d538ae9cc3ae7014c621af))



# [1.0.0](https://github.com/leoli0605/npm-env-setup/compare/45a0bf78f82824d25f1b0373b21b509d147ffe83...v1.0.0) (2024-03-15)


### Bug Fixes
Expand Down
86 changes: 54 additions & 32 deletions docs/download_links.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ function generateMarkdown({ beforeMarker, afterMarker, content }) {
// 根據資產名稱和下載 URL 生成對應的 shell 命令
function generateShellCommand(asset) {
if (asset.name.includes('win-x64')) {
return `powershell.exe -Command "Invoke-WebRequest -Uri "${asset.browser_download_url}" -OutFile "${asset.name}"; Start-Process "${asset.name}" -Wait; Remove-Item "${asset.name}" -Force"`;
return `powershell.exe -Command "Invoke-WebRequest -Uri ${asset.browser_download_url} -OutFile ${asset.name}; Start-Process ${asset.name} -Wait; Remove-Item ${asset.name} -Force"`;
} else {
return `curl -L "${asset.browser_download_url}" -o ${asset.name} && chmod +x ${asset.name} && ./${asset.name} && rm -f ${asset.name}`;
return `curl -L ${asset.browser_download_url} -o ${asset.name} && chmod +x ${asset.name} && ./${asset.name} && rm -f ${asset.name}`;
}
}

Expand All @@ -32,38 +32,60 @@ function selectMarkers(asset) {
}
}

const url = `https://api.github.com/repos/DinosauriaLab/npm-env-setup/releases/latest`;
const options = {
headers: {
'User-Agent': 'node.js',
},
};
const MAX_RETRIES = 10; // 最大重試次數
const RETRY_DELAY = 5000; // 重試間隔時間,單位毫秒

https
.get(url, options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
const release = JSON.parse(data);
console.log(release);
console.log(`Latest release: ${release.name}`);
release.assets.forEach((asset) => {
console.log(`Download URL: ${asset.browser_download_url}`);
console.log(`Asset name: ${asset.name}`);
const shellCommand = generateShellCommand(asset);
const { beforeMarker, afterMarker } = selectMarkers(asset);
if (beforeMarker && afterMarker) {
generateMarkdown({
beforeMarker,
afterMarker,
content: '```shell\n' + shellCommand + '\n```',
function fetchReleaseData(retryCount = 0) {
const url = `https://api.github.com/repos/DinosauriaLab/npm-env-setup/releases/latest`;
const options = {
headers: {
'User-Agent': 'node.js',
},
};

https
.get(url, options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
try {
const release = JSON.parse(data);
console.log(`Latest release: ${release.name}`);
release.assets.forEach((asset) => {
console.log(`Download URL: ${asset.browser_download_url}`);
console.log(`Asset name: ${asset.name}`);
const shellCommand = generateShellCommand(asset);
const { beforeMarker, afterMarker } = selectMarkers(asset);
if (beforeMarker && afterMarker) {
generateMarkdown({
beforeMarker,
afterMarker,
content: '```shell\n' + shellCommand + '\n```',
});
}
});
} catch (error) {
console.error('Error parsing response: ', error.message);
retryOrFail(retryCount);
}
});
})
.on('error', (err) => {
console.error('HTTPS request failed: ', err.message);
retryOrFail(retryCount);
});
})
.on('error', (err) => {
console.error('Error: ', err.message);
});
}

function retryOrFail(retryCount) {
if (retryCount < MAX_RETRIES) {
console.log(`Retry ${retryCount + 1}/${MAX_RETRIES} after ${RETRY_DELAY}ms...`);
setTimeout(() => fetchReleaseData(retryCount + 1), RETRY_DELAY);
} else {
console.log('Max retries reached. Giving up.');
}
}

// 初始調用
fetchReleaseData();

0 comments on commit 4abd8a0

Please sign in to comment.