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

[UI] Dynamically adding front-matter to documentation pages #379

Merged
merged 17 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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
92 changes: 92 additions & 0 deletions .github/workflows/feature-list.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Feature List

on:
workflow_dispatch:
inputs:
spreadsheet_uri:
description: 'Link of the spreadsheet containing subscription details.'
type: string
required: true

jobs:
update-feature-data:
runs-on: ubuntu-latest
env:
FEATURES_FILE: 'data/features.json'

steps:
- name: Trigger Feature List workflow and wait for completion
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_ACCESS_TOKEN}}
script: |
const result = await github.rest.actions.createWorkflowDispatch({
owner: 'layer5labs',
repo: 'meshery-extensions-packages',
Copy link
Member

Choose a reason for hiding this comment

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

What's the purpose of running the workflow over here? @vishalvivekm @SAHU-01 @jerensl

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This workflow fetches the integration sheet and parses the csv and gives us a json file, additionally, it filters out and returns rows of the sheet in json that we need to map, i.e. if a feature on the sheet has been documented or has been marked to be displayed on pricing page.

workflow_id: 'generate-feature-list.yml',
ref: 'master',
inputs: {
spreadsheet_uri: '${{ secrets.INPUT_SPREADSHEET_URI }}'
}
});

console.log("Triggered workflow, waiting for completion...");

while (true) {
const runs = await github.rest.actions.listWorkflowRuns({
owner: 'layer5labs',
repo: 'meshery-extensions-packages',
workflow_id: 'generate-feature-list.yml'
});

if (runs.data.workflow_runs[0].status === 'completed') {
console.log("Workflow completed");
break;
}

console.log("Waiting for workflow to complete...");
await new Promise(resolve => setTimeout(resolve, 30000));
}

- name: Checkout repository
uses: actions/checkout@v4

- name: Create data directory if it doesn't exist
run: mkdir -p data

- name: Download new feature data
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_ACCESS_TOKEN}}
script: |
const fs = require('fs');
const path = require('path');

const { data } = await github.rest.repos.getContent({
owner: 'layer5labs',
repo: 'meshery-extensions-packages',
path: 'feature-data.json'
});

const newContent = Buffer.from(data.content, 'base64').toString('utf-8');
fs.writeFileSync('${{ env.FEATURES_FILE }}', newContent);

- name: Update or create features.json
run: |
if [ -f "${{ env.FEATURES_FILE }}" ]; then
echo "Updating existing features.json"
else
echo "Creating new features.json"
cp "${{ env.FEATURES_FILE }}" data/features.json
fi

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Updated feature data
file_pattern: ${{ env.FEATURES_FILE }}
branch: master
commit_options: "--signoff"
commit_user_name: l5io
commit_user_email: [email protected]
commit_author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
71 changes: 71 additions & 0 deletions .github/workflows/new-feature-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Nightly Google Sheet Check

on:
schedule:
- cron: '0 0 * * *' # Run every day at midnight UTC

jobs:
check-for-updates:
runs-on: ubuntu-latest
steps:
- name: Check for Google Sheet updates
id: sheet-check
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_ACCESS_TOKEN}}
script: |
const { GoogleSpreadsheet } = require('google-spreadsheet');

async function checkForUpdates() {
const doc = new GoogleSpreadsheet('${{ secrets.INPUT_SPREADSHEET_URI }}');
await doc.useServiceAccountAuth({
client_email: process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL,
private_key: process.env.GOOGLE_PRIVATE_KEY,
});

await doc.loadInfo();
const sheet = doc.sheetsByIndex[0];
const lastModified = sheet.lastModified;

const cache = await github.rest.actions.getActionsCacheList({
owner: context.repo.owner,
repo: context.repo.repo,
});

let lastKnownModified = null;
if (cache.data.actions_caches.length > 0) {
lastKnownModified = new Date(cache.data.actions_caches[0].last_accessed_at);
}

if (!lastKnownModified || lastModified > lastKnownModified) {
await github.rest.actions.createActionsCacheEntry({
owner: context.repo.owner,
repo: context.repo.repo,
key: 'last-modified-time',
ref: context.ref,
cache_data: lastModified.toISOString(),
});
return true;
}

return false;
}

