Skip to content

Commit

Permalink
feat: add github action to publish workflow ui files (#1027)
Browse files Browse the repository at this point in the history
* feat: add github action to publish workflow ui files

* feat: change entirely how it works

* feat: change entirely how it works

* chore: fix script

* chore: fix path

* fix: remove quotes form package

* fix: lets go

* chore: fix body

* feat: support workflow in tests
  • Loading branch information
estephinson authored Nov 18, 2022
1 parent 6799f0d commit 9eea77d
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/publish-workflow-ui.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
34 changes: 34 additions & 0 deletions bin/publish_workflow_json.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 9 additions & 3 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 9eea77d

Please sign in to comment.