From 46d2ab142e2c5f344cbae75f0121417cf5df07cf Mon Sep 17 00:00:00 2001 From: Sean Roberts Date: Fri, 17 May 2024 08:14:21 -0400 Subject: [PATCH] fix(wfui cleanup): cleanup workflow-ui workflows --- .github/workflows/publish-workflow-ui.yml | 40 ------ bin/combined_workflow_files.ts | 78 ---------- bin/publish_workflow_ui.sh | 55 -------- netlify.toml | 15 -- site/feature-pilot/site-settings.js | 10 -- site/feature-pilot/workflow-ui.json | 130 ----------------- .../site-settings/feature-pilot/index.json | 131 ----------------- site/surfaces/site-settings/index.json | 133 ------------------ test/main.js | 8 +- 9 files changed, 1 insertion(+), 599 deletions(-) delete mode 100644 .github/workflows/publish-workflow-ui.yml delete mode 100644 bin/combined_workflow_files.ts delete mode 100755 bin/publish_workflow_ui.sh delete mode 100644 site/feature-pilot/site-settings.js delete mode 100644 site/feature-pilot/workflow-ui.json delete mode 100644 site/surfaces/site-settings/feature-pilot/index.json delete mode 100644 site/surfaces/site-settings/index.json diff --git a/.github/workflows/publish-workflow-ui.yml b/.github/workflows/publish-workflow-ui.yml deleted file mode 100644 index fc4778167..000000000 --- a/.github/workflows/publish-workflow-ui.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Publish Workflow UI -on: - workflow_dispatch: - push: - branches: - - main - paths: - - site/plugins.json - pull_request: - types: [opened, synchronize, reopened] - branches-ignore: - - 'publish_workflow_ui_**' -jobs: - sync-to-repo: - runs-on: ubuntu-latest - steps: - - name: Git checkout - uses: actions/checkout@v3 - - name: Using Node.js - uses: actions/setup-node@v3 - with: - node-version: '*' - cache: 'npm' - check-latest: true - - name: Install dependencies - run: npm install - - name: Setup git config - run: | - git config user.name 'token-generator-app[bot]' - git config user.email '82042599+token-generator-app[bot]@users.noreply.github.com' - - name: Generate GitHub token - uses: navikt/github-app-token-generator@v1.2.1 - id: get-token - with: - private-key: ${{ secrets.TOKENS_PRIVATE_KEY }} - app-id: ${{ secrets.TOKENS_APP_ID }} - - name: Upload Workflow UI files - env: - GITHUB_TOKEN: ${{ steps.get-token.outputs.token }} - run: bin/publish_workflow_ui.sh diff --git a/bin/combined_workflow_files.ts b/bin/combined_workflow_files.ts deleted file mode 100644 index 0735131f8..000000000 --- a/bin/combined_workflow_files.ts +++ /dev/null @@ -1,78 +0,0 @@ - -/* eslint-disable n/no-sync */ -import fs from 'fs' -import path from 'path' - -interface Surface { - surfaceName: string - surfaceScripts: string[] - basePath: string -} - -interface Workflow { - package: string - packageId?: string - surfaces: Surface[] -} - -const getFiles = async function* (dir: string): AsyncGenerator { - const dirents = await fs.promises.readdir(dir, { withFileTypes: true }); - for (const dirent of dirents) { - const res = path.resolve(dir, dirent.name); - if (dirent.isDirectory()) { - yield* getFiles(res); - } else { - yield res; - } - } -} - -// read all workflow-ui.json files from `site/**/workflow-ui.json` -const workflowFiles = []; -for await (const file of getFiles('site')) { - const normalizedFileName = file?.toLowerCase() || ''; - if (normalizedFileName.endsWith('/workflow-ui.json')){ - workflowFiles.push(file); - } -} - -const workflows = workflowFiles.map((file) => { - const content = fs.readFileSync(file) - return JSON.parse(content.toString()) as Workflow -}) - - -console.log(`processing ${workflows.length} workflows - ${workflows.map((workflow) => workflow.package).join(', ')}`) - -const surfaces = workflows.reduce>((acc, workflow) => { - const newAcc = { ...acc } - workflow.surfaces.forEach((surface) => { - const filteredWorkflow = { - ...workflow, - surfaces: workflow.surfaces.filter(({ surfaceName }) => surfaceName === surface.surfaceName), - } - - newAcc[surface.surfaceName] = [...(acc[surface.surfaceName] ?? []), filteredWorkflow] - }) - - return newAcc -}, {}) - -Object.entries(surfaces).forEach(([surfaceName, surfaceWorkflows]) => { - const surfaceRoot = `site/surfaces/${surfaceName}` - if (!fs.existsSync(surfaceRoot)) { - fs.mkdirSync(surfaceRoot, { recursive: true }) - } - - fs.writeFileSync(`${surfaceRoot}/index.json`, JSON.stringify(surfaceWorkflows, null, 2)) - - surfaceWorkflows.forEach((surfaceWorkflow) => { - const normalizedPackage = (surfaceWorkflow.packageId || surfaceWorkflow.package).toLowerCase() - - const surfacePackageRoot = `${surfaceRoot}/${normalizedPackage}` - if (!fs.existsSync(surfacePackageRoot)) { - fs.mkdirSync(surfacePackageRoot, { recursive: true }) - } - fs.writeFileSync(`${surfacePackageRoot}/index.json`, JSON.stringify(surfaceWorkflow, null, 2)) - }) -}) diff --git a/bin/publish_workflow_ui.sh b/bin/publish_workflow_ui.sh deleted file mode 100755 index a94ca2b6b..000000000 --- a/bin/publish_workflow_ui.sh +++ /dev/null @@ -1,55 +0,0 @@ -PR_TITLE="chore: publish workflow-ui files" -BRANCH_NAME="publish_workflow_ui_$(date +%s)" - -git switch -c $BRANCH_NAME - -# install jq -sudo apt-get install jq - -# Loop through each package, install from npm and copy the workflow-ui.json from root of the package if it exists -cat site/plugins.json | jq ".[] | select(.workflow == true) | .package" | while read PACKAGE -do - PACKAGE=$(echo $PACKAGE | tr -d '"') - echo "Downloading workflow-ui for $PACKAGE" - npm pack $PACKAGE - tar -xzf *.tgz - - if [ -f package/workflow-ui.json ]; then - echo "Copying workflow-ui.json for $PACKAGE" - - PACKAGE_ID=$(cat package/workflow-ui.json | jq -r ".packageId // .package") - DEST="site/$PACKAGE_ID" - - mkdir -p $DEST - cp package/workflow-ui.json $DEST/workflow-ui.json - - cat $DEST/workflow-ui.json | jq ".surfaces | .[] | .surfaceScripts | .[]?" | while read SCRIPT - do - # strip quotes and leading ./ from script path - SCRIPT=$(echo $SCRIPT | tr -d '"' | sed 's/^\.\///') - echo "Copying $SCRIPT for $PACKAGE" - cp package/$SCRIPT $DEST/$SCRIPT - done - - ls $DEST - fi - - - rm -rf ./package -done - -npx tsx bin/combined_workflow_files.ts - -# Add all files to git in the site directory -git add site - -# See if we have any changes. We should. We should only push on main branch -if [[ -n "$(git status --porcelain)" && "$GITHUB_REF_NAME" == "main" ]]; then - echo "Creating PR \"$PR_TITLE\" for branch $BRANCH_NAME" - git commit -m "$PR_TITLE" - git push origin $BRANCH_NAME - gh pr create --title "$PR_TITLE" --body "This is an automated PR to publish workflow-ui" --label "workflow_ui" --label "automerge" -else - # Shouldn't end up here, but log that there was nothing to sync - echo "Skipping PR." -fi diff --git a/netlify.toml b/netlify.toml index 4c4a773d7..392a8cbc6 100644 --- a/netlify.toml +++ b/netlify.toml @@ -6,18 +6,3 @@ for = "/plugins.json" [headers.values] Access-Control-Allow-Origin = "*" - -[[redirects]] - from = "/workflow-ui/surfaces/:surface/" - to = "/surfaces/:surface/index.json" - status = 200 - -[[redirects]] - from = "/workflow-ui/surfaces/:surface/*" - to = "/surfaces/:surface/:splat/index.json" - status = 200 - -[[redirects]] - from = "/workflow-ui/package/:package/*" - to = "/:package/:splat" - status = 200 \ No newline at end of file diff --git a/site/feature-pilot/site-settings.js b/site/feature-pilot/site-settings.js deleted file mode 100644 index d4ae64a21..000000000 --- a/site/feature-pilot/site-settings.js +++ /dev/null @@ -1,10 +0,0 @@ -console.log('surface script is running') - -/* eslint-disable no-console, no-undef */ -netlifyContext.on('WFUI_SAVE', async (uiState) => { - console.log('save called') -}); - -netlifyContext.on('WFUI_LOAD', async (uiState) => { - console.log('load called') -}); diff --git a/site/feature-pilot/workflow-ui.json b/site/feature-pilot/workflow-ui.json deleted file mode 100644 index 195df08fd..000000000 --- a/site/feature-pilot/workflow-ui.json +++ /dev/null @@ -1,130 +0,0 @@ -{ - "package": "@netlify/feature-package-pilot", - "packageId": "feature-pilot", - "packageName": "", - "friendlyName": "WorkflowUI Pilot", - "surfaces": [ - { - "surfaceName": "site-settings", - "surfaceScripts": ["site-settings.js"], - "routes": { - "/": [ - { - "type": "section", - "title": "Overview", - "description": "General information about your emails integration", - "display": "hidden", - "if": { - "truthy": "$PKG.enabled", - "then": { - "display": "visible" - } - }, - "contents": [ - { - "type": "form", - "title": "Email Integration configuration", - "contents": [ - { - "type": "select", - "label": "Emails provider", - "id": "NETLIFY_EMAILS_PROVIDER", - "required": true, - "value": [ - { - "label": "Postmark", - "value": "postmark" - }, - { - "label": "SendGrid", - "value": "sendgrid" - }, - { - "label": "Mailgun", - "value": "mailgun" - } - ] - }, - { - "type": "input-password", - "label": "Emails provider API key", - "id": "NETLIFY_EMAILS_PROVIDER_API_KEY", - "required": true - }, - { - "type": "input-text", - "label": "Mailgun domain", - "id": "NETLIFY_EMAILS_MAILGUN_DOMAIN", - "required": false, - "display": "hidden", - "if": { - "equals": [ - "$EL.NETLIFY_EMAILS_PROVIDER", - "mailgun" - ], - "then": { - "display": "visible", - "required": true - } - } - }, - { - "type": "select", - "label": "Mailgun host region", - "id": "NETLIFY_EMAILS_MAILGUN_HOST_REGION", - "required": false, - "value": [ - { - "label": "US", - "value": "US" - }, - { - "label": "EU", - "value": "EU" - } - ], - "display": "hidden", - "if": { - "equals": [ - "$EL.NETLIFY_EMAILS_PROVIDER", - "mailgun" - ], - "then": { - "display": "visible", - "required": true - } - } - }, - { - "type": "input-text", - "label": "Emails directory", - "id": "NETLIFY_EMAILS_DIRECTORY", - "required": true, - "value": "./emails" - }, - { - "type": "text", - "value": "" - } - ] - } - ] - - }, - { - "type": "enablement", - "title": "Pilot", - "description": "Manage sending emails and editing templates - all without rolling your own email service\\n\\nWithin a few clicks, enable emails on your web application by choosing your preferred email provider and configuring your settings.\\n\\n", - "illustration": "/6625c10d771150915a28.svg", - "if": { - "truthy": "$PKG.enabled", - "then": { - "description": "Disabling emails will stop emails handlers from working on any subsequent deployments. All configuration values will be lost." - } - } - } - ] - } - } - ] -} \ No newline at end of file diff --git a/site/surfaces/site-settings/feature-pilot/index.json b/site/surfaces/site-settings/feature-pilot/index.json deleted file mode 100644 index a57c7c60a..000000000 --- a/site/surfaces/site-settings/feature-pilot/index.json +++ /dev/null @@ -1,131 +0,0 @@ -{ - "package": "@netlify/feature-package-pilot", - "packageId": "feature-pilot", - "packageName": "", - "friendlyName": "WorkflowUI Pilot", - "surfaces": [ - { - "surfaceName": "site-settings", - "surfaceScripts": [ - "site-settings.js" - ], - "routes": { - "/": [ - { - "type": "section", - "title": "Overview", - "description": "General information about your emails integration", - "display": "hidden", - "if": { - "truthy": "$PKG.enabled", - "then": { - "display": "visible" - } - }, - "contents": [ - { - "type": "form", - "title": "Email Integration configuration", - "contents": [ - { - "type": "select", - "label": "Emails provider", - "id": "NETLIFY_EMAILS_PROVIDER", - "required": true, - "value": [ - { - "label": "Postmark", - "value": "postmark" - }, - { - "label": "SendGrid", - "value": "sendgrid" - }, - { - "label": "Mailgun", - "value": "mailgun" - } - ] - }, - { - "type": "input-password", - "label": "Emails provider API key", - "id": "NETLIFY_EMAILS_PROVIDER_API_KEY", - "required": true - }, - { - "type": "input-text", - "label": "Mailgun domain", - "id": "NETLIFY_EMAILS_MAILGUN_DOMAIN", - "required": false, - "display": "hidden", - "if": { - "equals": [ - "$EL.NETLIFY_EMAILS_PROVIDER", - "mailgun" - ], - "then": { - "display": "visible", - "required": true - } - } - }, - { - "type": "select", - "label": "Mailgun host region", - "id": "NETLIFY_EMAILS_MAILGUN_HOST_REGION", - "required": false, - "value": [ - { - "label": "US", - "value": "US" - }, - { - "label": "EU", - "value": "EU" - } - ], - "display": "hidden", - "if": { - "equals": [ - "$EL.NETLIFY_EMAILS_PROVIDER", - "mailgun" - ], - "then": { - "display": "visible", - "required": true - } - } - }, - { - "type": "input-text", - "label": "Emails directory", - "id": "NETLIFY_EMAILS_DIRECTORY", - "required": true, - "value": "./emails" - }, - { - "type": "text", - "value": "" - } - ] - } - ] - }, - { - "type": "enablement", - "title": "Pilot", - "description": "Manage sending emails and editing templates - all without rolling your own email service\\n\\nWithin a few clicks, enable emails on your web application by choosing your preferred email provider and configuring your settings.\\n\\n", - "illustration": "/6625c10d771150915a28.svg", - "if": { - "truthy": "$PKG.enabled", - "then": { - "description": "Disabling emails will stop emails handlers from working on any subsequent deployments. All configuration values will be lost." - } - } - } - ] - } - } - ] -} \ No newline at end of file diff --git a/site/surfaces/site-settings/index.json b/site/surfaces/site-settings/index.json deleted file mode 100644 index 5c70e9818..000000000 --- a/site/surfaces/site-settings/index.json +++ /dev/null @@ -1,133 +0,0 @@ -[ - { - "package": "@netlify/feature-package-pilot", - "packageId": "feature-pilot", - "packageName": "", - "friendlyName": "WorkflowUI Pilot", - "surfaces": [ - { - "surfaceName": "site-settings", - "surfaceScripts": [ - "site-settings.js" - ], - "routes": { - "/": [ - { - "type": "section", - "title": "Overview", - "description": "General information about your emails integration", - "display": "hidden", - "if": { - "truthy": "$PKG.enabled", - "then": { - "display": "visible" - } - }, - "contents": [ - { - "type": "form", - "title": "Email Integration configuration", - "contents": [ - { - "type": "select", - "label": "Emails provider", - "id": "NETLIFY_EMAILS_PROVIDER", - "required": true, - "value": [ - { - "label": "Postmark", - "value": "postmark" - }, - { - "label": "SendGrid", - "value": "sendgrid" - }, - { - "label": "Mailgun", - "value": "mailgun" - } - ] - }, - { - "type": "input-password", - "label": "Emails provider API key", - "id": "NETLIFY_EMAILS_PROVIDER_API_KEY", - "required": true - }, - { - "type": "input-text", - "label": "Mailgun domain", - "id": "NETLIFY_EMAILS_MAILGUN_DOMAIN", - "required": false, - "display": "hidden", - "if": { - "equals": [ - "$EL.NETLIFY_EMAILS_PROVIDER", - "mailgun" - ], - "then": { - "display": "visible", - "required": true - } - } - }, - { - "type": "select", - "label": "Mailgun host region", - "id": "NETLIFY_EMAILS_MAILGUN_HOST_REGION", - "required": false, - "value": [ - { - "label": "US", - "value": "US" - }, - { - "label": "EU", - "value": "EU" - } - ], - "display": "hidden", - "if": { - "equals": [ - "$EL.NETLIFY_EMAILS_PROVIDER", - "mailgun" - ], - "then": { - "display": "visible", - "required": true - } - } - }, - { - "type": "input-text", - "label": "Emails directory", - "id": "NETLIFY_EMAILS_DIRECTORY", - "required": true, - "value": "./emails" - }, - { - "type": "text", - "value": "" - } - ] - } - ] - }, - { - "type": "enablement", - "title": "Pilot", - "description": "Manage sending emails and editing templates - all without rolling your own email service\\n\\nWithin a few clicks, enable emails on your web application by choosing your preferred email provider and configuring your settings.\\n\\n", - "illustration": "/6625c10d771150915a28.svg", - "if": { - "truthy": "$PKG.enabled", - "then": { - "description": "Disabling emails will stop emails handlers from working on any subsequent deployments. All configuration values will be lost." - } - } - } - ] - } - } - ] - } -] \ No newline at end of file diff --git a/test/main.js b/test/main.js index 715ef6968..22431ae76 100644 --- a/test/main.js +++ b/test/main.js @@ -59,7 +59,7 @@ const getMajorVersion = function (version) { /* eslint-disable max-nested-callbacks */ // eslint-disable-next-line max-lines-per-function, max-statements pluginsList.forEach((plugin) => { - const { package: packageName, repo, version, name, compatibility, variables, workflow, status } = plugin + const { package: packageName, repo, version, name, compatibility, variables, status } = plugin Object.entries(plugin).forEach(([attribute, value]) => { test(`Plugin attribute "${attribute}" should have a proper shape: ${packageName}`, (t) => { @@ -110,12 +110,6 @@ pluginsList.forEach((plugin) => { }) } - if (workflow !== undefined) { - test(`Plugin Workflow should be a boolean`, (t) => { - t.true(typeof workflow === 'boolean') - }) - } - if (compatibility === undefined) { return }