Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add github action to publish workflow ui files #1027

Merged
merged 9 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to install the package vs pulling the file directly from NPM?

We only need raw files, not to pull dependencies and such

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, will use https://unpkg.com

Copy link
Contributor

@sean-roberts sean-roberts Nov 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example being

npm pack $PACKAGE
tar -xf *.tgz

now a package directory will be there with the file contents

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppose we'll need the whole package for the dynamic scripts and such

This is what I was using currently but I'll use npm pack instead

curl -s https://unpkg.com/$PACKAGE@latest/workflow-ui.json -o site/$PACKAGE/workflow-ui.json || true

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking but

if you change this to site/workflow-ui/package/$PACKAGE/workflow-ui.json it would already accomplish the package endpoint

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