diff --git a/tools/release-latest.mjs b/tools/release-latest.mjs index 6cc3f8d14..2a37a84e1 100644 --- a/tools/release-latest.mjs +++ b/tools/release-latest.mjs @@ -1,32 +1,34 @@ -import { execSync } from 'child_process'; // For shell commands -import * as fs from 'fs/promises'; // For file system operations -import * as https from 'https'; // For downloading files +import { execSync } from 'child_process' // For shell commands +import * as fs from 'fs/promises' // For file system operations +import * as https from 'https' // For downloading files -const gitUrl = 'https://github.com/Amazefcc233/mimir-docs'; -const deployPath = '~/deploy'; -const artifactPath = 'artifact/'; +const gitUrl = 'https://github.com/Amazefcc233/mimir-docs' +const deployPath = '~/deploy' +const artifactPath = 'artifact/' async function main() { // Clone repository - await execSync(`git clone --single-branch --branch main ${gitUrl} ${deployPath}`); + execSync(`git clone --single-branch --branch main ${gitUrl} ${deployPath}`) // Change directory - process.chdir(deployPath); + process.chdir(deployPath) // Get release information from environment variables (assuming GitHub Actions context) - const version = process.env.GITHUB_EVENT_RELEASE_TAG_NAME.slice(1); // remove leading 'v' - const releaseTime = convertReleaseTime(process.env.GITHUB_EVENT_RELEASE_PUBLISHED_AT); - const releaseNote = await getReleaseNote(process.env.GITHUB_EVENT_RELEASE_BODY); + const version = process.env.GITHUB_EVENT_RELEASE_TAG_NAME.slice(1) // remove leading 'v' + const releaseTime = convertReleaseTime(process.env.GITHUB_EVENT_RELEASE_PUBLISHED_AT) + const releaseNote = await getReleaseNote(process.env.GITHUB_EVENT_RELEASE_BODY) // Get asset information - const [apkInfo, ipaInfo] = await Promise.all([getAssetInfo('apk'), getAssetInfo('ipa')]); + const [apkInfo, ipaInfo] = await Promise.all([getAssetInfo('apk'), getAssetInfo('ipa')]) // Configure git - await execSync('git config --global user.name "github-actions[bot]"'); - await execSync('git config --global user.email "github-actions[bot]@users.noreply.github.com"'); + execSync('git config --global user.name "github-actions[bot]"') + execSync('git config --global user.email "github-actions[bot]@users.noreply.github.com"') // Create artifact directory - await fs.mkdir(artifactPath, { recursive: true }); + await fs.mkdir(artifactPath, { recursive: true }) + + // Generate artifact data const artifactData = { @@ -53,43 +55,57 @@ async function main() { }, }, }, - }; + } // Write artifact data to JSON file - const jsonData = JSON.stringify(artifactData, null, 2); - await fs.writeFile(`\{artifactPath\}{version}.json`, jsonData); + const jsonData = JSON.stringify(artifactData, null, 2) + await fs.writeFile(`${artifactPath}${version}.json`, jsonData) // Symlink latest.json to current version - await fs.unlink(`${artifactPath}latest.json`, { ignoreENOENT: true }); // Ignore if file doesn't exist - await fs.symlink(`${version}.json`, `${artifactPath}latest.json`); + await fs.unlink(`${artifactPath}latest.json`, { ignoreENOENT: true }) // Ignore if file doesn't exist + await fs.symlink(`${version}.json`, `${artifactPath}latest.json`) // Git operations - await execSync('git add .'); - await execSync(`git commit -m "Release New Version: ${version}"`); - await execSync(`git push "git@github.com:Amazefcc233/mimir-docs" main:main`); + execSync('git add .') + execSync(`git commit -m "Release New Version: ${version}"`) + execSync(`git push "git@github.com:Amazefcc233/mimir-docs" main:main`) } async function convertReleaseTime(releaseTimeString) { - const releaseTime = new Date(releaseTimeString.replace('T', ' ').replace('Z', '')); - releaseTime.setHours(releaseTime.getHours() - 8); // Adjust for 8 hours difference - return releaseTime.toISOString().slice(0, 19).replace('T', ' '); // Format: YYYY-MM-DD HH:MM:SS + const releaseTime = new Date(releaseTimeString.replace('T', ' ').replace('Z', '')) + releaseTime.setHours(releaseTime.getHours() - 8) // Adjust for 8 hours difference + return releaseTime.toISOString().slice(0, 19).replace('T', ' ') // Format: YYYY-MM-DD HH:MM:SS } async function getReleaseNote(body) { - const lines = body.split('\n'); - const startIndex = lines.findIndex(line => line.startsWith('## 更改')); - const endIndex = lines.findIndex(line => line.startsWith('## How to download')); - return lines.slice(startIndex + 1, endIndex - 1).join('\n').trim(); + const lines = body.split('\n') + const startIndex = lines.findIndex(line => line.startsWith('## 更改')) + const endIndex = lines.findIndex(line => line.startsWith('## How to download')) + return lines.slice(startIndex + 1, endIndex - 1).join('\n').trim() } async function getAssetInfo(type) { - const asset = process.env[`GITHUB_EVENT_RELEASE_ASSETS_${type.toUpperCase()}_0`]; + const asset = process.env[`GITHUB_EVENT_RELEASE_ASSETS_${type.toUpperCase()}_0`] if (!asset) { - return { name: '', sha256: '', url: '' }; + return { name: '', sha256: '', url: '' } + } + const url = asset.browser_download_url + const sha256 = url ? await downloadAndHash(url) : '' + return { name: asset.name, sha256, url } +} + +async function downloadAndHash(url) { + const response = await fetch(url) + const chunks = [] + for await (const chunk of response.body) { + chunks.push(chunk) } - const url = asset.browser_download_url; - const sha256 = url ? await downloadAndHash(url) : ''; - return { name: asset.name, sha256, url }; + const buffer = Buffer.concat(chunks) + const hash = crypto.createHash('sha256').update(buffer).digest('hex') + return hash } -async function downloadAndHash(url) +main().catch(error => { + console.error(error) + process.exit(1) +}) diff --git a/tools/to-distro.mjs b/tools/to-distro.mjs new file mode 100644 index 000000000..70d783607 --- /dev/null +++ b/tools/to-distro.mjs @@ -0,0 +1,34 @@ +import fs from 'fs/promises'; // For file system operations + +const projectPbxprojPath = 'ios/Runner.xcodeproj/project.pbxproj'; + +async function main() { + // Read project.pbxproj file content + const filedata = await fs.readFile(projectPbxprojPath, 'utf-8'); + + // Replace CODE_SIGN_IDENTITY + filedata = filedata.replace( + 'CODE_SIGN_IDENTITY = "Apple Development";', + 'CODE_SIGN_IDENTITY = "Apple Distribution";', + ); + + // Replace CODE_SIGN_STYLE + filedata = filedata.replace('CODE_SIGN_STYLE = Automatic;', 'CODE_SIGN_STYLE = Manual;'); + + // Replace DEVELOPMENT_TEAM + filedata = filedata.replace('DEVELOPMENT_TEAM = "";', 'DEVELOPMENT_TEAM = "M5APZD5CKA";'); + + // Replace PROVISIONING_PROFILE_SPECIFIER + filedata = filedata.replace( + 'PROVISIONING_PROFILE_SPECIFIER = "";', + 'PROVISIONING_PROFILE_SPECIFIER = "SITLife-Distribution-AppStore";', + ); + + // Write updated file content back to the file + await fs.writeFile(projectPbxprojPath, filedata); +} + +main().catch(error => { + console.error(error); + process.exit(1); +});