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

Feature workflow typo fixed #403

Merged
merged 5 commits into from
Oct 29, 2024
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
97 changes: 49 additions & 48 deletions .github/workflows/feature-list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

permissions:
contents: write
actions: write
actions: read

jobs:
check-and-update-features:
Expand All @@ -19,57 +19,58 @@ jobs:
- name: Checkout current repository
uses: actions/checkout@v4

- name: Restore cache
id: cache-sha
uses: actions/cache@v3
with:
path: .sha-cache
key: feature-data-sha
restore-keys: |
feature-data-sha

- name: Check for updates in source repository
id: check-updates
uses: actions/github-script@v7
with:
script: |
const { data: sourceFile } = await github.rest.repos.getContent({
owner: 'layer5labs',
repo: 'meshery-extensions-packages',
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,
});

let hasUpdates = true;
if (cache.data.actions_caches.length > 0) {
const lastSHA = cache.data.actions_caches[0].key.split('-').pop();
hasUpdates = lastSHA !== latestSHA;
}

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
});

// 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 });

// Write the new content
fs.writeFileSync('${{ env.FEATURES_FILE }}', content);

core.setOutput('has-updates', 'true');
} else {
core.setOutput('has-updates', 'false');
}
script: |
const { data: sourceFile } = await github.rest.repos.getContent({
owner: 'layer5labs',
repo: 'meshery-extensions-packages',
path: 'feature_data.json',
ref: 'master'
});

// Store the latest commit SHA
const latestSHA = sourceFile.sha;

const fs = require('fs');

// Check if we have a previous SHA
let hasUpdates = true;
const shaCachePath = '.sha-cache/latest-sha';
if (fs.existsSync(shaCachePath)) {
const lastSHA = fs.readFileSync(shaCachePath, 'utf8');
hasUpdates = lastSHA !== latestSHA;
}

if (hasUpdates) {
// Save the new SHA
fs.mkdirSync('.sha-cache', { recursive: true });
fs.writeFileSync(shaCachePath, latestSHA);

// Decode and save the content
const content = Buffer.from(sourceFile.content, 'base64').toString('utf8');

// Create data directory if it doesn't exist
fs.mkdirSync('data', { recursive: true });

// Write the new content
fs.writeFileSync(process.env.FEATURES_FILE, content);

core.setOutput('has-updates', 'true');
} else {
core.setOutput('has-updates', 'false');
}

- name: Commit changes
if: steps.check-updates.outputs.has-updates == 'true'
Expand Down
Loading