From e64796f7d11e4a19f487fac735e2021505f13404 Mon Sep 17 00:00:00 2001 From: Ed Stephinson Date: Thu, 17 Nov 2022 14:31:38 +0000 Subject: [PATCH 1/9] feat: add github action to publish workflow ui files --- .github/workflows/publish-workflow-ui.yml | 33 +++++++++++++++++++++++ bin/publish_workflow_json.sh | 25 +++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 .github/workflows/publish-workflow-ui.yml create mode 100644 bin/publish_workflow_json.sh diff --git a/.github/workflows/publish-workflow-ui.yml b/.github/workflows/publish-workflow-ui.yml new file mode 100644 index 000000000..01cf9a1cc --- /dev/null +++ b/.github/workflows/publish-workflow-ui.yml @@ -0,0 +1,33 @@ +name: Publish Workflow UI +on: + repository_dispatch: + # sync_cms_to_repo is a bespoke type created for use with the CMS Webhook + types: [sync_cms_to_repo] +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.1.1 + id: get-token + with: + private-key: ${{ secrets.TOKENS_PRIVATE_KEY }} + app-id: ${{ secrets.TOKENS_APP_ID }} + - name: Sync CMS to repo + env: + GITHUB_TOKEN: ${{ steps.get-token.outputs.token }} + run: bin/publish_workflow_ui.sh ${{ github.event.client_payload.package }} diff --git a/bin/publish_workflow_json.sh b/bin/publish_workflow_json.sh new file mode 100644 index 000000000..413a7f2de --- /dev/null +++ b/bin/publish_workflow_json.sh @@ -0,0 +1,25 @@ +PLUGIN=$1 +PR_TITLE="chore: publish workflow-ui for $PLUGIN" +BRANCH_NAME="publish_workflow_ui_$(date +%s)" + +git switch -c $BRANCH_NAME + +# Get the latest version of the plugin +npm install $PLUGIN + +# Copy the workflow-ui.json from the root of the installed plugin directory +cp node_modules/$PLUGIN/workflow-ui.json site/$PLUGIN/workflow-ui.json + +# This is the only file we want to commit +git add site/$PLUGIN/workflow-ui.json + +# See if we have any changes. We should. +if [[ -n "$(git status --porcelain)" ]]; 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 for $PLUGIN" --label "workflow_ui" --label "automerge" +else + # Shouldn't end up here, but log that there was nothing to sync + echo "Looks like there was nothing to sync." +fi From 186a4a51df598a2e2608d0e090dff823766a7555 Mon Sep 17 00:00:00 2001 From: Ed Stephinson Date: Thu, 17 Nov 2022 15:04:00 +0000 Subject: [PATCH 2/9] feat: change entirely how it works --- .github/workflows/publish-workflow-ui.yml | 12 +++++++----- bin/publish_workflow_json.sh | 22 ++++++++++++++++------ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/.github/workflows/publish-workflow-ui.yml b/.github/workflows/publish-workflow-ui.yml index 01cf9a1cc..70a38eb58 100644 --- a/.github/workflows/publish-workflow-ui.yml +++ b/.github/workflows/publish-workflow-ui.yml @@ -1,8 +1,10 @@ name: Publish Workflow UI on: - repository_dispatch: - # sync_cms_to_repo is a bespoke type created for use with the CMS Webhook - types: [sync_cms_to_repo] + push: + branches: + - "main" + paths: + - "site/plugins.json" jobs: sync-to-repo: runs-on: ubuntu-latest @@ -27,7 +29,7 @@ jobs: with: private-key: ${{ secrets.TOKENS_PRIVATE_KEY }} app-id: ${{ secrets.TOKENS_APP_ID }} - - name: Sync CMS to repo + - name: Upload Workflow UI files env: GITHUB_TOKEN: ${{ steps.get-token.outputs.token }} - run: bin/publish_workflow_ui.sh ${{ github.event.client_payload.package }} + run: bin/publish_workflow_ui.sh diff --git a/bin/publish_workflow_json.sh b/bin/publish_workflow_json.sh index 413a7f2de..024876b70 100644 --- a/bin/publish_workflow_json.sh +++ b/bin/publish_workflow_json.sh @@ -4,14 +4,24 @@ BRANCH_NAME="publish_workflow_ui_$(date +%s)" git switch -c $BRANCH_NAME -# Get the latest version of the plugin -npm install $PLUGIN +# install jq +sudo apt-get install jq -# Copy the workflow-ui.json from the root of the installed plugin directory -cp node_modules/$PLUGIN/workflow-ui.json site/$PLUGIN/workflow-ui.json +PACKAGES=cat site/plugins.json | jq ".[].package" -# This is the only file we want to commit -git add site/$PLUGIN/workflow-ui.json +# Loop through each package, install from npm and copy the workflow-ui.json from root of the package if it exists +for PACKAGE in $PACKAGES +do + echo "Installing $PACKAGE" + npm install $PACKAGE + if [ -f "node_modules/$PACKAGE/workflow-ui.json" ]; then + echo "Copying workflow-ui.json from $PACKAGE" + cp node_modules/$PACKAGE/workflow-ui.json site/workflow-ui/$PACKAGE.json + fi +done + +# Add all files to git in the site directory +git add site # See if we have any changes. We should. if [[ -n "$(git status --porcelain)" ]]; then From c40ddb65b8456e9f85691f7bd81fdc2788f9748e Mon Sep 17 00:00:00 2001 From: Ed Stephinson Date: Thu, 17 Nov 2022 15:05:02 +0000 Subject: [PATCH 3/9] feat: change entirely how it works --- .github/workflows/publish-workflow-ui.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-workflow-ui.yml b/.github/workflows/publish-workflow-ui.yml index 70a38eb58..d0e1c63ab 100644 --- a/.github/workflows/publish-workflow-ui.yml +++ b/.github/workflows/publish-workflow-ui.yml @@ -2,9 +2,9 @@ name: Publish Workflow UI on: push: branches: - - "main" + - main paths: - - "site/plugins.json" + - site/plugins.json jobs: sync-to-repo: runs-on: ubuntu-latest From a3af82b8c9808bbf230d819466d237c48a773cbd Mon Sep 17 00:00:00 2001 From: Ed Stephinson Date: Thu, 17 Nov 2022 15:11:51 +0000 Subject: [PATCH 4/9] chore: fix script --- bin/publish_workflow_json.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/bin/publish_workflow_json.sh b/bin/publish_workflow_json.sh index 024876b70..37f0c31f9 100644 --- a/bin/publish_workflow_json.sh +++ b/bin/publish_workflow_json.sh @@ -1,5 +1,4 @@ -PLUGIN=$1 -PR_TITLE="chore: publish workflow-ui for $PLUGIN" +PR_TITLE="chore: publish workflow-ui files" BRANCH_NAME="publish_workflow_ui_$(date +%s)" git switch -c $BRANCH_NAME @@ -7,10 +6,8 @@ git switch -c $BRANCH_NAME # install jq sudo apt-get install jq -PACKAGES=cat site/plugins.json | jq ".[].package" - # Loop through each package, install from npm and copy the workflow-ui.json from root of the package if it exists -for PACKAGE in $PACKAGES +cat site/plugins.json | jq ".[].package" | while read PACKAGE do echo "Installing $PACKAGE" npm install $PACKAGE From e9f1268ae4db11c29046f81761186f0ad65704d0 Mon Sep 17 00:00:00 2001 From: Ed Stephinson Date: Thu, 17 Nov 2022 15:13:13 +0000 Subject: [PATCH 5/9] chore: fix path --- bin/publish_workflow_json.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/publish_workflow_json.sh b/bin/publish_workflow_json.sh index 37f0c31f9..5a152b0b4 100644 --- a/bin/publish_workflow_json.sh +++ b/bin/publish_workflow_json.sh @@ -13,7 +13,7 @@ do npm install $PACKAGE if [ -f "node_modules/$PACKAGE/workflow-ui.json" ]; then echo "Copying workflow-ui.json from $PACKAGE" - cp node_modules/$PACKAGE/workflow-ui.json site/workflow-ui/$PACKAGE.json + cp node_modules/$PACKAGE/workflow-ui.json site/$PACKAGE/workflow-ui.json fi done From 4c4004067ac83e70d83caf3c8a0e4adc05eaacc8 Mon Sep 17 00:00:00 2001 From: Ed Stephinson Date: Thu, 17 Nov 2022 15:14:51 +0000 Subject: [PATCH 6/9] fix: remove quotes form package --- bin/publish_workflow_json.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/publish_workflow_json.sh b/bin/publish_workflow_json.sh index 5a152b0b4..fc99017ad 100644 --- a/bin/publish_workflow_json.sh +++ b/bin/publish_workflow_json.sh @@ -10,6 +10,8 @@ sudo apt-get install jq cat site/plugins.json | jq ".[].package" | while read PACKAGE do echo "Installing $PACKAGE" + # remove the quotes from the package name + PACKAGE=$(echo $PACKAGE | tr -d '"') npm install $PACKAGE if [ -f "node_modules/$PACKAGE/workflow-ui.json" ]; then echo "Copying workflow-ui.json from $PACKAGE" From ae91314363951bc82069bf59c6ea430f2bf289d1 Mon Sep 17 00:00:00 2001 From: Ed Stephinson Date: Thu, 17 Nov 2022 15:16:51 +0000 Subject: [PATCH 7/9] fix: lets go --- bin/publish_workflow_json.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/publish_workflow_json.sh b/bin/publish_workflow_json.sh index fc99017ad..2eaf160bc 100644 --- a/bin/publish_workflow_json.sh +++ b/bin/publish_workflow_json.sh @@ -7,7 +7,7 @@ git switch -c $BRANCH_NAME 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 ".[].package" | while read PACKAGE +cat site/plugins.json | jq ".[] | select(.workflow == true) | .package" | while read PACKAGE do echo "Installing $PACKAGE" # remove the quotes from the package name From 8ec1e34a65284ba4643194b3477dda45166c4d34 Mon Sep 17 00:00:00 2001 From: Ed Stephinson Date: Thu, 17 Nov 2022 15:20:00 +0000 Subject: [PATCH 8/9] chore: fix body --- bin/publish_workflow_json.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/publish_workflow_json.sh b/bin/publish_workflow_json.sh index 2eaf160bc..f9ab90a4e 100644 --- a/bin/publish_workflow_json.sh +++ b/bin/publish_workflow_json.sh @@ -27,7 +27,7 @@ if [[ -n "$(git status --porcelain)" ]]; 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 for $PLUGIN" --label "workflow_ui" --label "automerge" + 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 "Looks like there was nothing to sync." From 3b0ebbbac71e0341bd00fc6f719e394785d31c86 Mon Sep 17 00:00:00 2001 From: Ed Stephinson Date: Thu, 17 Nov 2022 15:31:05 +0000 Subject: [PATCH 9/9] feat: support workflow in tests --- test/main.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/main.js b/test/main.js index bf0a1c59a..eda314225 100644 --- a/test/main.js +++ b/test/main.js @@ -13,8 +13,8 @@ const { manifest } = pacote const { valid: validVersion, validRange, lt: ltVersion, major, minor, patch, minVersion } = semver const STRING_ATTRIBUTES = ['author', 'description', 'name', 'package', 'repo', 'status', 'version'] -const OPTIONAL_ATTRIBUTES = new Set(['status', 'compatibility', 'variables']) -const ATTRIBUTES = new Set([...STRING_ATTRIBUTES, 'compatibility', 'variables']) +const OPTIONAL_ATTRIBUTES = new Set(['status', 'compatibility', 'variables', 'workflow']) +const ATTRIBUTES = new Set([...STRING_ATTRIBUTES, 'compatibility', 'variables', 'workflow']) const ENUMS = { status: ['DEACTIVATED', undefined], } @@ -58,7 +58,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 } = plugin + const { package: packageName, repo, version, name, compatibility, variables, workflow } = plugin Object.entries(plugin).forEach(([attribute, value]) => { test(`Plugin attribute "${attribute}" should have a proper shape: ${packageName}`, (t) => { @@ -107,6 +107,12 @@ pluginsList.forEach((plugin) => { }) } + if (workflow !== undefined) { + test(`Plugin Workflow should be a boolean`, (t) => { + t.true(typeof workflow === 'boolean') + }) + } + if (compatibility === undefined) { return }