diff --git a/.eas/workflows/pr-builds.yml b/.eas/workflows/pr-builds.yml new file mode 100644 index 0000000..501b355 --- /dev/null +++ b/.eas/workflows/pr-builds.yml @@ -0,0 +1,31 @@ +name: PR builds + +# Builds the release configuration for both platforms on every pull request to +# main, so a change that breaks prebuild or a native compile fails on the PR +# instead of at store-build time. Uses the "pr" profile in eas.json: an Android +# APK signed with the template debug keystore and an iOS simulator build, so it +# needs no signing credentials. JS checks (typecheck, lint, jest) stay in +# .github/workflows/ci.yml. + +on: + pull_request: + branches: ['main'] + +concurrency: + cancel_in_progress: true + group: ${{ workflow.filename }}-${{ github.ref }} + +jobs: + build_android: + name: Build Android (APK) + type: build + params: + platform: android + profile: pr + + build_ios: + name: Build iOS (simulator) + type: build + params: + platform: ios + profile: pr diff --git a/eas.json b/eas.json index f62a4b7..23df4ac 100644 --- a/eas.json +++ b/eas.json @@ -11,6 +11,16 @@ "preview": { "distribution": "internal" }, + "pr": { + "distribution": "internal", + "android": { + "buildType": "apk", + "withoutCredentials": true + }, + "ios": { + "simulator": true + } + }, "production": { "autoIncrement": true } diff --git a/tests/easWorkflows.test.ts b/tests/easWorkflows.test.ts new file mode 100644 index 0000000..4a8a97e --- /dev/null +++ b/tests/easWorkflows.test.ts @@ -0,0 +1,40 @@ +import { readdirSync, readFileSync } from 'fs'; +import { join } from 'path'; + +// EAS workflow build jobs name an eas.json profile. A typo or a renamed profile +// only fails on EAS, after the PR is open. `eas workflow:validate` catches it +// too but needs a login, so this is the offline gate. +const ROOT = join(__dirname, '..'); +const DIR = join(ROOT, '.eas', 'workflows'); +const eas = JSON.parse(readFileSync(join(ROOT, 'eas.json'), 'utf8')); + +const workflows = readdirSync(DIR).filter((f) => /\.ya?ml$/.test(f)); +const profilesIn = (yml: string) => [...yml.matchAll(/^\s+profile:\s*['"]?([\w-]+)/gm)].map((m) => m[1]); + +describe('EAS workflows', () => { + it.each(workflows)('%s: every build profile exists in eas.json', (file) => { + for (const p of profilesIn(readFileSync(join(DIR, file), 'utf8'))) { + expect(Object.keys(eas.build)).toContain(p); + } + }); + + describe('pr-builds.yml', () => { + const yml = readFileSync(join(DIR, 'pr-builds.yml'), 'utf8'); + + it('runs on pull requests to main and builds both platforms with the pr profile', () => { + expect(yml).toMatch(/^on:\n\s+pull_request:\n\s+branches: \['main'\]/m); + expect(yml).toMatch(/platform: android\n\s+profile: pr/); + expect(yml).toMatch(/platform: ios\n\s+profile: pr/); + }); + + // PR builds must not need signing credentials: none are set up for iOS, + // and a store keystore has no business signing throwaway PR artifacts. + it('pr profile needs no signing credentials', () => { + const pr = eas.build.pr; + expect(pr.android).toEqual({ buildType: 'apk', withoutCredentials: true }); + expect(pr.ios).toEqual({ simulator: true }); + expect(pr.developmentClient).toBeUndefined(); + expect(pr.autoIncrement).toBeUndefined(); + }); + }); +});