enh(ci): Refactor build workflow and build ios app #1625
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: Build | |
on: | |
pull_request: | |
push: | |
branches: | |
- develop | |
- master | |
jobs: | |
js: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [20.x] | |
npm-version: [10.x] | |
name: node${{ matrix.node-versions }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up node ${{ matrix.node-version }} | |
uses: actions/setup-node@v1 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Set up npm ${{ matrix.npm-version }} | |
run: npm i -g npm@"${{ matrix.npm-version }}" | |
- name: Cache node modules | |
uses: actions/cache@v1 | |
env: | |
cache-name: cache-node-modules | |
with: | |
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS | |
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-build-${{ env.cache-name }}- | |
${{ runner.os }}-build- | |
${{ runner.os }}- | |
- name: Install dependencies | |
run: | | |
npm ci -f | |
- name: Install dependencies & build | |
run: | | |
npm run build-release --if-present | |
- name: Save context | |
uses: buildjet/cache/save@v3 | |
with: | |
key: build-context-${{ github.run_id }} | |
path: ./ | |
android: | |
needs: js | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
java-version: [ 17 ] | |
name: java${{ matrix.java-version }} | |
steps: | |
- uses: actions/setup-java@v4 | |
with: | |
distribution: 'oracle' | |
java-version: ${{ matrix.java-version }} | |
- name: Restore context | |
uses: buildjet/cache/restore@v3 | |
with: | |
fail-on-cache-miss: true | |
key: build-context-${{ github.run_id }} | |
path: ./ | |
- name: Build android | |
run: | | |
npx cap sync | |
cd android | |
chmod +x gradlew | |
./gradlew assemble | |
ios: | |
needs: js | |
runs-on: macos-latest | |
name: ios | |
steps: | |
- name: Restore context | |
uses: buildjet/cache/restore@v3 | |
with: | |
fail-on-cache-miss: true | |
key: build-context-${{ github.run_id }} | |
path: ./ | |
- name: setup-cocoapods | |
uses: maxim-lobanov/setup-cocoapods@v1 | |
with: | |
podfile-path: ios/App/Podfile.lock | |
- uses: maxim-lobanov/setup-xcode@v1 | |
with: | |
xcode-version: latest-stable | |
- name: Build android | |
env: | |
scheme: "Floccus" | |
platform: "iOS Simulator" | |
run: | | |
npx cap sync | |
device=`xcrun xctrace list devices 2>&1 | grep -oE 'iPhone.*?[^\(]+' | head -1 | awk '{$1=$1;print}' | sed -e "s/ Simulator$//"` | |
if [ $scheme = default ]; then scheme=$(cat default); fi | |
if [ "`ls -A | grep -i \\.xcworkspace\$`" ]; then filetype_parameter="workspace" && file_to_build="`ls -A | grep -i \\.xcworkspace\$`"; else filetype_parameter="project" && file_to_build="`ls -A | grep -i \\.xcodeproj\$`"; fi | |
file_to_build=`echo $file_to_build | awk '{$1=$1;print}'` | |
xcodebuild build-for-testing -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=$platform,name=$device" | |
summary: | |
runs-on: ubuntu-latest | |
needs: [ js, android, ios ] | |
if: always() | |
name: build-summary | |
steps: | |
- name: Summary status | |
run: if ${{ needs.js.result != 'success' || ( needs.android.result != 'success' && needs.selenium.result != 'skipped' ) || ( needs.ios.result != 'success' && needs.ios.result != 'skipped' ) }}; then exit 1; fi |