Skip to content

Commit

Permalink
simplyfing workflow logic
Browse files Browse the repository at this point in the history
Signed-off-by: Ankita Sahu <[email protected]>
  • Loading branch information
SAHU-01 committed Oct 27, 2024
1 parent 6a38b10 commit 31e0f82
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 132 deletions.
109 changes: 48 additions & 61 deletions .github/workflows/feature-list.yml
Original file line number Diff line number Diff line change
@@ -1,89 +1,76 @@
name: Feature List
name: Feature List Update

on:
workflow_dispatch:
inputs:
spreadsheet_uri:
description: 'Link of the spreadsheet containing subscription details.'
type: string
required: true
schedule:
- cron: '0 0 * * *' # Run every night at midnight UTC
workflow_dispatch:

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

steps:
- name: Trigger Feature List workflow and wait for completion
- name: Checkout current repository
uses: actions/checkout@v4

- name: Check for updates in source repository
id: check-updates
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_ACCESS_TOKEN}}
script: |
const result = await github.rest.actions.createWorkflowDispatch({
const { data: sourceFile } = await github.rest.repos.getContent({
owner: 'layer5labs',
repo: 'meshery-extensions-packages',
workflow_id: 'generate-feature-list.yml',
ref: 'master',
inputs: {
spreadsheet_uri: '${{ secrets.INPUT_SPREADSHEET_URI }}'
}
path: 'feature-data.json',
ref: 'master'
});
// Store the latest commit SHA
const latestSHA = sourceFile.sha;
// Try to get the previously stored SHA from cache
const cache = await github.rest.actions.getActionsCacheList({
owner: context.repo.owner,
repo: context.repo.repo,
});
console.log("Triggered workflow, waiting for completion...");
let hasUpdates = true;
if (cache.data.actions_caches.length > 0) {
const lastSHA = cache.data.actions_caches[0].key.split('-').pop();
hasUpdates = lastSHA !== latestSHA;
}
while (true) {
const runs = await github.rest.actions.listWorkflowRuns({
owner: 'layer5labs',
repo: 'meshery-extensions-packages',
workflow_id: 'generate-feature-list.yml'
if (hasUpdates) {
// Update the cache with new SHA
await github.rest.actions.createActionsCacheEntry({
owner: context.repo.owner,
repo: context.repo.repo,
key: `feature-data-sha-${latestSHA}`,
ref: context.ref,
cache_data: latestSHA
});
if (runs.data.workflow_runs[0].status === 'completed') {
console.log("Workflow completed");
break;
}
// Decode and save the content
const content = Buffer.from(sourceFile.content, 'base64').toString('utf-8');
const fs = require('fs');
// Create data directory if it doesn't exist
fs.mkdirSync('data', { recursive: true });
console.log("Waiting for workflow to complete...");
await new Promise(resolve => setTimeout(resolve, 30000));
// Write the new content
fs.writeFileSync('${{ env.FEATURES_FILE }}', content);
}
- 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
return hasUpdates;
- name: Commit changes
if: steps.check-updates.outputs.result == 'true'
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Updated feature data
commit_message: "Updated feature data from source repository"
file_pattern: ${{ env.FEATURES_FILE }}
branch: master
commit_options: "--signoff"
Expand Down
71 changes: 0 additions & 71 deletions .github/workflows/new-feature-check.yml

This file was deleted.

0 comments on commit 31e0f82

Please sign in to comment.