Skip to content

Commit

Permalink
feat: build & publish dynamic plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneswuerbach committed May 14, 2024
1 parent d9ff4ca commit 637b937
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 21 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ jobs:
- run: yarn tsc
- run: yarn test:all
- run: yarn build:all
- run: ./scripts/build-dynamic-plugins.sh
7 changes: 7 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:

- run: yarn build:all

- run: ./scripts/build-dynamic-plugins.sh

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
Expand All @@ -36,3 +38,8 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Upload dynamic plugin to release
run: ./scripts/upload-dynamic-plugins.sh '${{ steps.changesets.outputs.publishedPackages }}'
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ node_modules/
# Build output
dist
dist-types
dist-dynamic

# Temporary change files created by Vim
*.swp
Expand Down
21 changes: 0 additions & 21 deletions plugins/humanitec/dynamic-export/export-dynamic-plugins.sh

This file was deleted.

File renamed without changes.
28 changes: 28 additions & 0 deletions scripts/build-dynamic-plugins.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh
set -e

currentDir=$(cd "$(dirname "$0")" && pwd)
pluginDir=$currentDir/../plugins
mkdir -p "$currentDir/output"

# More details on dynamic-plugins can be found here:
# https://github.com/janus-idp/backstage-showcase/blob/main/showcase-docs/dynamic-plugins.md

echo ===================================
echo Exporting frontend plugin
echo ===================================
cd "$pluginDir/humanitec"
npx --yes @janus-idp/[email protected] package export-dynamic-plugin --embed-as-dependencies --clean --no-in-place
npm pack ./dist-dynamic --pack-destination "$currentDir/output"
echo ===================================
echo Exporting backend plugin
echo ===================================
cd "$pluginDir/humanitec-backend"
npx --yes @janus-idp/[email protected] package export-dynamic-plugin --embed-as-dependencies --clean
npm pack ./dist-dynamic --pack-destination "$currentDir/output"
echo ===================================
echo Exporting backend scaffolder module
echo ===================================
cd "$pluginDir/humanitec-backend-scaffolder-module"
npx --yes @janus-idp/[email protected] package export-dynamic-plugin --embed-as-dependencies --clean
npm pack ./dist-dynamic --pack-destination "$currentDir/output"
25 changes: 25 additions & 0 deletions scripts/upload-dynamic-plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env node

const { execSync } = require('child_process');
const { join: pathJoin } = require('path');

const publishedPackagesJSON = process.argv[2];

// The format is [{"name": "@xx/xx", "version": "1.2.0"}, {"name": "@xx/xy", "version": "0.8.9"}]
// https://github.com/changesets/action/tree/v1/?tab=readme-ov-file#outputs

if (!publishedPackagesJSON) {
console.error('Please provide the list of published packages');
process.exit(1);
}

const publishedPackages = JSON.parse(publishedPackagesJSON);

for (const package of publishedPackages) {
package.name += '-dynamic'
console.log(`Publishing package: ${package.name}@${package.version}`);

const archive = pathJoin(__dirname, 'output', `${package.name}-${package.version}.tgz`);

execSync(`npm publish ${archive} --access public`, { stdio: 'inherit' });
}

0 comments on commit 637b937

Please sign in to comment.