Skip to content

Refactor if statements to match .NET #1

Refactor if statements to match .NET

Refactor if statements to match .NET #1

# Check if we actually need to build any of the packages and if not, this job will prepare the artifacts
# required by downstream jobs.
#
# Cache hits are detected by hashing all relevant files. This is required as we might be running CI on
# multiple commits on the same branch.
#
# There is a small chance the cache gets invalidated between this check and downstream jobs run.
# This is acceptable as the work-around is just rerunning the build.
#
# Some notes on caching and artifacts:
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows
# - Caches are restricted to current back and fall back to default branch (master)
# - Caches cannot be downloaded to a new location.
# - Artifacts are restricted to current workflow.
#
name: Check cache
on:
workflow_call:
outputs:
version-label:
value: ${{ jobs.check-cache.outputs.version-label }}
packages-jvm-cache-hit:
value: ${{ jobs.check-cache.outputs.packages-jvm-cache-hit }}
packages-android-cache-hit:
value: ${{ jobs.check-cache.outputs.packages-android-cache-hit }}
android-test-base-apk-cache-hit:
value: ${{ jobs.check-cache.outputs.android-test-base-apk-cache-hit }}
packages-macos-x64-cache-hit:
value: ${{ jobs.check-cache.outputs.packages-macos-x64-cache-hit }}
packages-macos-arm64-cache-hit:
value: ${{ jobs.check-cache.outputs.packages-macos-arm64-cache-hit }}
packages-ios-x64-cache-hit:
value: ${{ jobs.check-cache.outputs.packages-ios-x64-cache-hit }}
packages-ios-arm64-cache-hit:
value: ${{ jobs.check-cache.outputs.packages-ios-arm64-cache-hit }}
jni-swig-stub-cache-hit:
value: ${{ jobs.check-cache.outputs.jni-swig-stub-cache-hit }}
jni-linux-lib-cache-hit:
value: ${{ jobs.check-cache.outputs.jni-linux-lib-cache-hit }}
jni-windows-lib-cache-hit:
value: ${{ jobs.check-cache.outputs.jni-windows-lib-cache-hit }}
packages-sha:
value: ${{ jobs.check-cache.outputs.packages-sha }}
benchmarks-sha:
value: ${{ jobs.check-cache.outputs.benchmarks-sha }}
core-commit-sha:
value: ${{ jobs.check-cache.outputs.core-commit-sha }}
jobs:
check-cache:
runs-on: ubuntu-latest
name: Check cache
env:
CACHE_SKIP_SAVE: true
outputs:
version-label: ${{ steps.find-library-version.outputs.label }}
packages-jvm-cache-hit: ${{ steps.jvm-cache.outputs.cache-hit }}
packages-android-cache-hit: ${{ steps.android-cache.outputs.cache-hit }}
android-test-base-apk-cache-hit: ${{ steps.android-test-base-apk.outputs.cache-hit }}
packages-macos-x64-cache-hit: ${{ steps.macos-x64-cache.outputs.cache-hit }}
packages-macos-arm64-cache-hit: ${{ steps.macos-arm64-cache.outputs.cache-hit }}
packages-ios-x64-cache-hit: ${{ steps.ios-x64-cache.outputs.cache-hit }}
packages-ios-arm64-cache-hit: ${{ steps.ios-arm64-cache.outputs.cache-hit }}
jni-swig-stub-cache-hit: ${{ steps.jni-swig-stub-cache.outputs.cache-hit }}
jni-linux-lib-cache-hit: ${{ steps.jni-linux-lib-cache.outputs.cache-hit }}
jni-windows-lib-cache-hit: ${{ steps.jni-windows-lib-cache.outputs.cache-hit }}
packages-sha: ${{ steps.packages-cache-key.outputs.sha }}
benchmarks-sha: ${{ steps.calculate-benchmarks-cache-key.outputs.sha }}
core-commit-sha: ${{ steps.calculate-core-commmit-sha.outputs.commit }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: "recursive"
- name: Find library version
id: find-library-version
run: |
version=$(grep "const val version" buildSrc/src/main/kotlin/Config.kt | cut -d \" -f2)
echo "label=$version" >> $GITHUB_OUTPUT
# This also include changes to Realm Core as they are hashed as part of `/packages/external/core`
- name: Calculate ./packages SHAs
id: packages-cache-key
run: echo "sha=${{ hashFiles('./packages/**', './buildSrc/**', '!./packages/test-base/**', '!./packages/test-sync/**') }}" >> $GITHUB_OUTPUT
- name: Calculate ./benchmarks SHAs
id: calculate-benchmarks-cache-key
run: echo "sha=${{ hashFiles('./benchmarks/**') }}" >> $GITHUB_OUTPUT
- name: Calculate Realm Core commit SHA
id: calculate-core-commit-sha
working-directory: packages/external/core
run: echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
#
# For each specific package we need to perform 3 steps:
#
# 1. Check if a cache is available and download it if it is.
# 2. If (1), store this cache as an artifact for jobs downstream to use.
# 3. Cleanup the build folder. This is required so we can download the next
# platform into a fresh cache location. It does not look possible to download
# a cache into a different location.
#
# TODO There doesn't seem to be a good way to check if a cache key exists without download it.
# https://github.com/actions/cache/issues/321
#
# TODO Create a custom action for this until we have a work-around?
#
#
# JVM (All platforms)
#
- name: Check JVM cache
id: jvm-cache
uses: cmelchior/cache@main
with:
path: ./packages/build/m2-buildrepo
key: packages-m2-jvm-sync-${{ steps.packages-cache-key.outputs.sha }}
- name: Save JVM packages
uses: actions/upload-artifact@v3
if: !cancelled() && steps.jvm-cache.outputs.cache-hit == 'true'

Check failure on line 125 in .github/workflows/include-check-cache.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/include-check-cache.yml

Invalid workflow file

You have an error in your yaml syntax on line 125
with:
name: packages-jvm-${{ steps.find-library-version.outputs.label }}
path: ./packages/build/m2-buildrepo/**/*
retention-days: 1
- name: Delete downloaded JVM cache files
id: delete-cache-jvm
uses: JesseTG/[email protected]
if: !cancelled() && steps.jvm-cache.outputs.cache-hit == 'true'
with:
path: ./packages/build/m2-buildrepo
#
# JNI Stub (JVM)
#
- name: Check JNI Swig stub cache
id: jni-swig-stub-cache
uses: cmelchior/cache@main
with:
path: ./packages/jni-swig-stub/build/generated/sources/jni
key: jni-swig-stubs-${{ steps.packages-cache-key.outputs.sha }}
- name: Save JNI Stub packages
uses: actions/upload-artifact@v3
if: !cancelled() && steps.jni-swig-stub-cache.outputs.cache-hit == 'true'
with:
name: jni-stub-${{ steps.find-library-version.outputs.label }}
path: ./packages/jni-swig-stub/build/generated/sources/jni/*
retention-days: 1
- name: Delete downloaded JVM cache files
id: delete-cache-jni-stub
uses: JesseTG/[email protected]
if: !cancelled() && steps.jni-swig-stub-cache.outputs.cache-hit == 'true'
with:
path: ./packages/jni-swig-stub/build/generated/sources/jni
#
# JNI Linux Lib
#
- name: Check JNI Linux lib cache
id: jni-linux-lib-cache
uses: cmelchior/cache@main
with:
path: ./packages/cinterop/src/jvmMain/linux-build-dir
key: jni-linux-lib-${{ steps.packages-cache-key.outputs.sha }}
- name: Save JNI Linux lib package
uses: actions/upload-artifact@v3
if: !cancelled() && steps.jni-linux-lib-cache.outputs.cache-hit == 'true'
with:
name: jni-linux-lib-${{ steps.find-library-version.outputs.label }}
path: ./packages/cinterop/src/jvmMain/linux-build-dir/**/*
retention-days: 1
- name: Delete downloaded JVM cache files
id: delete-cache-linux-lib
uses: JesseTG/[email protected]
if: !cancelled() && steps.jni-linux-lib-cache.outputs.cache-hit == 'true'
with:
path: ./packages/cinterop/src/jvmMain/linux-build-dir
#
# Android
#
- name: Check Android cache
id: android-cache
uses: cmelchior/cache@main
with:
path: ./packages/build/m2-buildrepo
key: packages-m2-android-sync-${{ steps.packages-cache-key.outputs.sha }}
- name: Save Android packages
uses: actions/upload-artifact@v3
if: !cancelled() && steps.android-cache.outputs.cache-hit == 'true'
with:
name: packages-android-${{ steps.find-library-version.outputs.label }}
path: ./packages/build/m2-buildrepo/**/*
retention-days: 1
- name: Delete downloaded Android cache files
id: delete-cache-android
uses: JesseTG/[email protected]
if: !cancelled() && steps.android-cache.outputs.cache-hit == 'true'
with:
path: ./packages/build/m2-buildrepo
#
# Android Base Test APK
#
- name: Check Android Test APK
id: android-test-base-apk
uses: cmelchior/cache@main
with:
path: ./packages/test-base/build/outputs/apk/androidTest/debug/test-base-debug-androidTest.apk
key: android-base-test-apk-key-${{ steps.packages-cache-key.outputs.sha }}
- name: Save Android Test APK
uses: actions/upload-artifact@v3
if: !cancelled() && steps.android-test-base-apk.outputs.cache-hit == 'true'
with:
name: android-base-test-apk-${{ steps.find-library-version.outputs.label }}
path: ./packages/test-base/build/outputs/apk/androidTest/debug/test-base-debug-androidTest.apk
retention-days: 1
- name: Delete Android Test APK cache files
id: delete-cache-android-base-test-apk
uses: JesseTG/[email protected]
if: !cancelled() && steps.android-test-base-apk.outputs.cache-hit == 'true'
with:
path: ./packages/test-base/build/outputs/apk/androidTest/debug/test-base-debug-androidTest.apk
#
# MacOS arm64
#
- name: Check MacOS arm64 cache
id: macos-arm64-cache
uses: cmelchior/cache@main
with:
path: ./packages/build/m2-buildrepo
key: packages-m2-macos-arm64-sync-${{ steps.packages-cache-key.outputs.sha }}
- name: Save MacOS arm64 packages
uses: actions/upload-artifact@v3
if: !cancelled() && steps.macos-arm64-cache.outputs.cache-hit == 'true'
with:
name: packages-macos-arm64-${{ steps.find-library-version.outputs.label }}
path: ./packages/build/m2-buildrepo/**/*
retention-days: 1
- name: Delete downloaded MacOS arm64 cache files
id: delete-cache-macos-arm64
uses: JesseTG/[email protected]
if: !cancelled() && steps.macos-arm64-cache.outputs.cache-hit == 'true'
with:
path: ./packages/build/m2-buildrepo
#
# MacOS x64
#
- name: Check MacOS X64 cache
id: macos-x64-cache
uses: cmelchior/cache@main
with:
path: ./packages/build/m2-buildrepo
key: packages-m2-macos-x64-sync-${{ steps.packages-cache-key.outputs.sha }}
- name: Save MacOS x64 packages
uses: actions/upload-artifact@v3
if: !cancelled() && steps.macos-x64-cache.outputs.cache-hit == 'true'
with:
name: packages-macos-x64-${{ steps.find-library-version.outputs.label }}
path: ./packages/build/m2-buildrepo/**/*
retention-days: 1
- name: Delete downloaded MacOS x64 cache files
id: delete-cache-macos-x64
uses: JesseTG/[email protected]
if: !cancelled() && steps.macos-x64-cache.outputs.cache-hit == 'true'
with:
path: ./packages/build/m2-buildrepo
#
# iOS arm64
#
- name: Check iOS arm64 cache
id: ios-arm64-cache
uses: cmelchior/cache@main
with:
path: ./packages/build/m2-buildrepo
key: packages-m2-ios-arm64-sync-${{ steps.packages-cache-key.outputs.sha }}
- name: Save iOS arm64 packages
uses: actions/upload-artifact@v3
if: !cancelled() && steps.ios-arm64-cache.outputs.cache-hit == 'true'
with:
name: packages-ios-arm64-${{ steps.find-library-version.outputs.label }}
path: ./packages/build/m2-buildrepo/**/*
retention-days: 1
- name: Delete downloaded iOS arm64 cache files
id: delete-cache-ios-arm64
uses: JesseTG/[email protected]
if: !cancelled() && steps.ios-arm64-cache.outputs.cache-hit == 'true'
with:
path: ./packages/build/m2-buildrepo
#
# iOS x64
#
- name: Check iOS X64 cache
id: ios-x64-cache
uses: cmelchior/cache@main
with:
path: ./packages/build/m2-buildrepo
key: packages-m2-ios-x64-sync-${{ steps.packages-cache-key.outputs.sha }}
- name: Save iOS x64 packages
uses: actions/upload-artifact@v3
if: !cancelled() && steps.ios-x64-cache.outputs.cache-hit == 'true'
with:
name: packages-ios-x64-${{ steps.find-library-version.outputs.label }}
path: ./packages/build/m2-buildrepo/**/*
retention-days: 1
- name: Delete downloaded iOS x64 cache files
id: delete-cache-ios-x64
uses: JesseTG/[email protected]
if: !cancelled() && steps.ios-x64-cache.outputs.cache-hit == 'true'
with:
path: ./packages/build/m2-buildrepo
#
# JNI Windows Lib
#
- name: Check JNI Windows lib cache
id: jni-windows-lib-cache
uses: cmelchior/cache@main
with:
path: ./packages/cinterop/src/jvmMain/windows-build-dir
key: jni-windows-lib-${{ steps.packages-cache-key.outputs.sha }}
enableCrossOsArchive: true
- name: Save JNI Windows lib package
uses: actions/upload-artifact@v3
if: !cancelled() && steps.jni-windows-lib-cache.outputs.cache-hit == 'true'
with:
name: jni-windows-lib-${{ needs.check-cache.outputs.version-label }}
path: ./packages/cinterop/src/jvmMain/windows-build-dir/Release/realmc.dll
retention-days: 1
- name: Delete downloaded JNI Windows lib cache files
id: delete-cache-windows-lib
uses: JesseTG/[email protected]
if: !cancelled() && steps.jni-windows-lib-cache.outputs.cache-hit == 'true'
with:
path: ./packages/cinterop/src/jvmMain/windows-build-dir