mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 13:39:01 +01:00 
			
		
		
		
	build: Update nightly version to avoid caching issues
This commit is contained in:
		
							parent
							
								
									f37fa3723b
								
							
						
					
					
						commit
						9c27672794
					
				
							
								
								
									
										2
									
								
								.github/workflows/main.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/main.yml
									
									
									
									
										vendored
									
									
								
							@ -44,6 +44,8 @@ jobs:
 | 
			
		||||
        run: npm ci
 | 
			
		||||
      - name: Update build info
 | 
			
		||||
        run: npm run update-build-info
 | 
			
		||||
      - name: Update nightly version
 | 
			
		||||
        run: npm run ci-update-nightly-version
 | 
			
		||||
      - name: Run electron-forge
 | 
			
		||||
        run: npm run make-electron -- --arch=${{ matrix.arch }}
 | 
			
		||||
      - name: Prepare artifacts (Unix)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										50
									
								
								bin/update-nightly-version.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								bin/update-nightly-version.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,50 @@
 | 
			
		||||
/**
 | 
			
		||||
 * @module
 | 
			
		||||
 * 
 | 
			
		||||
 * The nightly version works uses the version described in `package.json`, just like any release.
 | 
			
		||||
 * The problem with this approach is that production builds have a very aggressive cache, and
 | 
			
		||||
 * usually running the nightly with this cached version of the application will mean that the
 | 
			
		||||
 * user might run into module not found errors or styling errors caused by an old cache.
 | 
			
		||||
 * 
 | 
			
		||||
 * This script is supposed to be run in the CI, which will update locally the version field of
 | 
			
		||||
 * `package.json` to contain the date. For example, `0.90.9-beta` will become `0.90.9-nightly-20241102-092832`.
 | 
			
		||||
 * 
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import { fileURLToPath } from "url";
 | 
			
		||||
import { dirname, join } from "path";
 | 
			
		||||
import fs from "fs";
 | 
			
		||||
 | 
			
		||||
function processVersion(version) {
 | 
			
		||||
    // Remove the beta suffix if any.
 | 
			
		||||
    version = version.replace("-beta", "");
 | 
			
		||||
 | 
			
		||||
    // Add the nightly suffix, plus the date.
 | 
			
		||||
    const referenceDate = new Date()
 | 
			
		||||
        .toISOString()
 | 
			
		||||
        .substring(0, 19)
 | 
			
		||||
        .replace(/[-:]*/g, "")
 | 
			
		||||
        .replace("T", "-");
 | 
			
		||||
    version = `${version}-nightly-${referenceDate}`;
 | 
			
		||||
 | 
			
		||||
    return version;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function main() {
 | 
			
		||||
    const scriptDir = dirname(fileURLToPath(import.meta.url));
 | 
			
		||||
    const packageJsonPath = join(scriptDir, "..", "package.json");
 | 
			
		||||
    
 | 
			
		||||
    // Read the version from package.json and process it.
 | 
			
		||||
    const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
 | 
			
		||||
    const currentVersion = packageJson.version;
 | 
			
		||||
    const adjustedVersion = processVersion(currentVersion);
 | 
			
		||||
    console.log("Current version is", currentVersion);
 | 
			
		||||
    console.log("Adjusted version is", adjustedVersion);
 | 
			
		||||
 | 
			
		||||
    // Write the adjusted version back in.
 | 
			
		||||
    packageJson.version = adjustedVersion;
 | 
			
		||||
    const formattedJson = JSON.stringify(packageJson, null, 4);    
 | 
			
		||||
    fs.writeFileSync(packageJsonPath, formattedJson);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
main();
 | 
			
		||||
@ -46,7 +46,8 @@
 | 
			
		||||
    "integration-edit-db": "cross-env TRILIUM_INTEGRATION_TEST=edit TRILIUM_PORT=8081 TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts",
 | 
			
		||||
    "integration-mem-db": "cross-env TRILIUM_INTEGRATION_TEST=memory TRILIUM_PORT=8082 TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts",
 | 
			
		||||
    "integration-mem-db-dev": "cross-env TRILIUM_INTEGRATION_TEST=memory TRILIUM_PORT=8082 TRILIUM_ENV=dev TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts",
 | 
			
		||||
    "generate-document": "cross-env nodemon src/tools/generate_document.ts 1000"
 | 
			
		||||
    "generate-document": "cross-env nodemon src/tools/generate_document.ts 1000",
 | 
			
		||||
    "ci-update-nightly-version": "tsx ./bin/update-nightly-version.ts"
 | 
			
		||||
  },
 | 
			
		||||
  "dependencies": {
 | 
			
		||||
    "@braintree/sanitize-url": "7.1.0",
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user