From 720a1791d7b31718d2ab2250f47fc3f7105a1c0d Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Fri, 15 Mar 2024 00:10:19 +0100 Subject: [PATCH 01/27] Added badges to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bae35fb..1c3fc39 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Vigilans Nexum +[![Node CI Build](https://github.com/doncolon/vigilans-nexum/actions/workflows/ci-build.yml/badge.svg)](https://github.com/DonColon/vigilans-nexum/actions/workflows/ci-build.yml) [![codecov](https://codecov.io/gh/DonColon/vigilans-nexum/graph/badge.svg?token=6TBGMM3XH1)](https://codecov.io/gh/DonColon/vigilans-nexum) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=DonColon_vigilans-nexum&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=DonColon_vigilans-nexum) Vigilans Nexum is a tactical, turn- and tile-based RPG with a deep story about trust and the invisible bonds that connects the people on the battlefield. This game is inspired by the by the fire emblem franchise and tries to capture the essence of the fire emblem games with a twist on the gameplay mechanics. ## Project Structure From 0c15d6567d94c96c4398846cc1478fd47b5a424d Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Fri, 15 Mar 2024 00:25:52 +0100 Subject: [PATCH 02/27] made changes --- .github/scripts/download-release-asset.cjs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/scripts/download-release-asset.cjs b/.github/scripts/download-release-asset.cjs index 954351d..1573c33 100644 --- a/.github/scripts/download-release-asset.cjs +++ b/.github/scripts/download-release-asset.cjs @@ -11,6 +11,8 @@ module.exports = async ({ core, context, github }) => { per_page: 1 }); + core.info(JSON.stringify(latestRelease, undefined, "\t")); + if(appVersion !== latestRelease.tag_name) { core.setFailed("Different version number between package.json and release"); } From 4b290f3695e911814cca2313d239e135dfc7e7e3 Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Fri, 15 Mar 2024 01:00:58 +0100 Subject: [PATCH 03/27] Fixed issue with tag name for draft releases --- .github/scripts/download-release-asset.cjs | 2 +- .github/scripts/retrieve-latest-release.js | 6 ++---- .github/scripts/upload-release-asset.js | 4 ++-- .github/scripts/utils.js | 7 ------- 4 files changed, 5 insertions(+), 14 deletions(-) delete mode 100644 .github/scripts/utils.js diff --git a/.github/scripts/download-release-asset.cjs b/.github/scripts/download-release-asset.cjs index 1573c33..4f1b3b1 100644 --- a/.github/scripts/download-release-asset.cjs +++ b/.github/scripts/download-release-asset.cjs @@ -13,7 +13,7 @@ module.exports = async ({ core, context, github }) => { core.info(JSON.stringify(latestRelease, undefined, "\t")); - if(appVersion !== latestRelease.tag_name) { + if(appVersion !== latestRelease.name) { core.setFailed("Different version number between package.json and release"); } diff --git a/.github/scripts/retrieve-latest-release.js b/.github/scripts/retrieve-latest-release.js index 3f7b242..59e71b3 100644 --- a/.github/scripts/retrieve-latest-release.js +++ b/.github/scripts/retrieve-latest-release.js @@ -1,4 +1,3 @@ -import { formatRepositoryTitle } from "./utils.js"; import pkg from "../../package.json" assert { type: "json" }; export default async ({ core, context, github }) => { @@ -15,7 +14,7 @@ export default async ({ core, context, github }) => { let isFirstRelease = false; if(latestRelease) { - latestVersion = latestRelease.tag_name; + latestVersion = latestRelease.name; core.info(`Latest release version ${latestVersion}`); } else { isFirstRelease = true; @@ -23,12 +22,11 @@ export default async ({ core, context, github }) => { } if(isFirstRelease || appVersion > latestVersion) { - const releaseName = `${formatRepositoryTitle(repo)} ${appVersion}`; const { data: newRelease } = await github.rest.repos.createRelease({ owner, repo, tag_name: appVersion, - name: releaseName, + name: appVersion, target_commitish: process.env.GITHUB_SHA, draft: true }); diff --git a/.github/scripts/upload-release-asset.js b/.github/scripts/upload-release-asset.js index 3cd10e0..353dd43 100644 --- a/.github/scripts/upload-release-asset.js +++ b/.github/scripts/upload-release-asset.js @@ -3,7 +3,7 @@ import { formatRepositoryTitle } from "./utils.js"; export default async ({ core, context, github, release }) => { const { owner, repo } = context.repo; - const artifactName = `${repo}-build-${release.tag_name}`; + const artifactName = `${repo}-build-${release.name}`; core.info(`Download build artifact ${artifactName}`); const { data: { artifacts: [artifactMetadata] } } = await github.rest.actions.listArtifactsForRepo({ @@ -21,7 +21,7 @@ export default async ({ core, context, github, release }) => { }); core.info(`Upload build artifact ${artifactName}`); - const assetLabel = `${formatRepositoryTitle(repo)} Build ${release.tag_name}`; + const assetLabel = `${formatRepositoryTitle(repo)} Build ${release.name}`; const assetName = `${artifactName}.zip`; await github.request({ diff --git a/.github/scripts/utils.js b/.github/scripts/utils.js deleted file mode 100644 index 925d232..0000000 --- a/.github/scripts/utils.js +++ /dev/null @@ -1,7 +0,0 @@ -export function formatRepositoryTitle(repo) { - return repo.split("-").map(value => capitalize(value)).join(" "); -} - -export function capitalize(value) { - return value.charAt(0).toUpperCase() + value.slice(1); -} From fc5654c1beb78a5256477ae0921e4c0e635c08e5 Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Fri, 15 Mar 2024 01:07:38 +0100 Subject: [PATCH 04/27] Added utils --- .github/scripts/utils.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .github/scripts/utils.js diff --git a/.github/scripts/utils.js b/.github/scripts/utils.js new file mode 100644 index 0000000..925d232 --- /dev/null +++ b/.github/scripts/utils.js @@ -0,0 +1,7 @@ +export function formatRepositoryTitle(repo) { + return repo.split("-").map(value => capitalize(value)).join(" "); +} + +export function capitalize(value) { + return value.charAt(0).toUpperCase() + value.slice(1); +} From 62c933e7db028824b9e42ff5066abc42f64e4384 Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Fri, 15 Mar 2024 01:51:45 +0100 Subject: [PATCH 05/27] Added token to request --- .github/scripts/download-release-asset.cjs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/scripts/download-release-asset.cjs b/.github/scripts/download-release-asset.cjs index 4f1b3b1..493f555 100644 --- a/.github/scripts/download-release-asset.cjs +++ b/.github/scripts/download-release-asset.cjs @@ -22,7 +22,10 @@ module.exports = async ({ core, context, github }) => { const { data: asset } = await github.request({ method: "GET", - url: assetMetadata.browser_download_url + url: assetMetadata.browser_download_url, + headers: { + authorization: `Bearer ${process.env.GITHUB_TOKEN}` + } }); const files = await decompress(Buffer.from(asset), "dist") From d65972aad5bd261ee3b0de2f904e77775bf442cc Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Fri, 15 Mar 2024 02:01:43 +0100 Subject: [PATCH 06/27] Test --- .github/scripts/download-release-asset.cjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/download-release-asset.cjs b/.github/scripts/download-release-asset.cjs index 493f555..4e1b9eb 100644 --- a/.github/scripts/download-release-asset.cjs +++ b/.github/scripts/download-release-asset.cjs @@ -20,7 +20,7 @@ module.exports = async ({ core, context, github }) => { const assetName = `${repo}-build-${appVersion}.zip`; const assetMetadata = latestRelease.assets.find((asset) => asset.name === assetName); - const { data: asset } = await github.request({ + const { data: asset } = await github.request.fetch({ method: "GET", url: assetMetadata.browser_download_url, headers: { From 115d5c87f30c8ff081667149111a8fd6752e605e Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Fri, 15 Mar 2024 02:06:47 +0100 Subject: [PATCH 07/27] test --- .github/scripts/download-release-asset.cjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/download-release-asset.cjs b/.github/scripts/download-release-asset.cjs index 4e1b9eb..68c9529 100644 --- a/.github/scripts/download-release-asset.cjs +++ b/.github/scripts/download-release-asset.cjs @@ -20,7 +20,7 @@ module.exports = async ({ core, context, github }) => { const assetName = `${repo}-build-${appVersion}.zip`; const assetMetadata = latestRelease.assets.find((asset) => asset.name === assetName); - const { data: asset } = await github.request.fetch({ + const { data: asset } = await fetch({ method: "GET", url: assetMetadata.browser_download_url, headers: { From ab019f58007d591a6df2f5a11b6c50feb313b52a Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Fri, 15 Mar 2024 02:11:55 +0100 Subject: [PATCH 08/27] test --- .github/scripts/download-release-asset.cjs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/scripts/download-release-asset.cjs b/.github/scripts/download-release-asset.cjs index 68c9529..df153f0 100644 --- a/.github/scripts/download-release-asset.cjs +++ b/.github/scripts/download-release-asset.cjs @@ -20,6 +20,8 @@ module.exports = async ({ core, context, github }) => { const assetName = `${repo}-build-${appVersion}.zip`; const assetMetadata = latestRelease.assets.find((asset) => asset.name === assetName); + console.log(assetMetadata.browser_download_url) + const { data: asset } = await fetch({ method: "GET", url: assetMetadata.browser_download_url, From 0dc536cb271708e1bd1891117b016a7e7c7f5e9d Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Fri, 15 Mar 2024 02:19:31 +0100 Subject: [PATCH 09/27] test --- .github/scripts/download-release-asset.cjs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/scripts/download-release-asset.cjs b/.github/scripts/download-release-asset.cjs index df153f0..4b4a064 100644 --- a/.github/scripts/download-release-asset.cjs +++ b/.github/scripts/download-release-asset.cjs @@ -22,9 +22,7 @@ module.exports = async ({ core, context, github }) => { console.log(assetMetadata.browser_download_url) - const { data: asset } = await fetch({ - method: "GET", - url: assetMetadata.browser_download_url, + const { data: asset } = await fetch(assetMetadata.browser_download_url, { headers: { authorization: `Bearer ${process.env.GITHUB_TOKEN}` } From bdc2e71902edf8d1bc26a866f6adb54035c17dcb Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Fri, 15 Mar 2024 19:18:52 +0100 Subject: [PATCH 10/27] test --- .github/scripts/download-release-asset.cjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/download-release-asset.cjs b/.github/scripts/download-release-asset.cjs index 4b4a064..7503ba6 100644 --- a/.github/scripts/download-release-asset.cjs +++ b/.github/scripts/download-release-asset.cjs @@ -24,7 +24,7 @@ module.exports = async ({ core, context, github }) => { const { data: asset } = await fetch(assetMetadata.browser_download_url, { headers: { - authorization: `Bearer ${process.env.GITHUB_TOKEN}` + Authorization: `Bearer ${process.env.GITHUB_TOKEN}` } }); From beced05db846773c42f0d304856a6c61ae5d788e Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Fri, 15 Mar 2024 19:24:16 +0100 Subject: [PATCH 11/27] test --- .github/scripts/download-release-asset.cjs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/scripts/download-release-asset.cjs b/.github/scripts/download-release-asset.cjs index 7503ba6..0afc2c7 100644 --- a/.github/scripts/download-release-asset.cjs +++ b/.github/scripts/download-release-asset.cjs @@ -28,6 +28,8 @@ module.exports = async ({ core, context, github }) => { } }); + console.log(asset); + const files = await decompress(Buffer.from(asset), "dist") const filePaths = files.map((file) => file.path); core.info(`Unzipped files: \n${filePaths.join("\n")}`); From 60838c5cb291835b8562a086524323bbc47ee8cb Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Fri, 15 Mar 2024 19:27:27 +0100 Subject: [PATCH 12/27] test --- .github/scripts/download-release-asset.cjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/download-release-asset.cjs b/.github/scripts/download-release-asset.cjs index 0afc2c7..f1aff16 100644 --- a/.github/scripts/download-release-asset.cjs +++ b/.github/scripts/download-release-asset.cjs @@ -22,13 +22,13 @@ module.exports = async ({ core, context, github }) => { console.log(assetMetadata.browser_download_url) - const { data: asset } = await fetch(assetMetadata.browser_download_url, { + const test = await fetch(assetMetadata.browser_download_url, { headers: { Authorization: `Bearer ${process.env.GITHUB_TOKEN}` } }); - console.log(asset); + console.log(test); const files = await decompress(Buffer.from(asset), "dist") const filePaths = files.map((file) => file.path); From 78cf5dbcc6857c49d1ab0bfbab980bcf437f4bb9 Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Fri, 15 Mar 2024 19:32:12 +0100 Subject: [PATCH 13/27] test --- .github/scripts/download-release-asset.cjs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/scripts/download-release-asset.cjs b/.github/scripts/download-release-asset.cjs index f1aff16..a16d328 100644 --- a/.github/scripts/download-release-asset.cjs +++ b/.github/scripts/download-release-asset.cjs @@ -22,15 +22,13 @@ module.exports = async ({ core, context, github }) => { console.log(assetMetadata.browser_download_url) - const test = await fetch(assetMetadata.browser_download_url, { + const asset = await fetch(assetMetadata.browser_download_url, { headers: { Authorization: `Bearer ${process.env.GITHUB_TOKEN}` } }); - console.log(test); - - const files = await decompress(Buffer.from(asset), "dist") + const files = await decompress(Buffer.from(asset.arrayBuffer()), "dist") const filePaths = files.map((file) => file.path); core.info(`Unzipped files: \n${filePaths.join("\n")}`); }; From daa2f8621d6c907a0666e4fe171fdd43a7c8ed7c Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Fri, 15 Mar 2024 19:35:46 +0100 Subject: [PATCH 14/27] Added await --- .github/scripts/download-release-asset.cjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/scripts/download-release-asset.cjs b/.github/scripts/download-release-asset.cjs index a16d328..486c1cd 100644 --- a/.github/scripts/download-release-asset.cjs +++ b/.github/scripts/download-release-asset.cjs @@ -28,7 +28,9 @@ module.exports = async ({ core, context, github }) => { } }); - const files = await decompress(Buffer.from(asset.arrayBuffer()), "dist") + const data = await asset.arrayBuffer(); + const files = await decompress(Buffer.from(data), "dist") + const filePaths = files.map((file) => file.path); core.info(`Unzipped files: \n${filePaths.join("\n")}`); }; From a82c1e64957fef2d0ed4c406dcac56c7f75a1e71 Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Sat, 16 Mar 2024 00:27:51 +0100 Subject: [PATCH 15/27] test --- .github/scripts/download-release-asset.cjs | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/scripts/download-release-asset.cjs b/.github/scripts/download-release-asset.cjs index 486c1cd..51e1767 100644 --- a/.github/scripts/download-release-asset.cjs +++ b/.github/scripts/download-release-asset.cjs @@ -29,6 +29,7 @@ module.exports = async ({ core, context, github }) => { }); const data = await asset.arrayBuffer(); + console.log(data); const files = await decompress(Buffer.from(data), "dist") const filePaths = files.map((file) => file.path); From e9bcc07e40294a8a889dae3b69d9a42106f17cf4 Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Sat, 16 Mar 2024 02:12:35 +0100 Subject: [PATCH 16/27] test --- .github/scripts/publish-latest-release.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/scripts/publish-latest-release.js b/.github/scripts/publish-latest-release.js index fbcef7c..a2e4f4e 100644 --- a/.github/scripts/publish-latest-release.js +++ b/.github/scripts/publish-latest-release.js @@ -5,8 +5,10 @@ export default async ({ core, context, github, release }) => { owner, repo, release_id: release.id, - draft: process.env.GITHUB_REF_NAME.includes("feature"), - prerelease: process.env.GITHUB_REF_NAME === "dev" + // draft: process.env.GITHUB_REF_NAME.includes("feature"), + // prerelease: process.env.GITHUB_REF_NAME === "dev" + draft: false, + prerelease: true }); core.info(`Published release ${release.name}`); From d501ab1bfb49ea3e733957d09724ec036078520d Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Sat, 16 Mar 2024 17:09:25 +0100 Subject: [PATCH 17/27] test --- .github/scripts/publish-latest-release.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/publish-latest-release.js b/.github/scripts/publish-latest-release.js index a2e4f4e..ba6bdb0 100644 --- a/.github/scripts/publish-latest-release.js +++ b/.github/scripts/publish-latest-release.js @@ -7,7 +7,7 @@ export default async ({ core, context, github, release }) => { release_id: release.id, // draft: process.env.GITHUB_REF_NAME.includes("feature"), // prerelease: process.env.GITHUB_REF_NAME === "dev" - draft: false, + draft: true, prerelease: true }); From 91ea019e7a49848afe0bb2f0a9da3332784a3c1c Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Sat, 16 Mar 2024 19:07:13 +0100 Subject: [PATCH 18/27] test --- .github/scripts/retrieve-latest-release.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/scripts/retrieve-latest-release.js b/.github/scripts/retrieve-latest-release.js index 59e71b3..f16eda8 100644 --- a/.github/scripts/retrieve-latest-release.js +++ b/.github/scripts/retrieve-latest-release.js @@ -39,7 +39,11 @@ export default async ({ core, context, github }) => { else if(isDraftRelease(latestRelease) && appVersion === latestVersion) { core.info(`Update draft release ${appVersion}`); core.info(JSON.stringify(latestRelease, undefined, "\t")); - + core.setOutput("release", latestRelease); + } + else if(isPreRelease(latestRelease) && appVersion === latestVersion) { + core.info(`Update pre release ${appVersion}`); + core.info(JSON.stringify(latestRelease, undefined, "\t")); core.setOutput("release", latestRelease); } else if(isFullRelease(latestRelease) && appVersion === latestVersion) { @@ -51,6 +55,10 @@ const isFullRelease = (release) => { return !release.draft && !release.prerelease; }; +const isPreRelease = (release) => { + return !release.draft && release.prerelease; +}; + const isDraftRelease = (release) => { - return release.draft || release.prerelease; + return release.draft && !release.prerelease; }; From cdf9b5793402b9ee5b561a2ff6123e8f7c663542 Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Sat, 16 Mar 2024 19:19:07 +0100 Subject: [PATCH 19/27] test asset upload --- .github/scripts/upload-release-asset.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/scripts/upload-release-asset.js b/.github/scripts/upload-release-asset.js index 353dd43..3d95875 100644 --- a/.github/scripts/upload-release-asset.js +++ b/.github/scripts/upload-release-asset.js @@ -24,6 +24,18 @@ export default async ({ core, context, github, release }) => { const assetLabel = `${formatRepositoryTitle(repo)} Build ${release.name}`; const assetName = `${artifactName}.zip`; + if(release.assets.length !== 0) { + const assetMetadata = release.assets.find((asset) => asset.name === assetName); + + if(assetMetadata) { + await github.rest.repos.deleteReleaseAsset({ + owner, + repo, + asset_id: artifactMetadata.id + }); + } + } + await github.request({ method: "POST", url: release.upload_url, From 9681698382780ab9ee622fd110f8f2317c334b4f Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Sat, 16 Mar 2024 19:31:24 +0100 Subject: [PATCH 20/27] test --- .github/scripts/upload-release-asset.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/scripts/upload-release-asset.js b/.github/scripts/upload-release-asset.js index 3d95875..bfa27cb 100644 --- a/.github/scripts/upload-release-asset.js +++ b/.github/scripts/upload-release-asset.js @@ -24,17 +24,17 @@ export default async ({ core, context, github, release }) => { const assetLabel = `${formatRepositoryTitle(repo)} Build ${release.name}`; const assetName = `${artifactName}.zip`; - if(release.assets.length !== 0) { - const assetMetadata = release.assets.find((asset) => asset.name === assetName); - - if(assetMetadata) { - await github.rest.repos.deleteReleaseAsset({ - owner, - repo, - asset_id: artifactMetadata.id - }); - } - } + // if(release.assets.length !== 0) { + // const assetMetadata = release.assets.find((asset) => asset.name === assetName); + + // if(assetMetadata) { + // await github.rest.repos.deleteReleaseAsset({ + // owner, + // repo, + // asset_id: artifactMetadata.id + // }); + // } + // } await github.request({ method: "POST", From 3b84c758adf0c7839f1e64d9bfe7125bcfb4be93 Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Sat, 16 Mar 2024 19:58:09 +0100 Subject: [PATCH 21/27] test --- .github/scripts/retrieve-latest-release.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/retrieve-latest-release.js b/.github/scripts/retrieve-latest-release.js index f16eda8..2206840 100644 --- a/.github/scripts/retrieve-latest-release.js +++ b/.github/scripts/retrieve-latest-release.js @@ -56,9 +56,9 @@ const isFullRelease = (release) => { }; const isPreRelease = (release) => { - return !release.draft && release.prerelease; + return release.prerelease; }; const isDraftRelease = (release) => { - return release.draft && !release.prerelease; + return release.draft; }; From ee1f538a6750159cf8574f82a949899646f33d76 Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Sat, 16 Mar 2024 20:04:23 +0100 Subject: [PATCH 22/27] test --- .github/scripts/retrieve-latest-release.js | 4 ++-- .github/scripts/upload-release-asset.js | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/scripts/retrieve-latest-release.js b/.github/scripts/retrieve-latest-release.js index 2206840..f0fa106 100644 --- a/.github/scripts/retrieve-latest-release.js +++ b/.github/scripts/retrieve-latest-release.js @@ -56,9 +56,9 @@ const isFullRelease = (release) => { }; const isPreRelease = (release) => { - return release.prerelease; + return release.prerelease && !release.draft; }; const isDraftRelease = (release) => { - return release.draft; + return release.draft && !release.prerelease; }; diff --git a/.github/scripts/upload-release-asset.js b/.github/scripts/upload-release-asset.js index bfa27cb..3d95875 100644 --- a/.github/scripts/upload-release-asset.js +++ b/.github/scripts/upload-release-asset.js @@ -24,17 +24,17 @@ export default async ({ core, context, github, release }) => { const assetLabel = `${formatRepositoryTitle(repo)} Build ${release.name}`; const assetName = `${artifactName}.zip`; - // if(release.assets.length !== 0) { - // const assetMetadata = release.assets.find((asset) => asset.name === assetName); - - // if(assetMetadata) { - // await github.rest.repos.deleteReleaseAsset({ - // owner, - // repo, - // asset_id: artifactMetadata.id - // }); - // } - // } + if(release.assets.length !== 0) { + const assetMetadata = release.assets.find((asset) => asset.name === assetName); + + if(assetMetadata) { + await github.rest.repos.deleteReleaseAsset({ + owner, + repo, + asset_id: artifactMetadata.id + }); + } + } await github.request({ method: "POST", From 19834e86703469069f11705d84d3b7f417ea97f9 Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Sat, 16 Mar 2024 20:07:41 +0100 Subject: [PATCH 23/27] test --- .github/scripts/retrieve-latest-release.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/retrieve-latest-release.js b/.github/scripts/retrieve-latest-release.js index f0fa106..2206840 100644 --- a/.github/scripts/retrieve-latest-release.js +++ b/.github/scripts/retrieve-latest-release.js @@ -56,9 +56,9 @@ const isFullRelease = (release) => { }; const isPreRelease = (release) => { - return release.prerelease && !release.draft; + return release.prerelease; }; const isDraftRelease = (release) => { - return release.draft && !release.prerelease; + return release.draft; }; From db8724bd66a72d59177df304d599d89236499279 Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Sat, 16 Mar 2024 20:12:17 +0100 Subject: [PATCH 24/27] test --- .github/scripts/upload-release-asset.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/upload-release-asset.js b/.github/scripts/upload-release-asset.js index 3d95875..b4d4bfb 100644 --- a/.github/scripts/upload-release-asset.js +++ b/.github/scripts/upload-release-asset.js @@ -31,7 +31,7 @@ export default async ({ core, context, github, release }) => { await github.rest.repos.deleteReleaseAsset({ owner, repo, - asset_id: artifactMetadata.id + asset_id: assetMetadata.id }); } } From cb720fe97c8a37659b6028e0d8f39e321569fb13 Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Sat, 16 Mar 2024 20:33:55 +0100 Subject: [PATCH 25/27] Only deploy if dev or main branch --- .github/scripts/download-release-asset.cjs | 14 ++++---------- .github/scripts/publish-latest-release.js | 6 ++---- .github/workflows/ci-build.yml | 2 ++ 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.github/scripts/download-release-asset.cjs b/.github/scripts/download-release-asset.cjs index 51e1767..4f1b3b1 100644 --- a/.github/scripts/download-release-asset.cjs +++ b/.github/scripts/download-release-asset.cjs @@ -20,18 +20,12 @@ module.exports = async ({ core, context, github }) => { const assetName = `${repo}-build-${appVersion}.zip`; const assetMetadata = latestRelease.assets.find((asset) => asset.name === assetName); - console.log(assetMetadata.browser_download_url) - - const asset = await fetch(assetMetadata.browser_download_url, { - headers: { - Authorization: `Bearer ${process.env.GITHUB_TOKEN}` - } + const { data: asset } = await github.request({ + method: "GET", + url: assetMetadata.browser_download_url }); - const data = await asset.arrayBuffer(); - console.log(data); - const files = await decompress(Buffer.from(data), "dist") - + const files = await decompress(Buffer.from(asset), "dist") const filePaths = files.map((file) => file.path); core.info(`Unzipped files: \n${filePaths.join("\n")}`); }; diff --git a/.github/scripts/publish-latest-release.js b/.github/scripts/publish-latest-release.js index ba6bdb0..fbcef7c 100644 --- a/.github/scripts/publish-latest-release.js +++ b/.github/scripts/publish-latest-release.js @@ -5,10 +5,8 @@ export default async ({ core, context, github, release }) => { owner, repo, release_id: release.id, - // draft: process.env.GITHUB_REF_NAME.includes("feature"), - // prerelease: process.env.GITHUB_REF_NAME === "dev" - draft: true, - prerelease: true + draft: process.env.GITHUB_REF_NAME.includes("feature"), + prerelease: process.env.GITHUB_REF_NAME === "dev" }); core.info(`Published release ${release.name}`); diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index f196adc..7b97b4e 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -163,6 +163,8 @@ jobs: timeout-minutes: 30 needs: [release] + + if: ${{ !contains('feature', github.ref_name) }} env: node_version: 20.x From 80fa50d0ecf1eb1cde0454e3fe6f12e53daed2ce Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Sat, 16 Mar 2024 20:52:29 +0100 Subject: [PATCH 26/27] Added cleanup workflow --- .github/scripts/cleanup-workflow-runs.js | 16 ++++++++++++++++ .github/workflows/ci-cleanup.yml | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 .github/scripts/cleanup-workflow-runs.js create mode 100644 .github/workflows/ci-cleanup.yml diff --git a/.github/scripts/cleanup-workflow-runs.js b/.github/scripts/cleanup-workflow-runs.js new file mode 100644 index 0000000..e597363 --- /dev/null +++ b/.github/scripts/cleanup-workflow-runs.js @@ -0,0 +1,16 @@ +export default async ({ core, context, github }) => { + const { owner, repo } = context.repo; + + const { data: workflowRuns } = await github.rest.actions.listWorkflowRunsForRepo({ + owner, + repo + }); + + for(const workflowRun of workflowRuns) { + await github.rest.actions.deleteWorkflowRun({ + owner, + repo, + run_id: workflowRun.id, + }); + } +}; diff --git a/.github/workflows/ci-cleanup.yml b/.github/workflows/ci-cleanup.yml new file mode 100644 index 0000000..ed9e230 --- /dev/null +++ b/.github/workflows/ci-cleanup.yml @@ -0,0 +1,22 @@ +name: Github CI Cleanup + +on: workflow_dispatch + +jobs: + cleanup: + name: Cleanup Workflow Runs + runs-on: ubuntu-latest + timeout-minutes: 30 + + steps: + - name: Checkout Repository ${{ github.event.repository.name }} + uses: actions/checkout@v4 + + - name: Retrieve Latest Release + uses: actions/github-script@v7 + id: cleanup_workflow_runs + with: + script: | + const scriptPath = '${{ github.workspace }}/.github/scripts/cleanup-workflow-runs.js'; + const { default: cleanupWorkflowRuns } = await import(scriptPath); + await cleanupWorkflowRuns({ core, context, github }); \ No newline at end of file From 5c8e9d76297e5445065cd1a2fdcec993cb4b4e4c Mon Sep 17 00:00:00 2001 From: Dardan Rrafshi Date: Sat, 16 Mar 2024 20:57:25 +0100 Subject: [PATCH 27/27] Fixed if condition --- .github/workflows/ci-build.yml | 2 +- .github/workflows/ci-cleanup.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 7b97b4e..4808c5e 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -164,7 +164,7 @@ jobs: needs: [release] - if: ${{ !contains('feature', github.ref_name) }} + if: github.ref_name == 'main' || github.ref_name == 'dev' env: node_version: 20.x diff --git a/.github/workflows/ci-cleanup.yml b/.github/workflows/ci-cleanup.yml index ed9e230..719cc26 100644 --- a/.github/workflows/ci-cleanup.yml +++ b/.github/workflows/ci-cleanup.yml @@ -4,7 +4,7 @@ on: workflow_dispatch jobs: cleanup: - name: Cleanup Workflow Runs + name: Cleanup Repository ${{ github.event.repository.name }} runs-on: ubuntu-latest timeout-minutes: 30 @@ -12,7 +12,7 @@ jobs: - name: Checkout Repository ${{ github.event.repository.name }} uses: actions/checkout@v4 - - name: Retrieve Latest Release + - name: Cleanup Workflow Runs uses: actions/github-script@v7 id: cleanup_workflow_runs with: