diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d27cd59a..01561830 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -214,9 +214,16 @@ jobs: env: SITMC_TEMP_SERVER_AUTH: ${{ secrets.SITMC_TEMP_SERVER_AUTH }} run: | - node tools/upload-sitmc.js build/app-release-signed.apk -d mimir-preview/latest.apk + node tools/upload-sitmc-preview.js build/app-release-signed.apk - name: Push changes uses: ad-m/github-push-action@master with: branch: ${{ github.ref }} + + - name: Deploy + if: github.repository == 'plum-tech/mimir' + env: + MIMIR_VERSION_TOKEN: ${{ secrets.MIMIR_VERSION_TOKEN }} + run: | + node tools/publish-preview.js diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8e6f7280..6c0f12e6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -37,7 +37,7 @@ jobs: env: SITMC_TEMP_SERVER_AUTH: ${{ secrets.SITMC_TEMP_SERVER_AUTH }} run: | - node tools/upload-release-sitmc.js + node tools/upload-sitmc-release.js - name: Deploy if: github.repository == 'plum-tech/mimir' @@ -45,4 +45,3 @@ jobs: MIMIR_VERSION_TOKEN: ${{ secrets.MIMIR_VERSION_TOKEN }} run: | node tools/publish-release.js - diff --git a/tools/lib/sitmc.js b/tools/lib/sitmc.js index c57c7bb1..fc3a1cbe 100644 --- a/tools/lib/sitmc.js +++ b/tools/lib/sitmc.js @@ -54,6 +54,6 @@ export async function deleteFile({ remotePath }) { * * @param {{tagName:string,fileName:string}} param0 */ -export function getArtifactDownloadUrl({ tagName, fileName }) { - return `https://temp.sitmc.club/prepare-download/${tagName}/${sanitizeNameForUri(fileName)}` +export function getArtifactDownloadUrl({ folder, fileName }) { + return `https://temp.sitmc.club/prepare-download/${folder}/${sanitizeNameForUri(fileName)}` } diff --git a/tools/publish-preview.js b/tools/publish-preview.js new file mode 100644 index 00000000..8c41e390 --- /dev/null +++ b/tools/publish-preview.js @@ -0,0 +1,43 @@ +import { getArtifactDownloadUrl } from './lib/sitmc.js' +import esMain from 'es-main' +import { uploadPreviewVersion } from "./lib/backend.js" +import { getLatestTag } from "./lib/git.js" +import { cli } from "@liplum/cli" + +const main = async () => { + const args = cli({ + name: 'publish-preview', + description: 'Publish the preview and version info onto the back end.', + examples: ['node ./publish-preview.js',], + require: [], + options: [], + }) + const { version } = await getLatestTag() + const info = buildVersionInfo({ + version, + }) + + const result = await uploadPreviewVersion(info) + console.log(`Uploaded result: ${result}`) +} + +const buildVersionInfo = ({ version }) => { + const fileName = `sitlife-v${version}.apk` + const info = { + version, + releaseNote: { + "zh-Hans": "", + }, + assets: { + Android: { + fileName, + defaultSrc: getArtifactDownloadUrl({ tagName: "mimir-preview", fileName }), + } + }, + } + return info +} + +if (esMain(import.meta)) { + main() +} diff --git a/tools/publish-release.js b/tools/publish-release.js index ac9c6832..14f2ac5b 100644 --- a/tools/publish-release.js +++ b/tools/publish-release.js @@ -34,17 +34,12 @@ const main = async () => { export const prepareVersionInfo = async () => { // Get release information from environment variables (GitHub Actions context) const version = getVersion() - const releaseTime = getPublishTime() const releaseNote = getReleaseNote() - console.log(version, releaseTime) - const apk = await searchAndGetAssetInfo(({ name }) => path.extname(name) === ".apk") // Generate artifact data const artifactPayload = buildVersionInfo({ version, - tagName: github.release.tag_name, - releaseTime, releaseNote, apk, }) @@ -79,32 +74,14 @@ export const getReleaseNote = () => { } } -export const getPublishTime = () => { - return new Date(github.release.published_at) -} - -const buildVersionInfo = ({ version, tagName, releaseTime, releaseNote, apk }) => { - const androidMarketUrl = "market://details?id=life.mysit.sit_life" +const buildVersionInfo = ({ version, releaseNote, apk }) => { const info = { version, - time: releaseTime, releaseNote, - importance: "normal", - delayInMinute: 7 * 24 * 60, assets: { Android: { fileName: apk.name, - defaultSrc: getArtifactDownloadUrl({ tagName, fileName: apk.name }), - src: { - "com.heytap.market": androidMarketUrl, - "com.hihonor.appmarket": androidMarketUrl, - "com.huawei.appmarket": androidMarketUrl, - "com.huawei.localBackup": androidMarketUrl, - "com.huawei.browser": androidMarketUrl, - "com.bbk.appstore": androidMarketUrl, - "com.xiaomi.market": androidMarketUrl, - "com.miui.packageinstaller": androidMarketUrl - } + defaultSrc: getArtifactDownloadUrl({ folder: "mimir", fileName: apk.name }), } }, } diff --git a/tools/upload-sitmc-preview.js b/tools/upload-sitmc-preview.js new file mode 100644 index 00000000..d63cc6b3 --- /dev/null +++ b/tools/upload-sitmc-preview.js @@ -0,0 +1,34 @@ +import { uploadFile } from "./lib/sitmc.js" +import { cli } from '@liplum/cli' +import esMain from "es-main" +import { sanitizeNameForUri } from "./lib/utils.js" +import { getLatestTag } from "./lib/git.js" +import "dotenv/config" + +const main = async () => { + const args = cli({ + name: 'upload-preview-sitmc', + description: 'Upload preview files onto SIT-MC server. Env $SITMC_FILE_TOKEN required.', + examples: ['node ./upload-preview-sitmc.js -s ',], + require: ['source'], + options: [{ + name: 'source', + alias: "s", + defaultOption: true, + description: 'The path of local file to upload to SIT-MC server.' + }], + }) + + const version = await getLatestTag() + const filePath = args.source + const res = await uploadFile({ + localFilePath: filePath, + remotePath: `mimir-preview/${sanitizeNameForUri(`sitlife-v${version}.apk`)}`, + }) + console.log(res) +} + + +if (esMain(import.meta)) { + main() +} diff --git a/tools/upload-release-sitmc.js b/tools/upload-sitmc-release.js similarity index 87% rename from tools/upload-release-sitmc.js rename to tools/upload-sitmc-release.js index c1f719df..8e9d3d67 100644 --- a/tools/upload-release-sitmc.js +++ b/tools/upload-sitmc-release.js @@ -4,7 +4,6 @@ import { cli } from '@liplum/cli' import { searchAndGetAssetInfo } from "./lib/release.js" import esMain from "es-main" import { downloadFile, sanitizeNameForUri } from "./lib/utils.js" -import { github } from "./lib/github.js" import os from "os" import "dotenv/config" @@ -17,7 +16,6 @@ const main = async () => { options: [], }) - const tag = github.release.tag_name const apk = await searchAndGetAssetInfo(({ name }) => path.extname(name) === ".apk") if (!apk) { console.error("Couldn't find .apk file in the release.") @@ -28,7 +26,7 @@ const main = async () => { await downloadFile(apk.url, apkPath) const res = await uploadFile({ localFilePath: apkPath, - remotePath: `${tag}/${sanitizeNameForUri(apk.name)}`, + remotePath: `mimir/${sanitizeNameForUri(apk.name)}`, }) console.log(res) } diff --git a/tools/upload-sitmc.js b/tools/upload-sitmc.js index 10affa1e..7d7233e3 100644 --- a/tools/upload-sitmc.js +++ b/tools/upload-sitmc.js @@ -23,7 +23,9 @@ const main = async () => { }) const filePath = args.source - const remotePath = args.destination ?? path.join(path.basename(path.dirname(filePath)), path.basename(filePath)) + const remotePath = args.destination ?? path.join( + path.basename(path.dirname(filePath)), path.basename(filePath) + ) const res = await uploadFile({ localFilePath: filePath, remotePath: remotePath,