Skip to content

Commit

Permalink
Add CI
Browse files Browse the repository at this point in the history
Resolves #1.

Use same lint of rancher/dashboard/pkg/rancher-components/package.json.

Signed-off-by: Masashi Honma <masashi.honma@gmail.com>
  • Loading branch information
masap committed Jan 30, 2025
1 parent 1339a93 commit 7f4ff82
Show file tree
Hide file tree
Showing 14 changed files with 629 additions and 189 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI Workflow

on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Nodejs with yarn caching
uses: actions/setup-node@v4
with:
cache: yarn
node-version-file: ".nvmrc"

- name: Install dependencies
run: |
yarn install
- name: Run lint
run: |
yarn lint
- name: Build Rancher Extension
run: |
yarn build-pkg supportability-review-app
27 changes: 23 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,26 @@
"node": ">=20"
},
"devDependencies": {
"core-js": "^3.39.0",
"eslint": "8.39.0",
"prettier": "3.4.2"
"@typescript-eslint/eslint-plugin": "5.62.0",
"@typescript-eslint/parser": "5.62.0",
"@vue/cli-plugin-eslint": "5.0.8",
"@vue/cli-plugin-typescript": "5.0.8",
"@vue/cli-service": "5.0.8",
"@vue/eslint-config-standard": "6.1.0",
"@vue/eslint-config-typescript": "9.1.0",
"babel-eslint": "10.1.0",
"eslint-plugin-import": "2.31.0",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "5.2.0",
"eslint-plugin-standard": "4.0.0",
"eslint-plugin-vue": "9.10.0",
"eslint": "7.32.0",
"typescript": "5.6.3",
"vue": "^3.2.13"
},
"peerDependencies": {
"core-js": "3.40.0",
"vue": "^3.2.13"
},
"dependencies": {
"@rancher/shell": "^3.0.1"
Expand All @@ -25,6 +42,8 @@
"build-pkg": "./node_modules/@rancher/shell/scripts/build-pkg.sh",
"serve-pkgs": "./node_modules/@rancher/shell/scripts/serve-pkgs",
"publish-pkgs": "./node_modules/@rancher/shell/scripts/extension/publish",
"parse-tag-name": "./node_modules/@rancher/shell/scripts/extension/parse-tag-name"
"parse-tag-name": "./node_modules/@rancher/shell/scripts/extension/parse-tag-name",
"lint": "eslint --ext .jsx,.js,.tsx,.ts .",
"lint:fix": "eslint --fix --ext .jsx,.js,.tsx,.ts ."
}
}
20 changes: 9 additions & 11 deletions pkg/supportability-review-app/config/types.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
export const SUPPORTABILITY_REVIEW_STORE = 'sr'
export const SUPPORTABILITY_REVIEW_STORE = 'sr';

// If this is changed, then the same should reflect in en-us.yaml
export const SUPPORTABILITY_REVIEW_PRODUCT_NAME = 'sr'
export const SUPPORTABILITY_REVIEW_PRODUCT_NAME = 'sr';

export const SUPPORTABILITY_REVIEW_CRD_IDS = {
REVIEW_BUNDLE: 'sr.cattle.io.reviewbundle'
}
export const SUPPORTABILITY_REVIEW_CRD_IDS = { REVIEW_BUNDLE: 'sr.cattle.io.reviewbundle' };

export const SR_APP_PAGES = {
DASHBOARD: 'dashboard',
VIEW_REPORT: 'view-report',
DASHBOARD: 'dashboard',
VIEW_REPORT: 'view-report',
REVIEW_BUNDLE: 'review-bundle'
}
};

export const SR_CHARTS = {
OPERATOR: 'rancher-supportability-review',
CRD: 'rancher-supportability-review-crd'
}
CRD: 'rancher-supportability-review-crd'
};

export const BLANK_CLUSTER = '_'
export const BLANK_CLUSTER = '_';
3 changes: 2 additions & 1 deletion pkg/supportability-review-app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { importTypes } from '@rancher/auto-import';
import { IPlugin } from '@shell/core/types';
import extensionRouting from './routing/sr-routing';
import srStore from './store';
import product from './product';