const hasUpdates = await checkForUpdates();
core.setOutput('has-updates', hasUpdates);

- name: Trigger Subscriptions Plan workflow
if: steps.sheet-check.outputs.has-updates == 'true'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_ACCESS_TOKEN}}
script: |
github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'feature-list.yml',
ref: 'main',
inputs: {
spreadsheet_uri: '${{ secrets.INPUT_SPREADSHEET_URI }}'
}
});
2 changes: 1 addition & 1 deletion assets/scss/_styles_project.scss
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ a:not([href]):not([class]):hover {
.matterinfo {
font-weight: $font-weight-medium;
background: $black;
font-family: "Open Sans";
font-family: "Qanelas Soft";
border-style: solid;
margin: 2rem auto;
padding: 1rem;
Expand Down
60 changes: 46 additions & 14 deletions layouts/partials/feature-info.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,56 @@
{{ $features := .Site.Data.features }}

{{ if not $features }}
{{ $features = getJSON "features.json" }}
{{ $features = getJSON "features.json" }}
{{ end }}

{{ if $features }}
{{ $groupedFeatures := dict }}
{{ range $features }}
{{ $docUrl := .documentation | default "" }}
{{ $cleanDocUrl := (index (split $docUrl "#") 0) }} <!-- Remove the # fragment if it exists -->
{{ if eq $cleanDocUrl $currentPage }}
<div class="matterinfo">
<h4 class="matterheader">Who can use this feature</h4>
{{ $subscription_tier := index .entire_row "Subscription Tier" }}
<div class="plan-support all-plans {{ lower $subscription_tier }}-plan">
<img src="/images/subscription.svg" alt="Icon" class="support-icon adaptive-icon">
Supported on <span class="tier">{{ $subscription_tier }}</span> Plan
</div>
</div>
{{ break }}
{{ end }}
{{ $docUrl := .documentation | default "" }}
{{ $cleanDocUrl := (index (split $docUrl "#") 0) }}
{{ if eq $cleanDocUrl $currentPage }}
{{ $tier := index .entire_row "Subscription Tier" }}
{{ $feature := index .entire_row "Feature" }}
{{ $currentFeatures := index $groupedFeatures $tier | default "" }}
{{ $groupedFeatures = merge $groupedFeatures (dict $tier (printf "%s%s%s" $currentFeatures (cond (eq $currentFeatures
"") "" ", ") $feature)) }}
{{ end }}
{{ end }}

{{ if ne (len $groupedFeatures) 0 }}
{{ $maxTier := "" }}
{{ $maxLength := 0 }}
{{ range $tier, $features := $groupedFeatures }}
{{ $length := len (split $features ", ") }}
{{ if gt $length $maxLength }}
{{ $maxTier = $tier }}
{{ $maxLength = $length }}
{{ end }}
{{ end }}

<div class="matterinfo">
<h4 class="matterheader">Who can use this feature</h4>
<div class="plan-support all-plans {{ lower $maxTier }}-plan">
<img src="/images/subscription.svg" alt="Icon" class="support-icon adaptive-icon">
Supported on <a href="https://layer5.io/pricing" class="tier-link" target="_blank"><span class="tier">{{ $maxTier
}}</span> </a>Plan
</div>

{{ if gt (len $groupedFeatures) 1 }}
<div class="add-ons">
<strong>Add-ons:</strong>
{{ $first := true }}
{{ range $tier, $features := $groupedFeatures }}
{{ if ne $tier $maxTier }}
{{ if not $first }}, {{ end }}
{{ $first = false }}
{{ $features }} [<a href="https://layer5.io/pricing" class="tier-link" target="_blank"><span class="tier">{{ $tier
}}</span></a>]
{{ end }}
{{ end }}
</div>
{{ end }}
</div>
{{ end }}
{{ end }}
2 changes: 1 addition & 1 deletion static/images/subscription.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading