Skip to content

Commit

Permalink
fix(preview): use proper comment output variables
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric committed Feb 18, 2023
1 parent 49544e3 commit 7902fca
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 23 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ jobs:
echo $(jq 'del(.expo.runtimeVersion)' app.json) > app.json
echo $(jq '.expo.android.runtimeVersion.policy = "sdkVersion"' app.json) > app.json
echo $(jq '.expo.ios.runtimeVersion.policy = "appVersion"' app.json) > app.json
echo $(jq '.expo.scheme = "expogithubaction"' app.json) > app.json
- name: 🚀 Create preview (multi QR)
if: ${{ env.hasAuth == 'true' }}
Expand Down
25 changes: 14 additions & 11 deletions build/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23903,8 +23903,8 @@ async function previewAction(input = previewInput()) {
for (const [name, value] of Object.entries(variables)) {
(0,core.setOutput)(name, value);
}
(0,core.setOutput)('messageId', messageId);
(0,core.setOutput)('messageBody', messageBody);
(0,core.setOutput)('commentId', messageId);
(0,core.setOutput)('comment', messageBody);
}
/**
* Validate and sanitize the command that creates the update.
Expand Down Expand Up @@ -23980,13 +23980,21 @@ function createSummary(updates, vars) {
}
return createMultipleQrSummary(updates, vars);
}
function createSingleQrSummary(updates, vars) {
function createSummaryHeader(updates, vars) {
const platformName = `Platform${updates.length === 1 ? '' : 's'}`;
const platformValue = updates.map(update => `**${update.platform}**`).join(', ');
const platformValue = updates
.map(update => update.platform)
.sort((a, b) => a.localeCompare(b))
.map(platform => `**${platform}**`)
.join(', ');
const appScheme = vars.projectScheme ? `\n- App Scheme → **${vars.projectScheme}**` : '';
return `🚀 Expo preview is ready!

- Project → **${vars.projectSlug}**
- ${platformName} → ${platformValue}
- ${platformName} → ${platformValue}${appScheme}`;
}
function createSingleQrSummary(updates, vars) {
return `${createSummaryHeader(updates, vars)}
- Runtime Version → **${vars.runtimeVersion}**
- **[More info](${vars.link})**

Expand All @@ -23996,8 +24004,6 @@ function createSingleQrSummary(updates, vars) {
}
function createMultipleQrSummary(updates, vars) {
const createTableHeader = (segments) => segments.filter(Boolean).join(' <br /> ');
const platformName = `Platform${updates.length === 1 ? '' : 's'}`;
const platformValue = updates.map(update => `**${update.platform}**`).join(', ');
const androidHeader = createTableHeader([
'Android',
vars.androidId && vars.androidRuntimeVersion ? `_(${vars.androidRuntimeVersion})_` : '',
Expand All @@ -24014,10 +24020,7 @@ function createMultipleQrSummary(updates, vars) {
const iosQr = vars.iosId && vars.iosQR
? `<a href="${vars.iosQR}"><img src="${vars.iosQR}" width="250px" height="250px" /></a>`
: null;
return `🚀 Expo preview is ready!

- Project → **${vars.projectSlug}**
- ${platformName} → ${platformValue}
return `${createSummaryHeader(updates, vars)}

${androidHeader} | ${iosHeader}
--- | ---
Expand Down
28 changes: 16 additions & 12 deletions src/actions/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export async function previewAction(input = previewInput()) {
setOutput(name, value);
}

setOutput('messageId', messageId);
setOutput('messageBody', messageBody);
setOutput('commentId', messageId);
setOutput('comment', messageBody);
}

/**
Expand Down Expand Up @@ -151,14 +151,24 @@ export function createSummary(updates: EasUpdate[], vars: ReturnType<typeof getV
return createMultipleQrSummary(updates, vars);
}

function createSingleQrSummary(updates: EasUpdate[], vars: ReturnType<typeof getVariables>) {
function createSummaryHeader(updates: EasUpdate[], vars: ReturnType<typeof getVariables>) {
const platformName = `Platform${updates.length === 1 ? '' : 's'}`;
const platformValue = updates.map(update => `**${update.platform}**`).join(', ');
const platformValue = updates
.map(update => update.platform)
.sort((a, b) => a.localeCompare(b))
.map(platform => `**${platform}**`)
.join(', ');

const appScheme = vars.projectScheme ? `\n- App Scheme → **${vars.projectScheme}**` : '';

return `🚀 Expo preview is ready!
- Project → **${vars.projectSlug}**
- ${platformName}${platformValue}
- ${platformName}${platformValue}${appScheme}`;
}

function createSingleQrSummary(updates: EasUpdate[], vars: ReturnType<typeof getVariables>) {
return `${createSummaryHeader(updates, vars)}
- Runtime Version → **${vars.runtimeVersion}**
- **[More info](${vars.link})**
Expand All @@ -170,9 +180,6 @@ function createSingleQrSummary(updates: EasUpdate[], vars: ReturnType<typeof get
function createMultipleQrSummary(updates: EasUpdate[], vars: ReturnType<typeof getVariables>) {
const createTableHeader = (segments: string[]) => segments.filter(Boolean).join(' <br /> ');

const platformName = `Platform${updates.length === 1 ? '' : 's'}`;
const platformValue = updates.map(update => `**${update.platform}**`).join(', ');

const androidHeader = createTableHeader([
'Android',
vars.androidId && vars.androidRuntimeVersion ? `_(${vars.androidRuntimeVersion})_` : '',
Expand All @@ -195,10 +202,7 @@ function createMultipleQrSummary(updates: EasUpdate[], vars: ReturnType<typeof g
? `<a href="${vars.iosQR}"><img src="${vars.iosQR}" width="250px" height="250px" /></a>`
: null;

return `🚀 Expo preview is ready!
- Project → **${vars.projectSlug}**
- ${platformName}${platformValue}
return `${createSummaryHeader(updates, vars)}
${androidHeader} | ${iosHeader}
--- | ---
Expand Down
18 changes: 18 additions & 0 deletions tests/actions/preview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ describe(createSummary, () => {
`);
});

it('returns expected message for both platforms with custom app scheme', () => {
const customSchemeConfig = { ...fakeExpoConfig, scheme: 'expogithubaction' };
expect(createSummary(fakeUpdatesSingle, getVariables(customSchemeConfig, fakeUpdatesSingle)))
.toMatchInlineSnapshot(`
"🚀 Expo preview is ready!
- Project → **fake-project**
- Platforms → **android**, **ios**
- App Scheme → **expogithubaction**
- Runtime Version → **exposdk:47.0.0**
- **[More info](https://expo.dev/projects/fake-project-id/updates/fake-group-id)**
<a href="https://qr.expo.dev/eas-update?appScheme=expogithubaction&projectId=fake-project-id&groupId=fake-group-id"><img src="https://qr.expo.dev/eas-update?appScheme=expogithubaction&projectId=fake-project-id&groupId=fake-group-id" width="250px" height="250px" /></a>
> Learn more about [𝝠 Expo Github Action](https://github.com/expo/expo-github-action/tree/main/preview#example-workflows)"
`);
});

it('returns expected message for android only', () => {
const fakeUpdate = fakeUpdatesSingle.filter(update => update.platform === 'android');
expect(createSummary(fakeUpdate, getVariables(fakeExpoConfig, fakeUpdate))).toMatchInlineSnapshot(`
Expand Down

0 comments on commit 7902fca

Please sign in to comment.