Skip to content

Commit

Permalink
fix(action): refactor manifest update to use async/await
Browse files Browse the repository at this point in the history
Refactored `updateManifest` function to make it asynchronous.
  • Loading branch information
gentlementlegen committed Oct 15, 2024
1 parent 8e99285 commit 90e7386
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ runs:
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const fs = require('fs').promises;
const path = require('path');
function updateManifest() {
async function updateManifest() {
const manifestPath = '${{ inputs.manifestPath }}';
const pluginPath = path.resolve('${{ github.workspace }}', 'plugin', 'index.js');
let pluginSettingsSchema;
try {
// Use require to load the compiled output
const pluginModule = require(pluginPath);
// Use dynamic import to load the ES module
const pluginModule = await import(`file://${pluginPath}`);
pluginSettingsSchema = pluginModule.pluginSettingsSchema;
if (!pluginSettingsSchema) {
Expand All @@ -76,7 +76,7 @@ runs:
process.exit(1);
}
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8'));
manifest["configuration"] = pluginSettingsSchema;
function customReviver(key, value) {
Expand Down Expand Up @@ -108,15 +108,13 @@ runs:
const updatedManifest = JSON.stringify(manifest, customReviver, 2);
console.log('Updated manifest:', updatedManifest);
fs.writeFileSync(manifestPath, updatedManifest);
await fs.writeFile(manifestPath, updatedManifest);
}
try {
updateManifest();
} catch (error) {
updateManifest().catch(error => {
console.error('Error updating manifest:', error);
process.exit(1);
}
});
- name: Format manifest using Prettier
shell: bash
Expand Down

0 comments on commit 90e7386

Please sign in to comment.