Appetize Validation #756
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Appetize Validation | |
on: | |
workflow_dispatch: | |
schedule: | |
# daily at 14:00h UTC | |
- cron: 0 14 * * * | |
jobs: | |
website: | |
name: Resolve website config | |
runs-on: ubuntu-latest | |
outputs: | |
config: ${{ steps.config.outputs.result }} | |
steps: | |
- name: π Setup repository | |
uses: actions/checkout@v3 | |
- name: π Setup website | |
uses: ./.github/actions/setup-website | |
# This command might fail on other dependencies, we just want to peek in the configs | |
- name: π·ββοΈ Build sdk config | |
working-directory: website | |
continue-on-error: true | |
run: yarn tsc src/client/configs/sdk.tsx > /dev/null | |
# Resolve the SDK configuration from website to validate against Appetize. | |
# With this, we can check if the versions and default version are available in Appetize. | |
- name: π΅οΈ Resolve sdk config | |
uses: actions/github-script@v6 | |
id: config | |
with: | |
script: | | |
const config = require('./website/src/client/configs/sdk') | |
const versions = Object.keys(config.versions) | |
core.info(`Resolved supported website SDKs`) | |
for (const version of versions) { | |
core.info(` - ${version} ${version === config.DEFAULT_SDK_VERSION ? '(default)' : ''}`) | |
} | |
return { versions, default: config.DEFAULT_SDK_VERSION } | |
appetize: | |
needs: website | |
name: Validate ${{ matrix.platform }} on ${{ matrix.appetize }} | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
# Use capitalized names for envvars | |
appetize: ['MAIN', 'EMBED'] | |
platform: ['ANDROID', 'IOS'] | |
steps: | |
- name: π Setup Node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 16.x | |
- name: π Download Appetize information | |
# Redirect output because the endpoint returns the public and private app keys | |
run: curl --silent --fail -o appetize.json https://[email protected]/v1/apps/$APP > /dev/null | |
env: | |
TOKEN: ${{ secrets[format('APPETIZE_{0}_TOKEN', matrix.appetize)] }} | |
APP: ${{ secrets[format('APPETIZE_{0}_{1}', matrix.appetize, matrix.platform)] }} | |
- name: π Download SDK information | |
run: curl --silent -o versions.json https://exp.host/--/api/v2/versions | |
- name: π§Ά Install semver | |
run: yarn add semver | |
- name: Validate version | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const semver = require('semver') | |
const { appVersionName: appetizeVersion } = require('./appetize.json') | |
const { sdkVersions } = require('./versions.json') | |
const platform = '${{ matrix.platform }}'.toLowerCase() | |
const appetize = '${{ matrix.appetize }}'.toLowerCase() | |
const website = JSON.parse('${{ needs.website.outputs.config }}') | |
const websiteSdk = sdkVersions[website.default] | |
const websiteVersion = (websiteSdk || {})[`${platform}ClientVersion`] | |
if (!websiteSdk) throw new Error(`Could not find default SDK "${website.default}"`) | |
if (!websiteVersion) throw new Error(`Could not find default ${platform} version for SDK "${website.default}"`) | |
const versionDiff = semver.diff(appetizeVersion, websiteVersion) | |
const appetizeIsNewer = semver.gt(appetizeVersion, websiteVersion) | |
const appetizeInfo = `Appetize (${appetize}) build for ${platform} (${appetizeVersion})` | |
const errorInfo = `${appetizeInfo} is outdated, website default is SDK ${website.default} (${websiteVersion})` | |
if (versionDiff === null) { | |
core.info(`${appetizeInfo} is up to date for SDK ${website.default}!`) | |
} else if (appetizeIsNewer) { | |
core.warning(`${appetizeInfo} is running a newer version, found SDK ${website.default} (${websiteVersion})`) | |
} else if (versionDiff === 'patch') { | |
core.warning(errorInfo) | |
} else { | |
throw new Error(errorInfo) | |
} | |
- name: π’ Notify on Slack | |
uses: 8398a7/action-slack@v3 | |
if: failure() | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_SNACK }} | |
with: | |
channel: '#snack' | |
status: ${{ job.status }} | |
author_name: Validate Appetize ${{ matrix.platform }} on ${{ matrix.appetize }} | |
fields: author |