Skip to content

Commit

Permalink
[tools] [workflow] publish-preview
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed Sep 22, 2024
1 parent 13fef99 commit 1f28013
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 34 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ 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'
env:
MIMIR_VERSION_TOKEN: ${{ secrets.MIMIR_VERSION_TOKEN }}
run: |
node tools/publish-release.js
4 changes: 2 additions & 2 deletions tools/lib/sitmc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`
}
43 changes: 43 additions & 0 deletions tools/publish-preview.js
Original file line number Diff line number Diff line change
@@ -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()
}
27 changes: 2 additions & 25 deletions tools/publish-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down Expand Up @@ -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 }),
}
},
}
Expand Down
34 changes: 34 additions & 0 deletions tools/upload-sitmc-preview.js
Original file line number Diff line number Diff line change
@@ -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 <file>',],
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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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.")
Expand All @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion tools/upload-sitmc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1f28013

Please sign in to comment.