// Init the package
export default function(plugin: IPlugin): void {
Expand All @@ -12,7 +13,7 @@ export default function(plugin: IPlugin): void {
plugin.metadata = require('./package.json');

// Load a product
plugin.addProduct(require('./product'));
plugin.addProduct(product);

// Add Vuex store
plugin.addDashboardStore(srStore.config.namespace, srStore.specifics, srStore.config);
Expand Down
83 changes: 44 additions & 39 deletions pkg/supportability-review-app/models/sr.cattle.io.reviewbundle.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,88 @@
import SteveModel from '@shell/plugins/steve/steve-class'
import { createRoute } from '../utils/custom-routing'
import SteveModel from '@shell/plugins/steve/steve-class';
import { createRoute } from '../utils/custom-routing';

export default class ReviewBundle extends SteveModel {
get _availableActions() {
let out = super._availableActions
let out = super._availableActions;

// Remove unused menus
const toFilter = ['goToViewConfig', 'goToClone', 'download']
const toFilter = ['goToViewConfig', 'goToClone', 'download'];

out = out.filter((action) => {
if (!toFilter.includes(action.action)) {
return action
return action;
}
})
});

// Add custom menus
const t = this.$rootGetters['i18n/t']
const t = this.$rootGetters['i18n/t'];

const downloadBundle = {
action: 'downloadThisBundle',
action: 'downloadThisBundle',
enabled: this.hasBundle,
icon: 'icon icon-fw icon-download',
label: t('sr.menuLabels.downloadBundle'),
total: 1
}
icon: 'icon icon-fw icon-download',
label: t('sr.menuLabels.downloadBundle'),
total: 1
};

const viewReport = {
action: 'viewReport',
action: 'viewReport',
enabled: this.hasBundle,
icon: 'icon icon-fw icon-info',
label: t('sr.menuLabels.viewReport'),
total: 1
}
icon: 'icon icon-fw icon-info',
label: t('sr.menuLabels.viewReport'),
total: 1
};

out.unshift(viewReport)
out.unshift(downloadBundle)
out.unshift(viewReport);
out.unshift(downloadBundle);

return out
return out;
}

viewReport() {
const route = createRoute('report', {}, {})
window.location.href = `../${route.params.product}/view-report/${this.id}/?bundlename=${this.metadata.name}`
const route = createRoute('report', {}, {});

window.location.href = `../${ route.params.product }/view-report/${ this.id }/?bundlename=${ this.metadata.name }`;
}

downloadFromUrl(url, filename) {
fetch(url)
.then((response) => response.blob())
.then((blob) => {
const link = document.createElement('a')
link.href = URL.createObjectURL(blob)
link.download = filename
link.click()
const link = document.createElement('a');

link.href = URL.createObjectURL(blob);
link.download = filename;
link.click();
})
.catch(console.error)
.catch(console.error);

Check warning on line 58 in pkg/supportability-review-app/models/sr.cattle.io.reviewbundle.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
}

async downloadThisBundle() {
const hostname = window.location.host
const hostname = window.location.host;

try {
this.downloadFromUrl(
'https://' +
hostname +
'/k8s/clusters/local/api/v1/namespaces/sr-operator-system/services/http:sr-bundle-app-frontend-service:80/proxy/' +
'?key=' +
this.metadata.name +
'&type=file',
`https://${
hostname
}/k8s/clusters/local/api/v1/namespaces/sr-operator-system/services/http:sr-bundle-app-frontend-service:80/proxy/` +
`?key=${
this.metadata.name
}&type=file`,
this.status?.fileName
)
);
} catch (err) {
this.$dispatch('growl/fromError', { title: 'Error downloading file', err }, { root: true })
this.$dispatch('growl/fromError', { title: 'Error downloading file', err }, { root: true });
}
}

get hasBundle() {
const fileName = this.status?.fileName
const fileName = this.status?.fileName;

if (fileName === undefined || fileName === '') {
return false
return false;
} else {
return true
return true;
}
}
}
78 changes: 40 additions & 38 deletions pkg/supportability-review-app/product.js
Original file line number Diff line number Diff line change
@@ -1,91 +1,93 @@
import { STATE, NAME as NAME_COL, AGE, NAMESPACE as NAMESPACE_COL } from '@shell/config/table-headers'
import { SUPPORTABILITY_REVIEW_PRODUCT_NAME, SUPPORTABILITY_REVIEW_CRD_IDS, SR_APP_PAGES } from './config/types'
import { rootRoute, createRoute } from './utils/custom-routing'
import { STATE, NAME as NAME_COL, AGE } from '@shell/config/table-headers';
import { SUPPORTABILITY_REVIEW_PRODUCT_NAME, SUPPORTABILITY_REVIEW_CRD_IDS, SR_APP_PAGES } from './config/types';
import { rootRoute, createRoute } from './utils/custom-routing';

