diff --git a/.github/workflows/publish-workflow-ui.yml b/.github/workflows/publish-workflow-ui.yml new file mode 100644 index 000000000..d0e1c63ab --- /dev/null +++ b/.github/workflows/publish-workflow-ui.yml @@ -0,0 +1,35 @@ +name: Publish Workflow UI +on: + push: + branches: + - main + paths: + - site/plugins.json +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: Upload Workflow UI files + env: + GITHUB_TOKEN: ${{ steps.get-token.outputs.token }} + run: bin/publish_workflow_ui.sh diff --git a/bin/publish_workflow_json.sh b/bin/publish_workflow_json.sh new file mode 100644 index 000000000..f9ab90a4e --- /dev/null +++ b/bin/publish_workflow_json.sh @@ -0,0 +1,34 @@ +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 + 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" + cp node_modules/$PACKAGE/workflow-ui.json site/$PACKAGE/workflow-ui.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 + 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 "Looks like there was nothing to sync." +fi 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 }