|
1 | 1 | import * as core from '@actions/core';
|
2 | 2 | import {context} from '@actions/github';
|
| 3 | +import type {TupleToUnion} from 'type-fest'; |
3 | 4 | import CONST from '@github/libs/CONST';
|
4 | 5 | import GithubUtils from '@github/libs/GithubUtils';
|
5 | 6 |
|
6 | 7 | function getTestBuildMessage(): string {
|
7 |
| - console.log('Input for android', core.getInput('ANDROID', {required: true})); |
8 |
| - const androidSuccess = core.getInput('ANDROID', {required: true}) === 'success'; |
9 |
| - const desktopSuccess = core.getInput('DESKTOP', {required: true}) === 'success'; |
10 |
| - const iOSSuccess = core.getInput('IOS', {required: true}) === 'success'; |
11 |
| - const webSuccess = core.getInput('WEB', {required: true}) === 'success'; |
| 8 | + const inputs = ['ANDROID', 'DESKTOP', 'IOS', 'WEB'] as const; |
| 9 | + const names = { |
| 10 | + [inputs[0]]: 'Android', |
| 11 | + [inputs[1]]: 'Desktop', |
| 12 | + [inputs[2]]: 'iOS', |
| 13 | + [inputs[3]]: 'Web', |
| 14 | + }; |
12 | 15 |
|
13 |
| - const androidLink = androidSuccess ? core.getInput('ANDROID_LINK') : '❌ FAILED ❌'; |
14 |
| - const desktopLink = desktopSuccess ? core.getInput('DESKTOP_LINK') : '❌ FAILED ❌'; |
15 |
| - const iOSLink = iOSSuccess ? core.getInput('IOS_LINK') : '❌ FAILED ❌'; |
16 |
| - const webLink = webSuccess ? core.getInput('WEB_LINK') : '❌ FAILED ❌'; |
| 16 | + const result = inputs.reduce((acc, platform) => { |
| 17 | + const input = core.getInput(platform, {required: false}); |
17 | 18 |
|
18 |
| - const androidQRCode = androidSuccess |
19 |
| - ? `` |
20 |
| - : "The QR code can't be generated, because the android build failed"; |
21 |
| - const desktopQRCode = desktopSuccess |
22 |
| - ? `` |
23 |
| - : "The QR code can't be generated, because the Desktop build failed"; |
24 |
| - const iOSQRCode = iOSSuccess ? `` : "The QR code can't be generated, because the iOS build failed"; |
25 |
| - const webQRCode = webSuccess ? `` : "The QR code can't be generated, because the web build failed"; |
| 19 | + if (!input) { |
| 20 | + acc[platform] = {link: 'N/A', qrCode: 'N/A'}; |
| 21 | + return acc; |
| 22 | + } |
| 23 | + |
| 24 | + const isSuccess = input === 'success'; |
| 25 | + |
| 26 | + const link = isSuccess ? core.getInput(`${platform}_LINK`) : '❌ FAILED ❌'; |
| 27 | + const qrCode = isSuccess |
| 28 | + ? `![${names[platform]}](https://api.qrserver.com/v1/create-qr-code/?size=120x120&data=${link})` |
| 29 | + : `The QR code can't be generated, because the ${names[platform]} build failed`; |
| 30 | + |
| 31 | + acc[platform] = { |
| 32 | + link, |
| 33 | + qrCode, |
| 34 | + }; |
| 35 | + return acc; |
| 36 | + }, {} as Record<TupleToUnion<typeof inputs>, {link: string; qrCode: string}>); |
26 | 37 |
|
27 | 38 | const message = `:test_tube::test_tube: Use the links below to test this adhoc build on Android, iOS, Desktop, and Web. Happy testing! :test_tube::test_tube:
|
28 | 39 | | Android :robot: | iOS :apple: |
|
29 | 40 | | ------------- | ------------- |
|
30 |
| -| ${androidLink} | ${iOSLink} | |
31 |
| -| ${androidQRCode} | ${iOSQRCode} | |
| 41 | +| ${result.ANDROID.link} | ${result.IOS.link} | |
| 42 | +| ${result.ANDROID.qrCode} | ${result.IOS.qrCode} | |
32 | 43 | | Desktop :computer: | Web :spider_web: |
|
33 |
| -| ${desktopLink} | ${webLink} | |
34 |
| -| ${desktopQRCode} | ${webQRCode} | |
| 44 | +| ${result.DESKTOP.link} | ${result.WEB.link} | |
| 45 | +| ${result.DESKTOP.qrCode} | ${result.WEB.qrCode} | |
35 | 46 |
|
36 | 47 | ---
|
37 | 48 |
|
|
0 commit comments