diff --git a/client/mobile/package.json b/client/mobile/package.json index 5859b233..276b76e7 100644 --- a/client/mobile/package.json +++ b/client/mobile/package.json @@ -32,12 +32,14 @@ "@babel/runtime": "^7.20.0", "@react-native-community/eslint-config": "^3.2.0", "@tsconfig/react-native": "^2.0.2", + "@types/fs-extra": "^11.0.1", "@types/jest": "^29.2.1", "@types/lodash": "^4.14.191", "@types/react": "^18.0.24", "@types/react-test-renderer": "^18.0.0", "babel-jest": "^29.2.1", "eslint": "^8.19.0", + "fs-extra": "^11.1.0", "jest": "^29.2.1", "metro-react-native-babel-preset": "0.73.7", "prettier": "^2.4.1", diff --git a/client/mobile/scripts/notify-links.js b/client/mobile/scripts/notify-links.js index 5d710574..878b9c88 100644 --- a/client/mobile/scripts/notify-links.js +++ b/client/mobile/scripts/notify-links.js @@ -1,5 +1,5 @@ -const { link } = require('fs'); const tailchat = require('tailchat-client-sdk'); +const fs = require('fs-extra'); // reference: https://docs.codemagic.io/yaml-basic-configuration/environment-variables/#artifact-links const artifactLinks = process.env['CM_ARTIFACT_LINKS']; @@ -9,23 +9,37 @@ console.log('artifactLinks:', artifactLinks); if (tailchatSubscribeId) { try { - const links = JSON.parse(artifactLinks) ?? []; - const text = - '[b]App 构建成功:[/b]\n' + - links - .map((link) => { - const { name, url, md5, versionName } = link; - return `${name} -version: ${versionName}(${md5}) -[url=${url}]下载链接[/url]`; - }) - .join('\n=========\n'); + if (fs.existsSync('~/SUCCESS')) { + const links = JSON.parse(artifactLinks) ?? []; + const text = + '[b]App 构建成功:[/b]\n' + + links + .map((link) => { + const { name, url, md5, versionName } = link; + return ( + `${name}\n` + + `version: ${versionName}(${md5})\n` + + `[url=${url}]下载安装包[/url]` + ); + }) + .join('\n=========\n'); - tailchat.sendSimpleNotify( - 'https://tailchat-nightly.moonrailgun.com', - tailchatSubscribeId, - text - ); + tailchat.sendSimpleNotify( + 'https://tailchat-nightly.moonrailgun.com', + tailchatSubscribeId, + text + ); + } else { + const text = + '[b]App 构建失败:[/b]\n' + + `[url=https://codemagic.io/app/${process.env['CM_PROJECT_ID']}/build/${process.env['CM_BUILD_ID']}]查看详情[/url]`; + + tailchat.sendSimpleNotify( + 'https://tailchat-nightly.moonrailgun.com', + tailchatSubscribeId, + text + ); + } } catch (e) { console.error(e); } diff --git a/client/mobile/yarn.lock b/client/mobile/yarn.lock index d3447dcb..60f68ce5 100644 --- a/client/mobile/yarn.lock +++ b/client/mobile/yarn.lock @@ -1797,6 +1797,14 @@ resolved "https://registry.npmmirror.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== +"@types/fs-extra@^11.0.1": + version "11.0.1" + resolved "https://registry.npmmirror.com/@types/fs-extra/-/fs-extra-11.0.1.tgz#f542ec47810532a8a252127e6e105f487e0a6ea5" + integrity sha512-MxObHvNl4A69ofaTRU8DFqvgzzv8s9yRtaPPm5gud9HDNvpB3GPQFvNuTWAI59B9huVGV5jXYJwbCsmBsOGYWA== + dependencies: + "@types/jsonfile" "*" + "@types/node" "*" + "@types/graceful-fs@^4.1.3": version "4.1.6" resolved "https://registry.npmmirror.com/@types/graceful-fs/-/graceful-fs-4.1.6.tgz#e14b2576a1c25026b7f02ede1de3b84c3a1efeae" @@ -1841,6 +1849,13 @@ resolved "https://registry.npmmirror.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3" integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ== +"@types/jsonfile@*": + version "6.1.1" + resolved "https://registry.npmmirror.com/@types/jsonfile/-/jsonfile-6.1.1.tgz#ac84e9aefa74a2425a0fb3012bdea44f58970f1b" + integrity sha512-GSgiRCVeapDN+3pqA35IkQwasaCh/0YFH5dEF6S88iDvEn901DjOeH3/QPY+XYP1DFzDZPvIvfeEgk+7br5png== + dependencies: + "@types/node" "*" + "@types/lodash@^4.14.191": version "4.14.191" resolved "https://registry.npmmirror.com/@types/lodash/-/lodash-4.14.191.tgz#09511e7f7cba275acd8b419ddac8da9a6a79e2fa" @@ -3976,6 +3991,15 @@ fresh@0.5.2: resolved "https://registry.npmmirror.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7" integrity sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q== +fs-extra@^11.1.0: + version "11.1.0" + resolved "https://registry.npmmirror.com/fs-extra/-/fs-extra-11.1.0.tgz#5784b102104433bb0e090f48bfc4a30742c357ed" + integrity sha512-0rcTq621PD5jM/e0a3EJoGC/1TC5ZBCERW82LQuwfGnCa1V8w7dpYH1yNu+SLb6E5dkeCBzKEyLGlFrnr+dUyw== + dependencies: + graceful-fs "^4.2.0" + jsonfile "^6.0.1" + universalify "^2.0.0" + fs-extra@^8.1.0: version "8.1.0" resolved "https://registry.npmmirror.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0" diff --git a/codemagic.yaml b/codemagic.yaml index 755a46b6..1a4ab73d 100644 --- a/codemagic.yaml +++ b/codemagic.yaml @@ -21,6 +21,8 @@ workflows: ./gradlew assembleRelease \ -PversionCode=$UPDATED_BUILD_NUMBER \ -PversionName=1.0.$UPDATED_BUILD_NUMBER + - name: Build finished successfully + script: touch ~/SUCCESS artifacts: - android/app/build/outputs/**/**/*.apk publishing: @@ -30,7 +32,7 @@ workflows: scripts: - name: Notify artifact URL to Tailchat script: | - node client/mobile/scripts/notify-links.js + node scripts/notify-links.js # ios: # name: build, test & publish iOS version