Compare commits

...
5 changed files with 89 additions and 60 deletions

No files matched your search

+1 -1
View File
@@ -3,4 +3,4 @@
* text=auto
# These files are text and should be normalized (Convert crlf => lf)
build/** text eol=lf
build/** text eol=lf linguist-generated=true
+33 -23
View File
@@ -44535,6 +44535,7 @@ function collectContinuousDeployFingerprintInput() {
exports.collectContinuousDeployFingerprintInput = collectContinuousDeployFingerprintInput;
(0, worker_1.executeAction)(continuousDeployFingerprintAction);
async function continuousDeployFingerprintAction(input = collectContinuousDeployFingerprintInput()) {
const isInPullRequest = (0, github_1.hasPullContext)();
const config = await (0, project_1.loadProjectConfig)(input.workingDirectory);
const projectId = config.extra?.eas?.projectId;
if (!projectId) {
@@ -44547,14 +44548,16 @@ async function continuousDeployFingerprintAction(input = collectContinuousDeploy
const iosFingerprintHash = await getFingerprintHashForPlatformAsync({ cwd: input.workingDirectory, platform: 'ios' });
(0, core_1.info)(`Android fingerprint: ${androidFingerprintHash}`);
(0, core_1.info)(`iOS fingerprint: ${iosFingerprintHash}`);
(0, core_1.info)('Looking for builds with matching runtime version (fingerprint)...');
let androidBuildInfo = await getBuildInfoWithFingerprintAsync({
cwd: input.workingDirectory,
platform: 'android',
profile: input.profile,
fingerprintHash: androidFingerprintHash,
excludeExpiredBuilds: isInPullRequest,
});
if (androidBuildInfo) {
(0, core_1.info)(`Existing Android build found for fingerprint: ${androidBuildInfo.id}`);
(0, core_1.info)(`Existing Android build found with matching fingerprint: ${androidBuildInfo.id}`);
}
else {
(0, core_1.info)(`No existing Android build found for fingerprint, starting a new build...`);
@@ -44569,21 +44572,22 @@ async function continuousDeployFingerprintAction(input = collectContinuousDeploy
platform: 'ios',
profile: input.profile,
fingerprintHash: iosFingerprintHash,
excludeExpiredBuilds: isInPullRequest,
});
if (iosBuildInfo) {
(0, core_1.info)(`Existing iOS build found for fingerprint: ${iosBuildInfo.id}`);
(0, core_1.info)(`Existing iOS build found with matching fingerprint: ${iosBuildInfo.id}`);
}
else {
(0, core_1.info)(`No existing iOS build found for fingerprint, starting a new build...`);
iosBuildInfo = await createEASBuildAsync({ cwd: input.workingDirectory, platform: 'ios', profile: input.profile });
}
const builds = [androidBuildInfo, iosBuildInfo];
(0, core_1.info)(`Publishing EAS Update`);
(0, core_1.info)(`Publishing EAS Update...`);
const updates = await publishEASUpdatesAsync({
cwd: input.workingDirectory,
branch: input.branch,
});
if (!(0, github_1.hasPullContext)()) {
if (!isInPullRequest) {
(0, core_1.info)(`Skipped comment: action was not run from a pull request`);
}
else {
@@ -44605,8 +44609,10 @@ async function continuousDeployFingerprintAction(input = collectContinuousDeploy
exports.continuousDeployFingerprintAction = continuousDeployFingerprintAction;
async function getFingerprintHashForPlatformAsync({ cwd, platform, }) {
try {
const { stdout } = await (0, exec_1.getExecOutput)('npx', ['expo-updates', 'fingerprint:generate', '--platform', platform], {
const extraArgs = (0, core_1.isDebug)() ? ['--debug'] : [];
const { stdout } = await (0, exec_1.getExecOutput)('npx', ['expo-updates', 'fingerprint:generate', '--platform', platform, ...extraArgs], {
cwd,
silent: !(0, core_1.isDebug)(),
});
const { hash } = JSON.parse(stdout);
if (!hash || typeof hash !== 'string') {
@@ -44618,7 +44624,7 @@ async function getFingerprintHashForPlatformAsync({ cwd, platform, }) {
throw new Error(`Could not get fingerprint for project: ${String(error)}`);
}
}
async function getBuildInfoWithFingerprintAsync({ cwd, platform, profile, fingerprintHash, }) {
async function getBuildInfoWithFingerprintAsync({ cwd, platform, profile, fingerprintHash, excludeExpiredBuilds, }) {
let stdout;
try {
const execOutput = await (0, exec_1.getExecOutput)(await (0, io_1.which)('eas', true), [
@@ -44637,6 +44643,7 @@ async function getBuildInfoWithFingerprintAsync({ cwd, platform, profile, finger
'--non-interactive',
], {
cwd,
silent: !(0, core_1.isDebug)(),
});
stdout = execOutput.stdout;
}
@@ -44650,38 +44657,41 @@ async function getBuildInfoWithFingerprintAsync({ cwd, platform, profile, finger
if (!builds[0]) {
return null;
}
return builds[0];
const build = builds[0];
if (excludeExpiredBuilds) {
// if the build is expired or will expire within the next day,
// return null to trigger a new build
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
if (tomorrow > new Date(build.expirationDate)) {
return null;
}
}
return build;
}
async function createEASBuildAsync({ cwd, profile, platform, }) {
let stdout;
try {
const execOutput = await (0, exec_1.getExecOutput)(await (0, io_1.which)('eas', true), [
'build',
'--profile',
profile,
'--platform',
platform,
'--non-interactive',
'--json',
'--no-wait',
'--build-logger-level',
'debug',
], {
const extraArgs = (0, core_1.isDebug)() ? ['--build-logger-level', 'debug'] : [];
const execOutput = await (0, exec_1.getExecOutput)(await (0, io_1.which)('eas', true), ['build', '--profile', profile, '--platform', platform, '--non-interactive', '--json', '--no-wait', ...extraArgs], {
cwd,
silent: !(0, core_1.isDebug)(),
});
stdout = execOutput.stdout;
}
catch (error) {
throw new Error(`Could not run command eas build: ${String(error)}`);
}
return JSON.parse(stdout);
return JSON.parse(stdout)[0];
}
async function publishEASUpdatesAsync({ cwd, branch }) {
let stdout = '';
let stdout;
try {
({ stdout } = await (0, exec_1.getExecOutput)(await (0, io_1.which)('eas', true), ['update', '--auto', '--branch', branch, '--non-interactive', '--json'], {
const execOutput = await (0, exec_1.getExecOutput)(await (0, io_1.which)('eas', true), ['update', '--auto', '--branch', branch, '--non-interactive', '--json'], {
cwd,
}));
silent: !(0, core_1.isDebug)(),
});
stdout = execOutput.stdout;
}
catch (error) {
throw new Error(`Could not create a new EAS Update: ${String(error)}`);
+7 -8
View File
@@ -33,7 +33,7 @@
<br />
> **Warning**
> This sub action is experimental and might change without notice. Use it at your own risk.
> This sub action is still in development and might change without notice. It is not yet ready for use.
## Overview
@@ -78,12 +78,6 @@ When using the GitHub API, you always need to be authenticated.
This action tries to auto-authenticate using the [Automatic token authentication][link-gha-token] from GitHub.
You can overwrite the token by adding the `GITHUB_TOKEN` environment variable or add the **github-token** input.
<div align="center">
<br />
with :heart:&nbsp;<strong>Expo</strong>
<br />
</div>
## Example workflows
Before diving into the workflow examples, you should know the basics of GitHub Actions.
@@ -108,7 +102,6 @@ on:
types: [opened, synchronize]
env:
EXPO_STAGING: 1
EXPO_TOKEN: ${{ secrets.EXPO_TOKEN }}
jobs:
@@ -158,3 +151,9 @@ jobs:
profile: ${{ github.event_name != 'pull_request' && 'production' || 'development' }}
branch: ${{ github.event_name != 'pull_request' && 'production' || 'development' }}
```
<div align="center">
<br />
with :heart:&nbsp;<strong>Expo</strong>
<br />
</div>
+47 -28
View File
@@ -1,4 +1,4 @@
import { getInput, info, setFailed, setOutput } from '@actions/core';
import { getInput, info, isDebug, setFailed, setOutput } from '@actions/core';
import { getExecOutput } from '@actions/exec';
import { which } from '@actions/io';
import { ExpoConfig } from '@expo/config';
@@ -22,6 +22,8 @@ export function collectContinuousDeployFingerprintInput() {
executeAction(continuousDeployFingerprintAction);
export async function continuousDeployFingerprintAction(input = collectContinuousDeployFingerprintInput()) {
const isInPullRequest = hasPullContext();
const config = await loadProjectConfig(input.workingDirectory);
const projectId = config.extra?.eas?.projectId;
if (!projectId) {
@@ -37,14 +39,17 @@ export async function continuousDeployFingerprintAction(input = collectContinuou
info(`Android fingerprint: ${androidFingerprintHash}`);
info(`iOS fingerprint: ${iosFingerprintHash}`);
info('Looking for builds with matching runtime version (fingerprint)...');
let androidBuildInfo = await getBuildInfoWithFingerprintAsync({
cwd: input.workingDirectory,
platform: 'android',
profile: input.profile,
fingerprintHash: androidFingerprintHash,
excludeExpiredBuilds: isInPullRequest,
});
if (androidBuildInfo) {
info(`Existing Android build found for fingerprint: ${androidBuildInfo.id}`);
info(`Existing Android build found with matching fingerprint: ${androidBuildInfo.id}`);
} else {
info(`No existing Android build found for fingerprint, starting a new build...`);
androidBuildInfo = await createEASBuildAsync({
@@ -59,9 +64,10 @@ export async function continuousDeployFingerprintAction(input = collectContinuou
platform: 'ios',
profile: input.profile,
fingerprintHash: iosFingerprintHash,
excludeExpiredBuilds: isInPullRequest,
});
if (iosBuildInfo) {
info(`Existing iOS build found for fingerprint: ${iosBuildInfo.id}`);
info(`Existing iOS build found with matching fingerprint: ${iosBuildInfo.id}`);
} else {
info(`No existing iOS build found for fingerprint, starting a new build...`);
iosBuildInfo = await createEASBuildAsync({ cwd: input.workingDirectory, platform: 'ios', profile: input.profile });
@@ -69,14 +75,14 @@ export async function continuousDeployFingerprintAction(input = collectContinuou
const builds = [androidBuildInfo, iosBuildInfo];
info(`Publishing EAS Update`);
info(`Publishing EAS Update...`);
const updates = await publishEASUpdatesAsync({
cwd: input.workingDirectory,
branch: input.branch,
});
if (!hasPullContext()) {
if (!isInPullRequest) {
info(`Skipped comment: action was not run from a pull request`);
} else {
const messageId = `continuous-deploy-fingerprint-projectId:${projectId}`;
@@ -105,9 +111,15 @@ async function getFingerprintHashForPlatformAsync({
platform: 'ios' | 'android';
}): Promise<string> {
try {
const { stdout } = await getExecOutput('npx', ['expo-updates', 'fingerprint:generate', '--platform', platform], {
cwd,
});
const extraArgs = isDebug() ? ['--debug'] : [];
const { stdout } = await getExecOutput(
'npx',
['expo-updates', 'fingerprint:generate', '--platform', platform, ...extraArgs],
{
cwd,
silent: !isDebug(),
}
);
const { hash } = JSON.parse(stdout);
if (!hash || typeof hash !== 'string') {
throw new Error(`Invalid fingerprint output: ${stdout}`);
@@ -123,13 +135,15 @@ async function getBuildInfoWithFingerprintAsync({
platform,
profile,
fingerprintHash,
excludeExpiredBuilds,
}: {
cwd: string;
platform: 'ios' | 'android';
profile: string;
fingerprintHash: string;
excludeExpiredBuilds: boolean;
}): Promise<BuildInfo | null> {
let stdout;
let stdout: string;
try {
const execOutput = await getExecOutput(
await which('eas', true),
@@ -150,6 +164,7 @@ async function getBuildInfoWithFingerprintAsync({
],
{
cwd,
silent: !isDebug(),
}
);
stdout = execOutput.stdout;
@@ -166,7 +181,19 @@ async function getBuildInfoWithFingerprintAsync({
return null;
}
return builds[0];
const build = builds[0] as BuildInfo;
if (excludeExpiredBuilds) {
// if the build is expired or will expire within the next day,
// return null to trigger a new build
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
if (tomorrow > new Date(build.expirationDate)) {
return null;
}
}
return build;
}
async function createEASBuildAsync({
@@ -178,24 +205,15 @@ async function createEASBuildAsync({
profile: string;
platform: 'ios' | 'android';
}): Promise<BuildInfo> {
let stdout;
let stdout: string;
try {
const extraArgs = isDebug() ? ['--build-logger-level', 'debug'] : [];
const execOutput = await getExecOutput(
await which('eas', true),
[
'build',
'--profile',
profile,
'--platform',
platform,
'--non-interactive',
'--json',
'--no-wait',
'--build-logger-level',
'debug',
],
['build', '--profile', profile, '--platform', platform, '--non-interactive', '--json', '--no-wait', ...extraArgs],
{
cwd,
silent: !isDebug(),
}
);
stdout = execOutput.stdout;
@@ -203,20 +221,21 @@ async function createEASBuildAsync({
throw new Error(`Could not run command eas build: ${String(error)}`);
}
return JSON.parse(stdout);
return JSON.parse(stdout)[0];
}
async function publishEASUpdatesAsync({ cwd, branch }: { cwd: string; branch: string }): Promise<EasUpdate[]> {
let stdout = '';
let stdout: string;
try {
({ stdout } = await getExecOutput(
const execOutput = await getExecOutput(
await which('eas', true),
['update', '--auto', '--branch', branch, '--non-interactive', '--json'],
{
cwd,
silent: !isDebug(),
}
));
);
stdout = execOutput.stdout;
} catch (error: unknown) {
throw new Error(`Could not create a new EAS Update: ${String(error)}`);
}
+1
View File
@@ -42,6 +42,7 @@ export type BuildInfo = {
sdkVersion: string;
appVersion: string;
gitCommitHash: string;
expirationDate: string;
};
export const appPlatformDisplayNames: Record<AppPlatform, string> = {