diff --git a/.github/workflows/build-extension-catalog.yml b/.github/workflows/build-extension-catalog.yml index bbd6bbd6ed..bcd8c1c7ea 100644 --- a/.github/workflows/build-extension-catalog.yml +++ b/.github/workflows/build-extension-catalog.yml @@ -28,7 +28,10 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 + + - name: Enable Corepack + run: corepack enable - name: Configure Git run: | @@ -47,20 +50,14 @@ jobs: with: version: v3.8.0 - - name: Setup Nodejs and npm - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - - - name: Setup yarn - run: npm install -g yarn - - name: Setup Nodejs with yarn caching uses: actions/setup-node@v4 with: - node-version-file: '.nvmrc' cache: yarn + - name: Setup yarn + run: npm install -g yarn + - name: Install dependencies run: yarn @@ -75,9 +72,9 @@ jobs: - name: Build and push UI image run: | publish="yarn publish-pkgs -cp -r ${{ inputs.registry_target }} -o ${{ github.repository_owner }}" - + if [[ -n "${{ inputs.tagged_release }}" ]]; then publish="$publish -t ${{ inputs.tagged_release }}" fi - + $publish diff --git a/.github/workflows/build-extension-charts.yml b/.github/workflows/build-extension-charts.yml index a1ffe2d621..bc832cdc7b 100644 --- a/.github/workflows/build-extension-charts.yml +++ b/.github/workflows/build-extension-charts.yml @@ -28,10 +28,13 @@ jobs: contents: read steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 + - name: Enable Corepack + run: corepack enable + - name: Configure Git run: | git config user.name 'github-actions[bot]' @@ -42,20 +45,14 @@ jobs: with: version: v3.8.0 - - name: Setup Nodejs and npm - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - - - name: Setup yarn - run: npm install -g yarn - - name: Setup Nodejs with yarn caching uses: actions/setup-node@v4 with: - node-version-file: '.nvmrc' cache: yarn + - name: Setup yarn + run: npm install -g yarn + - name: Install dependencies run: yarn @@ -76,7 +73,7 @@ jobs: if [[ -n "${{ inputs.tagged_release }}" ]]; then publish="$publish -t ${{ inputs.tagged_release }}" fi - + $publish - name: Upload charts artifact @@ -98,9 +95,9 @@ jobs: pages: write steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: - ref: "${{ inputs.target_branch }}" + ref: '${{ inputs.target_branch }}' - name: Configure Git run: | @@ -125,4 +122,3 @@ jobs: env: CR_TOKEN: '${{ secrets.GITHUB_TOKEN }}' CR_SKIP_EXISTING: true - diff --git a/.github/workflows/check-plugins.yaml b/.github/workflows/check-plugins.yaml index bef1266370..7d8dcd5bd0 100644 --- a/.github/workflows/check-plugins.yaml +++ b/.github/workflows/check-plugins.yaml @@ -9,23 +9,29 @@ jobs: validate: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - - name: Validate Plugin build system - run: ./shell/scripts/test-plugins-build.sh - shell: bash + - name: Checkout + uses: actions/checkout@v4 - - name: Upload files - uses: actions/upload-artifact@v3 - if: failure() - with: - name: test - path: | - /tmp/tmp.**/test-app - !/tmp/tmp.**/test-app/node_modules/ - !/tmp/tmp.**/test-app/pkg/test-pkg/node_modules/ - retention-days: 2 + - name: Enable Corepack + run: corepack enable + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + cache: 'yarn' + + - name: Validate Plugin build system + run: ./shell/scripts/test-plugins-build.sh + shell: bash + + - name: Upload files + uses: actions/upload-artifact@v3 + if: failure() + with: + name: test + path: | + /tmp/tmp.**/test-app + !/tmp/tmp.**/test-app/node_modules/ + !/tmp/tmp.**/test-app/pkg/test-pkg/node_modules/ + retention-days: 2 diff --git a/.github/workflows/release-shell-pkg.yaml b/.github/workflows/release-shell-pkg.yaml index 7a0879f2a0..eed1093a2d 100644 --- a/.github/workflows/release-shell-pkg.yaml +++ b/.github/workflows/release-shell-pkg.yaml @@ -3,8 +3,8 @@ name: Publish Shell Package on: push: tags: - - 'shell-pkg-v*' - - 'creators-pkg-v*' + - 'shell-pkg-v*' + - 'creators-pkg-v*' jobs: build: @@ -13,46 +13,46 @@ jobs: contents: read packages: write steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - persist-credentials: false + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + persist-credentials: false - - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' + - uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' - - name: Check Tags Version Matching - env: - TAG: ${{github.ref_name}} - run: ./.github/workflows/scripts/check-package-tag-version.sh - shell: bash + - name: Check Tags Version Matching + env: + TAG: ${{github.ref_name}} + run: ./.github/workflows/scripts/check-package-tag-version.sh + shell: bash - - name: Validate Plugin build system - run: ./shell/scripts/test-plugins-build.sh - shell: bash + - name: Validate Plugin build system + run: ./shell/scripts/test-plugins-build.sh + shell: bash - # Reset the local (ci) repository state because - # The previous step (Validate Plugin build system) changes - # the version number on package.json for Shell in order - # to release it in verdaccio for it's tests - - name: Reset repository (file system) - run: | - git reset --hard HEAD - echo $YARN_REGISTRY - cat ./shell/package.json + # Reset the local (ci) repository state because + # The previous step (Validate Plugin build system) changes + # the version number on package.json for Shell in order + # to release it in verdaccio for it's tests + - name: Reset repository (file system) + run: | + git reset --hard HEAD + echo $NPM_REGISTRY + cat ./shell/package.json - - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - registry-url: 'https://registry.npmjs.org' - scope: '@rancher' - - - name: Install packages - run: yarn install --frozen-lockfile + - uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + registry-url: 'https://registry.npmjs.org' + scope: '@rancher' - - name: Publish Shell Package to npm - run: ./shell/scripts/publish-shell.sh --npm - env: - TAG: ${{github.ref_name}} - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Install packages + run: yarn install --frozen-lockfile + + - name: Publish Shell Package to npm + run: ./shell/scripts/publish-shell.sh --npm + env: + TAG: ${{github.ref_name}} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/shell/creators/extension/app/app.package.json b/creators/extension/app/app.package.json similarity index 97% rename from shell/creators/extension/app/app.package.json rename to creators/extension/app/app.package.json index 4222d09d21..809dbfa446 100644 --- a/shell/creators/extension/app/app.package.json +++ b/creators/extension/app/app.package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": false, "engines": { - "node": ">=20" + "node": ">=16" }, "dependencies": { "cache-loader": "^4.1.0", diff --git a/shell/creators/extension/app/files/.eslintignore b/creators/extension/app/files/.eslintignore similarity index 100% rename from shell/creators/extension/app/files/.eslintignore rename to creators/extension/app/files/.eslintignore diff --git a/shell/creators/extension/app/files/.eslintrc.js b/creators/extension/app/files/.eslintrc.js similarity index 100% rename from shell/creators/extension/app/files/.eslintrc.js rename to creators/extension/app/files/.eslintrc.js diff --git a/shell/creators/extension/app/files/.github/workflows/build-extension-catalog.yml b/creators/extension/app/files/.github/workflows/build-extension-catalog.yml similarity index 100% rename from shell/creators/extension/app/files/.github/workflows/build-extension-catalog.yml rename to creators/extension/app/files/.github/workflows/build-extension-catalog.yml diff --git a/shell/creators/extension/app/files/.github/workflows/build-extension-charts.yml b/creators/extension/app/files/.github/workflows/build-extension-charts.yml similarity index 100% rename from shell/creators/extension/app/files/.github/workflows/build-extension-charts.yml rename to creators/extension/app/files/.github/workflows/build-extension-charts.yml diff --git a/shell/creators/extension/app/files/.gitlab-ci.yml b/creators/extension/app/files/.gitlab-ci.yml similarity index 100% rename from shell/creators/extension/app/files/.gitlab-ci.yml rename to creators/extension/app/files/.gitlab-ci.yml diff --git a/shell/creators/extension/app/files/.vscode/settings.json b/creators/extension/app/files/.vscode/settings.json similarity index 100% rename from shell/creators/extension/app/files/.vscode/settings.json rename to creators/extension/app/files/.vscode/settings.json diff --git a/creators/extension/app/files/.yarnrc.yml b/creators/extension/app/files/.yarnrc.yml new file mode 100644 index 0000000000..29a16cc945 --- /dev/null +++ b/creators/extension/app/files/.yarnrc.yml @@ -0,0 +1,2 @@ +nodeLinker: node-modules +pnpMode: false \ No newline at end of file diff --git a/shell/creators/extension/app/files/babel.config.js b/creators/extension/app/files/babel.config.js similarity index 100% rename from shell/creators/extension/app/files/babel.config.js rename to creators/extension/app/files/babel.config.js diff --git a/shell/creators/extension/app/files/.gitignore b/creators/extension/app/files/gitignore similarity index 100% rename from shell/creators/extension/app/files/.gitignore rename to creators/extension/app/files/gitignore diff --git a/shell/creators/extension/app/files/tsconfig.json b/creators/extension/app/files/tsconfig.json similarity index 100% rename from shell/creators/extension/app/files/tsconfig.json rename to creators/extension/app/files/tsconfig.json diff --git a/shell/creators/extension/app/files/vue.config.js b/creators/extension/app/files/vue.config.js similarity index 100% rename from shell/creators/extension/app/files/vue.config.js rename to creators/extension/app/files/vue.config.js diff --git a/shell/creators/extension/app/init b/creators/extension/app/init similarity index 91% rename from shell/creators/extension/app/init rename to creators/extension/app/init index e0830e1b38..766c2f5553 100755 --- a/shell/creators/extension/app/init +++ b/creators/extension/app/init @@ -1,7 +1,6 @@ #!/usr/bin/env node /* eslint-disable no-console */ -const { execSync } = require('child_process'); const path = require('path'); const fs = require('fs-extra'); @@ -14,9 +13,10 @@ const targets = { const files = [ 'tsconfig.json', 'vue.config.js', - '.gitignore', + 'gitignore', '.eslintignore', '.eslintrc.js', + '.yarnrc.yml', 'babel.config.js', '.vscode/settings.json' ]; @@ -26,6 +26,7 @@ console.log('Creating Skeleton Application'); const args = process.argv; let appFolder = path.resolve('.'); +let shellVersion = ''; if ( args.length > 2 ) { const name = args[2]; @@ -40,7 +41,9 @@ let addGitlabWorkflow = false; let addWorkflowFolder = true; // Check for Gitlab integration option -if ( args.length > 3 ) { +if ( args.length >= 3 ) { + shellVersion = args[3]; + for (let i = 3; i < args.length; i++) { switch (args[i]) { case '-l': @@ -95,10 +98,7 @@ Object.keys(targets).forEach((target) => { const creatorPkgData = fs.readFileSync(path.join(__dirname, 'package.json')); const creatorPkg = JSON.parse(creatorPkgData); -// Fetch the latest version of @rancher/shell -const shellVersion = execSync('npm view @rancher/shell version').toString().trim(); - -// Set the latest version of @rancher/shell in the dependencies +// Set the package version of @rancher/shell in the dependencies pkg.dependencies['@rancher/shell'] = `^${ shellVersion }`; // Rest of dependencies are in the _pkgs property of package.json - copy then across @@ -138,8 +138,9 @@ if ( addWorkflowFolder ) { // Copy base files files.forEach((file) => { + const destinationFile = file === 'gitignore' ? '.gitignore' : file; const src = path.join(__dirname, 'files', file); - const dest = path.join(appFolder, file); + const dest = path.join(appFolder, destinationFile); if (!fs.existsSync(dest)) { console.log(` Adding file: ${ file }`); diff --git a/shell/creators/extension/app/package.json b/creators/extension/app/package.json similarity index 94% rename from shell/creators/extension/app/package.json rename to creators/extension/app/package.json index 46f8f99d72..f75c3628aa 100644 --- a/shell/creators/extension/app/package.json +++ b/creators/extension/app/package.json @@ -11,7 +11,7 @@ "init" ], "engines": { - "node": ">=20.0.0" + "node": ">=16.0.0" }, "_requires": [ "core-js", diff --git a/shell/creators/extension/init b/creators/extension/init old mode 100644 new mode 100755 similarity index 73% rename from shell/creators/extension/init rename to creators/extension/init index 64f9a1dc5f..80683293aa --- a/shell/creators/extension/init +++ b/creators/extension/init @@ -4,6 +4,7 @@ const { execSync } = require('child_process'); const fs = require('fs'); const path = require('path'); +const creatorPkg = require('./package.json'); const args = process.argv.slice(2); let extensionName = ''; @@ -11,6 +12,7 @@ let appName = ''; let updateOnly = false; let skeletonOnly = false; let ignoreShellDepCheck = false; +let tagUsed = ''; // To store the inferred tag args.forEach((arg, index) => { switch (arg) { @@ -47,6 +49,45 @@ if ( !extensionName && !updateOnly && !skeletonOnly ) { process.exit(1); } +// Infer the tag used based on the installed version and dist-tags +try { + const packageName = creatorPkg.name; + const currentVersion = creatorPkg.version; + + // Fetch the dist-tags from npm + const distTags = JSON.parse(execSync(`npm view ${ packageName } dist-tags --json`).toString()); + + // Find the tag matching the current version + tagUsed = Object.keys(distTags).find((tag) => distTags[tag] === currentVersion) || 'latest'; + + console.log(`Inferred tag used: ${ tagUsed }`); +} catch (error) { + console.error('Error inferring tag:', error.message); + process.exit(1); +} + +// Now, check the version of `@rancher/shell` package based on the inferred tag +let shellVersion = 'latest'; +const shellPackageName = '@rancher/shell'; + +try { + // Fetch the version of the `@rancher/shell` package that corresponds to the inferred tag + const tagVersion = execSync(`npm view ${ shellPackageName } dist-tags.${ tagUsed }`).toString().trim(); + + if (tagVersion) { + shellVersion = tagVersion; + } else { + const latestVersion = execSync(`npm view ${ shellPackageName } version`).toString().trim(); + + shellVersion = latestVersion; + } +} catch (error) { + console.error(` Failed to determine version for ${ shellPackageName }:`, error.message); + process.exit(1); +} + +console.log(` Using version ${ shellVersion } for ${ shellPackageName }`); + const basePath = process.cwd(); let skeletonPath; let isInsideSkeleton = false; @@ -98,7 +139,7 @@ try { if ( !isInsideSkeleton && !skeletonExists ) { console.log(`Creating skeleton application: ${ appName }...`); // Pass all arguments to the app/init script - execSync(`node ${ path.join(__dirname, 'app', 'init') } ${ appName } ${ args.join(' ') }`, { stdio: 'inherit' }); + execSync(`node ${ path.join(__dirname, 'app', 'init') } ${ appName } ${ shellVersion } ${ args.join(' ') }`, { stdio: 'inherit' }); // Ensure the skeleton path directory is created before attempting to change directory if ( !fs.existsSync(skeletonPath) ) { @@ -124,7 +165,7 @@ try { // Check for package existence and create it if necessary if ( !pkgExists ) { console.log(`Creating package: ${ extensionName }...`); - execSync(`node ${ path.join(__dirname, 'pkg', 'init') } ${ extensionName } ${ args.join(' ') }`, { stdio: 'inherit' }); + execSync(`node ${ path.join(__dirname, 'pkg', 'init') } ${ extensionName } ${ shellVersion } ${ args.join(' ') }`, { stdio: 'inherit' }); } if ( args.includes('--update') || args.includes('-u') ) { diff --git a/shell/creators/extension/package.json b/creators/extension/package.json similarity index 73% rename from shell/creators/extension/package.json rename to creators/extension/package.json index d5a7d1ac83..043d1959cd 100644 --- a/shell/creators/extension/package.json +++ b/creators/extension/package.json @@ -1,17 +1,19 @@ { "name": "@rancher/create-extension", "description": "Rancher UI Extension generator", - "version": "0.1.0", + "version": "0.2.0", "license": "Apache-2.0", "author": "SUSE", - "private": false, - "bin": "./init", + "packageManager": "yarn@4.4.1", + "bin": { + "create-extension": "./init" + }, "files": [ "**/*", "init" ], "engines": { - "node": ">=12" + "node": ">=16" }, "_requires": [ "core-js", @@ -22,4 +24,4 @@ "dependencies": { "fs-extra": "^10.0.0" } -} +} \ No newline at end of file diff --git a/shell/creators/extension/pkg/files/babel.config.js b/creators/extension/pkg/files/babel.config.js similarity index 100% rename from shell/creators/extension/pkg/files/babel.config.js rename to creators/extension/pkg/files/babel.config.js diff --git a/shell/creators/extension/pkg/files/index.ts b/creators/extension/pkg/files/index.ts similarity index 100% rename from shell/creators/extension/pkg/files/index.ts rename to creators/extension/pkg/files/index.ts diff --git a/shell/creators/extension/pkg/files/tsconfig.json b/creators/extension/pkg/files/tsconfig.json similarity index 100% rename from shell/creators/extension/pkg/files/tsconfig.json rename to creators/extension/pkg/files/tsconfig.json diff --git a/shell/creators/extension/pkg/files/vue.config.js b/creators/extension/pkg/files/vue.config.js similarity index 100% rename from shell/creators/extension/pkg/files/vue.config.js rename to creators/extension/pkg/files/vue.config.js diff --git a/shell/creators/extension/pkg/init b/creators/extension/pkg/init similarity index 90% rename from shell/creators/extension/pkg/init rename to creators/extension/pkg/init index 99b969c4af..a46ee7905f 100755 --- a/shell/creators/extension/pkg/init +++ b/creators/extension/pkg/init @@ -36,10 +36,13 @@ const args = process.argv; const name = args[2]; const folder = path.resolve('.'); const pkgFolder = path.join(folder, 'pkg', name); +let shellVersion = ''; let addTypeFolders = true; -if ( args.length > 3 ) { +if ( args.length >= 3 ) { + shellVersion = args[3]; + for ( let i = 3; i < args.length; i++ ) { switch (args[i]) { case '--skip-templates': @@ -115,20 +118,12 @@ function fetchLatestVersion() { pkg.rancher = { annotations: { 'catalog.cattle.io/rancher-version': `>= ${ release.tag_name }` } }; - // Fetch the latest version of @rancher/shell - const latestShellVersion = execSync('npm view @rancher/shell version').toString().trim() || null; - - if (!latestShellVersion) { + if ( !shellVersion ) { console.log('Could not get a shell version from npm, skipping adding catalog.cattle.io/ui-extensions-version annotation to package.json'); } else { - const splitShellVersion = latestShellVersion.split('.'); - const majorVersion = splitShellVersion[0]; - const minorVersion = splitShellVersion[1]; - const parsedShellVersion = `${ majorVersion }.${ minorVersion }.0`; + console.log(` Adding catalog.cattle.io/ui-extensions-version '>= ${ shellVersion }' to package.json`); - console.log(` Adding catalog.cattle.io/ui-extensions-version '>= ${ parsedShellVersion }' to package.json`); - - pkg.rancher.annotations['catalog.cattle.io/ui-extensions-version'] = `>= ${ parsedShellVersion }`; + pkg.rancher.annotations['catalog.cattle.io/ui-extensions-version'] = `>= ${ shellVersion }`; } writePackageJson(); diff --git a/shell/creators/extension/pkg/package.json b/creators/extension/pkg/package.json similarity index 96% rename from shell/creators/extension/pkg/package.json rename to creators/extension/pkg/package.json index 8b48374aa7..0566ff56fd 100644 --- a/shell/creators/extension/pkg/package.json +++ b/creators/extension/pkg/package.json @@ -11,7 +11,7 @@ "init" ], "engines": { - "node": ">=20.0.0" + "node": ">=16.0.0" }, "resolutions": { "d3-color": "3.1.0", diff --git a/shell/creators/extension/pkg/pkg.package.json b/creators/extension/pkg/pkg.package.json similarity index 97% rename from shell/creators/extension/pkg/pkg.package.json rename to creators/extension/pkg/pkg.package.json index 9d1a44ec42..988b17589e 100644 --- a/shell/creators/extension/pkg/pkg.package.json +++ b/creators/extension/pkg/pkg.package.json @@ -6,7 +6,7 @@ "rancher": true, "scripts": {}, "engines": { - "node": ">=12" + "node": ">=16" }, "devDependencies": { "@vue/cli-plugin-babel": "~5.0.0", diff --git a/shell/creators/extension/pkg/vue-shim.ts b/creators/extension/pkg/vue-shim.ts similarity index 100% rename from shell/creators/extension/pkg/vue-shim.ts rename to creators/extension/pkg/vue-shim.ts diff --git a/shell/creators/extension/update/init b/creators/extension/update/init similarity index 100% rename from shell/creators/extension/update/init rename to creators/extension/update/init diff --git a/shell/creators/extension/update/package.json b/creators/extension/update/package.json similarity index 93% rename from shell/creators/extension/update/package.json rename to creators/extension/update/package.json index 46d1ff35f3..a847b9abcd 100644 --- a/shell/creators/extension/update/package.json +++ b/creators/extension/update/package.json @@ -12,7 +12,7 @@ "upgrade" ], "engines": { - "node": ">=20.0.0" + "node": ">=16.0.0" }, "dependencies": { "fs-extra": "^10.0.0" diff --git a/shell/creators/extension/update/upgrade b/creators/extension/update/upgrade similarity index 100% rename from shell/creators/extension/update/upgrade rename to creators/extension/update/upgrade diff --git a/docusaurus/docs/extensions/extensions-getting-started.md b/docusaurus/docs/extensions/extensions-getting-started.md index 836ce7a3fe..34d76e5b20 100644 --- a/docusaurus/docs/extensions/extensions-getting-started.md +++ b/docusaurus/docs/extensions/extensions-getting-started.md @@ -67,14 +67,14 @@ You should be able to reach the older Ember UI by navigating to the Rancher API There are a few options available to be passed as an argument to the `@rancher/extension` script: -| Option | Description | -| :-----------------------: | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `--update \| -u` | This will update all dependencies within the extension to match the declared versions in the shell. Update can be ran independently or along with creating an extension (e.g. `yarn create @rancher/extension my-extension --update` | -| `--app-name \| -a ` | Allows specifying a different name for the skeleton application instead of using the extension name. | -| `--skeleton-only \| -s` | Installs only the skeleton application without creating the extension package. | -| `-l` | This will automatically add the [`.gitlab-ci.yml`](https://github.com/rancher/dashboard/blob/master/shell/creators/extension/app/files/.gitlab-ci.yml) pipeline file for integration with GitLab | -| `-w` | Does not add the Github workflow files [`build-extension-catalog.yml`, `build-extension-charts.yml`](https://github.com/rancher/dashboard/tree/master/shell/creators/extension/app/files/.github/workflows) to be used as Github actions. These files will be added automatically by default. | -| `-t` | Does not add the template folders automatically into the Extension package. These folders will be added automatically by default | +| Option | Description | +| :-----------------------: | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `--update \| -u` | This will update all dependencies within the extension to match the declared versions in the shell. Update can be ran independently or along with creating an extension (e.g. `yarn create @rancher/extension my-extension --update` | +| `--app-name \| -a ` | Allows specifying a different name for the skeleton application instead of using the extension name. | +| `--skeleton-only \| -s` | Installs only the skeleton application without creating the extension package. | +| `-l` | This will automatically add the [`.gitlab-ci.yml`](https://github.com/rancher/dashboard/blob/master/creators/extension/app/files/.gitlab-ci.yml) pipeline file for integration with GitLab | +| `-w` | Does not add the Github workflow files [`build-extension-catalog.yml`, `build-extension-charts.yml`](https://github.com/rancher/dashboard/tree/master/creators/extension/app/files/.github/workflows) to be used as Github actions. These files will be added automatically by default. | +| `-t` | Does not add the template folders automatically into the Extension package. These folders will be added automatically by default | --- @@ -322,7 +322,7 @@ You'll notice that if you reload the Rancher UI, the extension is not persistent Creating a Release for your extension is the official avenue for loading extensions into any Rancher instance. As mentioned in the [Introduction](./introduction.md), the extension can be packaged into a Helm chart and added as a Helm repository to be easily accessible from your Rancher Manager. -We have created [workflows](https://github.com/rancher/dashboard/tree/master/shell/creators/extension/app/files/.github/workflows) for [Github Actions](https://docs.github.com/en/actions) which will automatically build, package, and release your extension as a Helm chart for use within your Github repository, and an [Extension Catalog Image](./advanced/air-gapped-environments) (ECI) which is published into a specified container registry (`ghcr.io` by default). Depending on the use case, you can utilize the Github repository as a [Helm repository](https://helm.sh/docs/topics/chart_repository/) endpoint which we can use to consume the chart in Rancher, or you can import the ECI into the Extension Catalog list and serve the Helm charts locally. +We have created [workflows](https://github.com/rancher/dashboard/tree/master/creators/extension/app/files/.github/workflows) for [Github Actions](https://docs.github.com/en/actions) which will automatically build, package, and release your extension as a Helm chart for use within your Github repository, and an [Extension Catalog Image](./advanced/air-gapped-environments) (ECI) which is published into a specified container registry (`ghcr.io` by default). Depending on the use case, you can utilize the Github repository as a [Helm repository](https://helm.sh/docs/topics/chart_repository/) endpoint which we can use to consume the chart in Rancher, or you can import the ECI into the Extension Catalog list and serve the Helm charts locally. > **Note:** GitLab support is offered through leverging the ECI build. For configuration instructions, follow the setps in the [Gitlab Integration](./publishing#gitlab-integration) section. diff --git a/docusaurus/docs/extensions/publishing.md b/docusaurus/docs/extensions/publishing.md index 332a356b39..af5747ba4d 100644 --- a/docusaurus/docs/extensions/publishing.md +++ b/docusaurus/docs/extensions/publishing.md @@ -5,7 +5,7 @@ There are currently two options for building and publishing a extensions: 1. Building the Helm charts and necessary assets of an extension that can be committed into a Github or Helm repository. 2. Building an [Extension Catalog Image](./advanced/air-gapped-environments) that can be pushed or mirrored into a container registry. -As discussed in the [Getting Started](./extensions-getting-started#creating-a-release) section, we have established a [workflow](https://github.com/rancher/dashboard/tree/master/shell/creators/extension/app/files/.github/workflows) using [Github reusable workflows](https://docs.github.com/en/actions/using-workflows/reusing-workflows), that automatically handles the build and publication of both the Helm charts and ECI into the Extension's GitHub repository. However, this workflow can be omitted for a more hands-on approach to publishing Extensions. +As discussed in the [Getting Started](./extensions-getting-started#creating-a-release) section, we have established a [workflow](https://github.com/rancher/dashboard/tree/master/creators/extension/app/files/.github/workflows) using [Github reusable workflows](https://docs.github.com/en/actions/using-workflows/reusing-workflows), that automatically handles the build and publication of both the Helm charts and ECI into the Extension's GitHub repository. However, this workflow can be omitted for a more hands-on approach to publishing Extensions. > Note: An explanation on the workflow files can be found in the [Additional Release Configuration](#additional-release-configuration) section. @@ -130,7 +130,7 @@ yarn publish-pkgs -c -p -r -o # Additional Release Configuration -Depending on your use case, there are multiple options on building and creating releases. When building an extension within a Github repository, you have the option of utilizing an action that triggers [prebuilt workflows](https://github.com/rancher/dashboard/tree/master/shell/creators/extension/app/files/.github/workflows). When added to your extension, the `./github/workflows` directory will contain the files: `build-extension-charts.yml` and `build-extension-catalog.yml`. These workflows accomplish two seperate actions: +Depending on your use case, there are multiple options on building and creating releases. When building an extension within a Github repository, you have the option of utilizing an action that triggers [prebuilt workflows](https://github.com/rancher/dashboard/tree/master/creators/extension/app/files/.github/workflows). When added to your extension, the `./github/workflows` directory will contain the files: `build-extension-charts.yml` and `build-extension-catalog.yml`. These workflows accomplish two seperate actions: - `build-extension-charts` - Builds the Helm charts and necessary assets that are then published to the specified branch (defaults to `gh-pages`). - The versioning of these builds is determined by the Extension Package `version` property found in `./pkg//package.json` @@ -147,7 +147,7 @@ By default, both of these actions are triggered by pushing into the `main` branc ## GitLab Integration -When building an extension that will be housed in a GitLab repository or hosted environment, there is only one option for publishing automatically - That is by utilizing the provided [GitLab Pipeline CI file](https://github.com/rancher/dashboard/blob/master/shell/creators/extension/app/files/.gitlab-ci.yml) that is generated when [creating the skeleton app](extensions-getting-started#creating-the-skeleton-app). +When building an extension that will be housed in a GitLab repository or hosted environment, there is only one option for publishing automatically - That is by utilizing the provided [GitLab Pipeline CI file](https://github.com/rancher/dashboard/blob/master/creators/extension/app/files/.gitlab-ci.yml) that is generated when [creating the skeleton app](extensions-getting-started#creating-the-skeleton-app). This pipeline will build an ECI and publish it to container registry (`registry.gitlab.com` by default) to allow for importing into Rancher Manager. The actual pipeline jobs are defined in the [Dashboard repo](https://github.com/rancher/dashboard/blob/master/.gitlab/workflows/build-extension-catalog.gitlab-ci.yml) to allow for proper versioning and to apply any updates to the pipeline without any additional work from the Extension developer. diff --git a/package.json b/package.json index eceaeb3aba..f1eaae33f5 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "node": ">=20.0.0" }, "workspaces": [ - "pkg/rancher-components" + "pkg/rancher-components", + "creators/extension" ], "scripts": { "build-pkg": "yarn lint && ./shell/scripts/build-pkg.sh", diff --git a/shell/scripts/publish-shell.sh b/shell/scripts/publish-shell.sh index 6f657ea4ff..e2ce2841eb 100755 --- a/shell/scripts/publish-shell.sh +++ b/shell/scripts/publish-shell.sh @@ -6,10 +6,10 @@ BASE_DIR="$( pwd )" SHELL_DIR=$BASE_DIR/shell/ -CREATORS_DIR=$BASE_DIR/shell/creators/extension -PUBLISH_ARGS="--no-git-tag-version --access public $NPM_TAG" +CREATORS_DIR=$BASE_DIR/creators/extension +PUBLISH_ARGS="--no-git-tag-version --access public --registry $NPM_REGISTRY $NPM_TAG" FORCE_PUBLISH_TO_NPM="false" -DEFAULT_YARN_REGISTRY="https://registry.npmjs.org" +DEFAULT_NPM_REGISTRY="https://registry.npmjs.org" # if TAG doesn't exist, we can exit as it's needed for any type of publish. if [ -z "$TAG" ]; then @@ -29,7 +29,7 @@ if [ "$1" == "--npm" ]; then fi if [ "$FORCE_PUBLISH_TO_NPM" == "true" ]; then - export YARN_REGISTRY=$DEFAULT_YARN_REGISTRY + export NPM_REGISTRY=$DEFAULT_NPM_REGISTRY fi pushd ${SHELL_DIR} >/dev/null @@ -48,7 +48,7 @@ function publish() { # if the PKG_VERSION has a - it means it will be a pre-release if [[ $PKG_VERSION == *"-"* ]]; then - PUBLISH_ARGS="--no-git-tag-version --access public --tag pre-release" + PUBLISH_ARGS="--no-git-tag-version --access public --registry $NPM_REGISTRY --tag pre-release" fi echo "Publishing ${NAME} from ${FOLDER}" @@ -64,7 +64,9 @@ function publish() { # Make a note of dependency versions, if required node ${SCRIPT_DIR}/record-deps.js - yarn publish . --new-version ${PKG_VERSION} ${PUBLISH_ARGS} + echo "Publishing to registry: $NPM_REGISTRY" + + npm publish ${PUBLISH_ARGS} RET=$? popd >/dev/null @@ -75,9 +77,6 @@ function publish() { fi } -# Generate the type definitions for the shell -${SCRIPT_DIR}/typegen.sh - echo "TAG ${TAG}" # let's get the package name and version from the tag @@ -87,6 +86,11 @@ PKG_V=$(sed 's/.*-pkg-v//'<<< "$TAG") echo "PKG_NAME ${PKG_NAME}" echo "PKG_V ${PKG_V}" +# Generate the type definitions for the shell +if [ ${PKG_NAME} == "shell" ]; then + ${SCRIPT_DIR}/typegen.sh +fi + # version comparison checks case $PKG_NAME in "shell") diff --git a/shell/scripts/test-plugins-build.sh b/shell/scripts/test-plugins-build.sh index e1a73bc44a..bbac4cc4f7 100755 --- a/shell/scripts/test-plugins-build.sh +++ b/shell/scripts/test-plugins-build.sh @@ -8,8 +8,8 @@ SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) BASE_DIR="$( cd $SCRIPT_DIR && cd ../.. & pwd)" SHELL_DIR=$BASE_DIR/shell/ SHELL_VERSION="99.99.99" -DEFAULT_YARN_REGISTRY="https://registry.yarnpkg.com/" -VERDACCIO_YARN_REGISTRY="http://localhost:4873" +DEFAULT_NPM_REGISTRY="https://registry.npmjs.org/" +VERDACCIO_NPM_REGISTRY="http://localhost:4873" echo ${SCRIPT_DIR} @@ -69,7 +69,7 @@ else rm -rf ~/.config/verdaccio/storage/@rancher/* fi -export YARN_REGISTRY=$VERDACCIO_YARN_REGISTRY +export NPM_REGISTRY=$VERDACCIO_NPM_REGISTRY export NUXT_TELEMETRY_DISABLED=1 # Remove test package from previous run, if present @@ -81,12 +81,17 @@ fi # We need to patch the version number of the shell, otherwise if we are running # with the currently published version, things will fail as those versions # are already published and Verdaccio will check, since it is a read-through cache -sed -i.bak -e "s/\"version\": \"[0-9]*.[0-9]*.[0-9]*\(-alpha\.[0-9]*\|-release[0-9]*.[0-9]*.[0-9]*\|-rc\.[0-9]*\)\{0,1\}\",/\"version\": \"${SHELL_VERSION}\",/g" ${SHELL_DIR}/package.json -rm ${SHELL_DIR}/package.json.bak +update_version_in_package_json() { + local package_json_path="$1" + local version="$2" -# Same as above for Rancher Components -# We might have bumped the version number but its not published yet, so this will fail -sed -i.bak -e "s/\"version\": \"[0-9]*.[0-9]*.[0-9]*\(-alpha\.[0-9]*\|-release[0-9]*.[0-9]*.[0-9]*\|-rc\.[0-9]*\)\{0,1\}\",/\"version\": \"${SHELL_VERSION}\",/g" ${BASE_DIR}/pkg/rancher-components/package.json + sed -i.bak -e "s/\"version\": \"[0-9]*.[0-9]*.[0-9]*\(-alpha\.[0-9]*\|-release[0-9]*.[0-9]*.[0-9]*\|-rc\.[0-9]*\)\{0,1\}\",/\"version\": \"${version}\",/g" "$package_json_path" + rm "${package_json_path}.bak" +} + +update_version_in_package_json "${SHELL_DIR}/package.json" "${SHELL_VERSION}" +update_version_in_package_json "${BASE_DIR}/pkg/rancher-components/package.json" "${SHELL_VERSION}" +update_version_in_package_json "${BASE_DIR}/creators/extension/package.json" "${SHELL_VERSION}" # Publish shell pkg (tag is needed as publish-shell is optimized to work with release-shell-pkg workflow) echo "Publishing Shell package to local registry" @@ -101,6 +106,9 @@ ${SHELL_DIR}/scripts/publish-shell.sh # Publish rancher components yarn build:lib + +npm set registry ${VERDACCIO_NPM_REGISTRY} +yarn config set registry ${VERDACCIO_NPM_REGISTRY} yarn publish:lib # We pipe into cat for cleaner logging - we need to set pipefail @@ -167,7 +175,7 @@ function clone_repo_test_extension_build() { echo -e "\nSetting up $REPO_NAME repository locally\n" # set registry to default (to install all of the other dependencies) - yarn config set registry ${DEFAULT_YARN_REGISTRY} + yarn config set registry ${DEFAULT_NPM_REGISTRY} if [ "${TEST_PERSIST_BUILD}" != "true" ]; then echo "Removing folder ${BASE_DIR}/$REPO_NAME" @@ -182,7 +190,7 @@ function clone_repo_test_extension_build() { yarn install # set registry to local verdaccio (to install new shell) - yarn config set registry ${VERDACCIO_YARN_REGISTRY} + yarn config set registry ${VERDACCIO_NPM_REGISTRY} # update package.json to use a specific version of shell sed -i.bak -e "s/\"\@rancher\/shell\": \"[0-9]*.[0-9]*.[0-9]*\",/\"\@rancher\/shell\": \"${SHELL_VERSION}\",/g" package.json @@ -210,7 +218,7 @@ function clone_repo_test_extension_build() { # delete folder echo "Removing folder ${BASE_DIR}/$REPO_NAME" rm -rf ${BASE_DIR}/$REPO_NAME - yarn config set registry ${DEFAULT_YARN_REGISTRY} + yarn config set registry ${DEFAULT_NPM_REGISTRY} } # Here we just add the extension that we want to include as a check (all our official extensions should be included here) diff --git a/tsconfig.json b/tsconfig.json index f6ffded3ab..09ed17997b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -29,7 +29,6 @@ "dist", "dist-pkg", "cypress", - "shell/creators", "shell/scripts", "cypress", "./cypress.config.ts",