Skip to content

Commit

Permalink
workflow sha issue fix
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 29, 2024
1 parent a68de89 commit 64d6540
Showing 1 changed file with 43 additions and 42 deletions.
85 changes: 43 additions & 42 deletions .github/workflows/feature-list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,48 +28,49 @@ jobs:
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;
const fs = require('fs');
// Check if we have a previous SHA
let hasUpdates = true;
if (fs.existsSync('.sha-cache')) {
const lastSHA = fs.readFileSync('.sha-cache', 'utf8');
hasUpdates = lastSHA !== latestSHA;
}
if (hasUpdates) {
// Save the new SHA
fs.mkdirSync('.sha-cache', { recursive: true });
fs.writeFileSync('.sha-cache', 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: 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;
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

0 comments on commit 64d6540

Please sign in to comment.