Skip to content

Commit

Permalink
Merge pull request #620 from ghost-fvtt/check-for-errors
Browse files Browse the repository at this point in the history
Check for errors
  • Loading branch information
ghost91- authored Sep 16, 2023
2 parents 74350ec + cb4a12b commit 2b3c6d0
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node_version: [16, 18]
node_version: [18, 20]
steps:
- name: checkout code
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node_version: [16, 18]
node_version: [18, 20]
steps:
- name: checkout code
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Additionally, a couple of options can also be read from a manifest file.
| `--changelogURL` | `FVTT_CHANGELOG_URL` | `changelog` | The URL of the changelog of the package version being published | No |
| `--deleteObsoleteVersions` | `FVTT_DELETE_OBSOLETE_VERSIONS` | | Delete obsolete versions, i.e., all versions with the same compatible core version as the version being published | No |
| `--dryRun` | `FVTT_DRY_RUN` | | Just perform a dry run instead of actually publishing the package | No |
| `--headed` | `FVTT_HEADED` | | Run in headed mode, to be able to see the browser interaction | No |
| `--manifestURL` | `FVTT_MANIFEST_URL` | `manifest` | The URL of the manifest of the package version being published | Yes |
| `--manifestPath` | `FVTT_MANIFEST_PATH` | | A path to a manifest file to read information from | No |
| `--maximumCoreVersion` | `FVTT_MAXIMUM_CORE_VERSION` | `compatibility.maximum`, | The maximum version of the core Foundry software which is allowed to use the package | No |
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"devDependencies": {
"@commitlint/cli": "17.7.1",
"@commitlint/config-conventional": "17.7.0",
"@types/node": "18.17.17",
"@types/node": "20.6.2",
"@typescript-eslint/eslint-plugin": "6.7.0",
"@typescript-eslint/parser": "6.7.0",
"commitlint": "17.7.1",
Expand All @@ -73,8 +73,8 @@
"playwright-chromium": "^1.18.1"
},
"engines": {
"node": "^16.17.1 || ^18.12.0",
"npm": "^10.0.0"
"node": "^18.12.0 || ^20.6.1",
"npm": "^9.0.0 || ^10.0.0"
},
"packageManager": "^npm@8.15.0"
"packageManager": "^npm@9.6.7"
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ program
'Delete obsolete versions, i.e., all versions with the same verified core version as the version being published',
)
.option('--dryRun', 'Just perform a dry run instead of actually publishing the package')
.option('--headed', 'Run in headed mode, to be able to see the browser interaction')
.option('--manifestURL <url>', 'The URL of the manifest of the package version being published')
.option('--manifestPath <path>', 'A path to a manifest file to read information from')
.option(
Expand Down
4 changes: 3 additions & 1 deletion src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface CLIOptions {
verifiedCoreVersion?: string;
deleteObsoleteVersions?: boolean;
dryRun?: boolean;
headed?: boolean;
manifestURL?: string;
manifestPath?: string;
maximumCoreVersion?: string;
Expand All @@ -24,7 +25,7 @@ export interface CLIOptions {
username?: string;
}
const optionalStringOptionKeys = ['changelogURL', 'maximumCoreVersion'] as const;
const optionalBooleanOptionKeys = ['deleteObsoleteVersions', 'dryRun'] as const;
const optionalBooleanOptionKeys = ['deleteObsoleteVersions', 'dryRun', 'headed'] as const;

const requiredOptionKeys = [
'verifiedCoreVersion',
Expand Down Expand Up @@ -81,6 +82,7 @@ function mergeWithEnvironmentVariables(options: CLIOptions): CLIOptions & Partia
? process.env.FVTT_DELETE_OBSOLETE_VERSIONS === 'true'
: undefined,
dryRun: process.env.FVTT_DRY_RUN !== undefined ? process.env.FVTT_DRY_RUN === 'true' : undefined,
headed: process.env.FVTT_HEADED !== undefined ? process.env.FVTT_HEADED === 'true' : undefined,
manifestURL: process.env.FVTT_MANIFEST_URL,
manifestPath: process.env.FVTT_MANIFEST_PATH,
maximumCoreVersion: process.env.FVTT_MAXIMUM_CORE_VERSION,
Expand Down
15 changes: 12 additions & 3 deletions src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function publish(options: Options): Promise<void> {
} else {
console.log(`Publishing Foundry VTT package with id '${options.packageID}'.`);
}
const browser = await chromium.launch({ headless: true });
const browser = await chromium.launch({ headless: !options.headed });
try {
const page = await browser.newPage();
await login(page, options);
Expand All @@ -37,7 +37,7 @@ async function login(page: Page, { username, password }: Options) {

async function updatePackage(page: Page, options: Options) {
console.log('Trying to update the package…');
await page.goto(path.join(foundryBaseURL, `admin/packages/package/${options.packageID}/change/`));
await page.goto(getPackageURL(options));

const id = await page.locator('tr.dynamic-versions:not(.has_original)').evaluate((e) => e.id);

Expand Down Expand Up @@ -67,11 +67,16 @@ async function updatePackage(page: Page, options: Options) {

const promises: Promise<unknown>[] = [];
if (!options.dryRun) {
promises.push(page.waitForNavigation({ waitUntil: 'load' }));
promises.push(page.waitForURL(getPackageURL(options)));
}
promises.push(page.click('[name="_continue"]'));
await Promise.all(promises);

const errors = await page.locator('ul.errorlist li').evaluateAll((li) => li.map((element) => element.textContent));
if (errors.length > 0) {
throw new Error(`Errors while updating package:\n${errors.join('\n')}`);
}

console.log('Package updated successfully.');
}

Expand All @@ -94,3 +99,7 @@ async function checkDeleteCheckboxes(page: Page, { verifiedCoreVersion }: Option
console.log(`Marked version ${version} for deletion.`);
}
}

function getPackageURL(options: Options): string {
return path.join(foundryBaseURL, `admin/packages/package/${options.packageID}/change/`);
}

0 comments on commit 2b3c6d0

Please sign in to comment.