From 02e1f528bf63b2a7fff5fad0423ce5b76d96a4d3 Mon Sep 17 00:00:00 2001 From: Horus Date: Thu, 18 May 2023 01:37:28 +0800 Subject: [PATCH] fix: add workflow to check release version match with package.json (#2420) --- .github/workflows/nightly-build.yml | 1 + .github/workflows/release-desktop-app.yml | 1 + apps/electron/scripts/generate-assets.mjs | 14 +++++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nightly-build.yml b/.github/workflows/nightly-build.yml index 1f0a9c7dcb..b7c16da426 100644 --- a/.github/workflows/nightly-build.yml +++ b/.github/workflows/nightly-build.yml @@ -66,6 +66,7 @@ jobs: API_SERVER_PROFILE: prod ENABLE_TEST_PROPERTIES: false ENABLE_IMAGE_PREVIEW_MODAL: false + RELEASE_VERSION: ${{ needs.set-build-version.outputs.version }} - name: Upload Artifact (web-static) uses: actions/upload-artifact@v3 diff --git a/.github/workflows/release-desktop-app.yml b/.github/workflows/release-desktop-app.yml index 0f6418d1ad..1c06854685 100644 --- a/.github/workflows/release-desktop-app.yml +++ b/.github/workflows/release-desktop-app.yml @@ -67,6 +67,7 @@ jobs: API_SERVER_PROFILE: prod ENABLE_TEST_PROPERTIES: false ENABLE_IMAGE_PREVIEW_MODAL: false + RELEASE_VERSION: ${{ github.event.inputs.version }} - name: Upload Artifact (web-static) uses: actions/upload-artifact@v3 diff --git a/apps/electron/scripts/generate-assets.mjs b/apps/electron/scripts/generate-assets.mjs index 70b35d4683..8b175caff4 100644 --- a/apps/electron/scripts/generate-assets.mjs +++ b/apps/electron/scripts/generate-assets.mjs @@ -9,6 +9,7 @@ const publicDistDir = path.join(electronRootDir, 'resources'); const affineWebDir = path.join(repoRootDir, 'apps', 'web'); const affineWebOutDir = path.join(affineWebDir, 'out'); const publicAffineOutDir = path.join(publicDistDir, `web-static`); +const releaseVersionEnv = process.env.RELEASE_VERSION || ''; console.log('build with following dir', { repoRootDir, @@ -19,9 +20,20 @@ console.log('build with following dir', { publicAffineOutDir, }); +// step 0: check version match +const electronPackageJson = await import(`${electronRootDir}/package.json`, { + assert: { + type: 'json', + }, +}); +if (releaseVersionEnv && electronPackageJson.version !== releaseVersionEnv) { + throw new Error( + `Version mismatch, expected ${releaseVersionEnv} but got ${electronPackageJson.version}` + ); +} // copy web dist files to electron dist -// step 0: clean up +// step 1: clean up await cleanup(); echo('Clean up done');