export function init($plugin, store) {
const { product, configureType, virtualType, basicType, headers } = $plugin.DSL(
const {
product, configureType, virtualType, basicType, headers
} = $plugin.DSL(
store,
SUPPORTABILITY_REVIEW_PRODUCT_NAME
// SUPPORTABILITY_REVIEW_PRODUCT_FULL_NAME,
)
);

function getBundleSizeString(row) {
if (row.status === undefined || row.status.fileSize === undefined) return '---'
if (row.status === undefined || row.status.fileSize === undefined) return '---';

const one_kilo = 1024
const one_mega = one_kilo * 1024
const one_giga = one_mega * 1024
const size = row.status.fileSize
const oneKilo = 1024;
const oneMega = oneKilo * 1024;
const oneGiga = oneMega * 1024;
const size = row.status.fileSize;

if (size < one_kilo) {
return size + ' B'
} else if (size < one_mega) {
return (size / one_kilo).toFixed(2) + ' KiB'
} else if (size < one_giga) {
return (size / one_mega).toFixed(2) + ' MiB'
if (size < oneKilo) {
return `${ size } B`;
} else if (size < oneMega) {
return `${ (size / oneKilo).toFixed(2) } KiB`;
} else if (size < oneGiga) {
return `${ (size / oneMega).toFixed(2) } MiB`;
} else {
return size + ' B'
return `${ size } B`;
}
}

// app in sidebar
product({
icon: 'service',
inStore: 'management',
icon: 'service',
inStore: 'management',
showClusterSwitcher: false,
weight: 100,
to: rootRoute()
})
weight: 100,
to: rootRoute()
});

// dashboard menu entry in SR App
virtualType({
labelKey: 'sr.menuLabels.dashboard',
// label: store.getters["i18n/t"]("sr.menuLabels.dashboard"),
name: SR_APP_PAGES.DASHBOARD,
route: rootRoute()
})
name: SR_APP_PAGES.DASHBOARD,
route: rootRoute()
});

// defining a k8s resource as page
configureType(SUPPORTABILITY_REVIEW_CRD_IDS.REVIEW_BUNDLE, {
displayName: store.getters['i18n/t'](`typeLabel."${SUPPORTABILITY_REVIEW_CRD_IDS.REVIEW_BUNDLE}"`),
displayName: store.getters['i18n/t'](`typeLabel."${ SUPPORTABILITY_REVIEW_CRD_IDS.REVIEW_BUNDLE }"`),
isCreatable: true,
isEditable: false,
isEditable: false,
isRemovable: true
})
});
headers(SUPPORTABILITY_REVIEW_CRD_IDS.REVIEW_BUNDLE, [
STATE,
NAME_COL,
{
name: 'Cluster',
name: 'Cluster',
labelKey: 'tableHeaders.clusterCount',
getValue: (row) => row.status?.clusterCount || '---',
sort: ['status.clusterCount']
sort: ['status.clusterCount']
},
{
name: 'Pass',
name: 'Pass',
labelKey: 'tableHeaders.pass',
getValue: (row) => row.status?.checkResult || '---',
sort: ['status.checkResult']
sort: ['status.checkResult']
},
{
name: 'Size',
name: 'Size',
labelKey: 'tableHeaders.bundleSize',
getValue: (row) => getBundleSizeString(row),
sort: ['status.fileSize']
sort: ['status.fileSize']
},
AGE
])
]);

virtualType({
label: store.getters['i18n/t']('sr.menuLabels.viewReport'),
name: SR_APP_PAGES.VIEW_REPORT,
name: SR_APP_PAGES.VIEW_REPORT,
route: createRoute('view-report')
})
});

// registering the defined pages as side-menu entries
basicType([
SR_APP_PAGES.DASHBOARD,
SUPPORTABILITY_REVIEW_CRD_IDS.REVIEW_BUNDLE
// SR_APP_PAGES.VIEW_REPORT,
])
]);
}
Loading

0 comments on commit 7f4ff82

Please sign in to comment.