Skip to content

Commit

Permalink
Merge pull request #98 from DonColon/feature-pipeline
Browse files Browse the repository at this point in the history
Fixed pipeline and added cleanup workflow
  • Loading branch information
DonColon authored Mar 16, 2024
2 parents f434a71 + 5c8e9d7 commit 140523c
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 9 deletions.
16 changes: 16 additions & 0 deletions .github/scripts/cleanup-workflow-runs.js
Original file line number Diff line number Diff line change
@@ -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,
});
}
};
4 changes: 3 additions & 1 deletion .github/scripts/download-release-asset.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
18 changes: 12 additions & 6 deletions .github/scripts/retrieve-latest-release.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { formatRepositoryTitle } from "./utils.js";
import pkg from "../../package.json" assert { type: "json" };

export default async ({ core, context, github }) => {
Expand All @@ -15,20 +14,19 @@ 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;
core.info(`First release version ${appVersion}`);
}

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
});
Expand All @@ -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) {
Expand All @@ -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;
};
16 changes: 14 additions & 2 deletions .github/scripts/upload-release-asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ jobs:
timeout-minutes: 30

needs: [release]

if: github.ref_name == 'main' || github.ref_name == 'dev'

env:
node_version: 20.x
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/ci-cleanup.yml
Original file line number Diff line number Diff line change
@@ -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 });
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 140523c

Please sign in to comment.