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/scripts/download-release-asset.cjs b/.github/scripts/download-release-asset.cjs index 954351d..4f1b3b1 100644 --- a/.github/scripts/download-release-asset.cjs +++ b/.github/scripts/download-release-asset.cjs @@ -11,7 +11,9 @@ module.exports = async ({ core, context, github }) => { per_page: 1 }); - if(appVersion !== latestRelease.tag_name) { + core.info(JSON.stringify(latestRelease, undefined, "\t")); + + 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..2206840 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 }); @@ -41,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) { @@ -53,6 +55,10 @@ const isFullRelease = (release) => { return !release.draft && !release.prerelease; }; +const isPreRelease = (release) => { + return release.prerelease; +}; + const isDraftRelease = (release) => { - return release.draft || release.prerelease; + return release.draft; }; diff --git a/.github/scripts/upload-release-asset.js b/.github/scripts/upload-release-asset.js index 3cd10e0..b4d4bfb 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,9 +21,21 @@ 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`; + 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: assetMetadata.id + }); + } + } + await github.request({ method: "POST", url: release.upload_url, diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index f196adc..4808c5e 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -163,6 +163,8 @@ jobs: timeout-minutes: 30 needs: [release] + + 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 new file mode 100644 index 0000000..719cc26 --- /dev/null +++ b/.github/workflows/ci-cleanup.yml @@ -0,0 +1,22 @@ +name: Github CI Cleanup + +on: workflow_dispatch + +jobs: + cleanup: + name: Cleanup Repository ${{ github.event.repository.name }} + runs-on: ubuntu-latest + timeout-minutes: 30 + + steps: + - name: Checkout Repository ${{ github.event.repository.name }} + uses: actions/checkout@v4 + + - name: Cleanup Workflow Runs + 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 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