Skip to content

Commit

Permalink
Remove hardcoded version from manifest
Browse files Browse the repository at this point in the history
* Dynamically set version as argument to build script
* Set version using tag ref_name in CI
* [Cleanup] gitignore ext/manifest.json as it's dynamically generated
  • Loading branch information
djahandarie committed Sep 23, 2023
1 parent 94ccff4 commit 6f24ac4
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 153 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,11 @@ jobs:
env:
CI: true

- name: Manifest
run: npm run test-manifest
env:
CI: true
- name: Build
run: npm run build

- name: Validate manifest.json of the extension
uses: cardinalby/schema-validator-action@c2da05377e89dd0c9b7be9420da0b3534b1efcce # pin@v1
with:
file: ext/manifest.json
schema: "https://json.schemastore.org/chrome-manifest.json"

- name: Build
run: npm run test-build
2 changes: 1 addition & 1 deletion .github/workflows/create-prerelease-on-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
node-version-file: ".node-version"

- name: Lint
run: npm run-script build
run: npm run-script build -- --yomitan-version ${{ github.ref_name }}
shell: bash

- name: Release
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
run: rm -rf /usr/share/fonts

- uses: actions/checkout@v3

- name: Install CJK fonts
uses: awalsh128/cache-apt-pkgs-action@1850ee53f6e706525805321a3f2f863dcf73c962 # v1.3.0
with:
packages: fonts-ipafont-mincho
execute_install_scripts: true

- uses: actions/setup-node@v3
with:
cache: "npm"
Expand All @@ -29,6 +29,9 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Cache playwright browsers
id: cache-playwright
uses: actions/cache@v3
Expand All @@ -40,7 +43,7 @@ jobs:
- if: ${{ steps.cache-playwright.outputs.cache-hit != 'true' }}
name: Install Playwright Browsers
run: npx playwright install chromium

- name: Grab latest dictionaries from dictionaries branch
uses: actions/checkout@v3
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ dictionaries/
/playwright-report/
/playwright/.cache/
/test/playwright/__screenshots__/
ext/manifest.json
10 changes: 4 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ Several command line arguments are available for these scripts:
* `[target]` - Builds a specific target.
* `--all` - Builds all targets specified in [manifest-variants.json](dev/data/manifest-variants.json).
* `--default` - Restores the default manifest file.
* `--manifest <target>` - Overwrites [ext/manifest.json](ext/manifest.json) with the manifest variant for the specified build target.
* `--manifest <target>` - Overwrites `ext/manifest.json` with the manifest variant for the specified build target.
* `--dry-run` - Runs the full build process (excluding zip building), checking that the configuration is valid.
* `--dry-run-build-zip` - If `--dry-run` is also specified, zip building will also be performed in memory; no files are created.
* `--yomitan-version <version>` - Sets the version number in the extension manifest. Defaults to 0.0.0.0 if not set.

If no arguments are specified, the command is equivalent to `build.bat --all`.

Expand All @@ -66,11 +67,8 @@ Otherwise, the [JSZip](https://stuk.github.io/jszip/) API is used to generate th
## Manifest

Manifest variants for different build targets are specified in [manifest-variants.json](dev/data/manifest-variants.json).
This file is used to overwrite the [manfiest.json](ext/manifest.json) file included in the extension.
By default, this manifest should be the default `chrome` manifest, and changes to [manfiest.json](ext/manifest.json) should not be committed
unless there is a corresponding change in [manifest-variants.json](dev/data/manifest-variants.json).
There is a continuous integration test which validates this, and the default manifest can be restored by running
`build.bat --default`.
This file is used to generate the `ext/manifest.json` file included in the extension.
The generated `ext/manfiest.json` should not be committed.

## Style

Expand Down
12 changes: 8 additions & 4 deletions dev/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function getIndexOfFilePath(array, item) {
return -1;
}

async function build(buildDir, extDir, manifestUtil, variantNames, manifestPath, dryRun, dryRunBuildZip) {
async function build(buildDir, extDir, manifestUtil, variantNames, manifestPath, dryRun, dryRunBuildZip, yomitanVersion) {
const sevenZipExes = ['7za', '7z'];

// Create build directory
Expand All @@ -130,6 +130,8 @@ async function build(buildDir, extDir, manifestUtil, variantNames, manifestPath,
process.stdout.write(message);
};

process.stdout.write(`Version: ${yomitanVersion}...\n`);

for (const variantName of variantNames) {
const variant = manifestUtil.getVariant(variantName);
if (typeof variant === 'undefined' || variant.buildable === false) { continue; }
Expand All @@ -148,7 +150,7 @@ async function build(buildDir, extDir, manifestUtil, variantNames, manifestPath,
const fileNameSafe = path.basename(fileName);
const fullFileName = path.join(buildDir, fileNameSafe);
if (!dryRun) {
fs.writeFileSync(manifestPath, ManifestUtil.createManifestString(modifiedManifest));
fs.writeFileSync(manifestPath, ManifestUtil.createManifestString(modifiedManifest).replace('$YOMITAN_VERSION', yomitanVersion));
}

if (!dryRun || dryRunBuildZip) {
Expand Down Expand Up @@ -183,11 +185,13 @@ async function main(argv) {
['manifest', null],
['dry-run', false],
['dry-run-build-zip', false],
['yomitan-version', '0.0.0.0'],
[null, []]
]));

const dryRun = args.get('dry-run');
const dryRunBuildZip = args.get('dry-run-build-zip');
const yomitanVersion = args.get('yomitan-version');

const manifestUtil = new ManifestUtil();

Expand All @@ -202,14 +206,14 @@ async function main(argv) {
manifestUtil.getVariants().filter(({buildable}) => buildable !== false).map(({name}) => name) :
args.get(null)
);
await build(buildDir, extDir, manifestUtil, variantNames, manifestPath, dryRun, dryRunBuildZip);
await build(buildDir, extDir, manifestUtil, variantNames, manifestPath, dryRun, dryRunBuildZip, yomitanVersion);
} finally {
// Restore manifest
const manifestName = (!args.get('default') && args.get('manifest') !== null) ? args.get('manifest') : null;
const restoreManifest = manifestUtil.getManifest(manifestName);
process.stdout.write('Restoring manifest...\n');
if (!dryRun) {
fs.writeFileSync(manifestPath, ManifestUtil.createManifestString(restoreManifest));
fs.writeFileSync(manifestPath, ManifestUtil.createManifestString(restoreManifest).replace('$YOMITAN_VERSION', yomitanVersion));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion dev/data/manifest-variants.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest": {
"manifest_version": 3,
"name": "Yomitan",
"version": "23.4.7.0",
"version": "$YOMITAN_VERSION",
"description": "Japanese dictionary with Anki integration",
"author": "TheMoeWay",
"icons": {
Expand Down
131 changes: 0 additions & 131 deletions ext/manifest.json

This file was deleted.

0 comments on commit 6f24ac4

Please sign in to comment.