Simplify CI setup #10
Workflow file for this run
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: | ||
workflow_call: | ||
defaults: | ||
run: | ||
shell: bash -l {0} | ||
env: | ||
flavour: oss | ||
config: debug | ||
api-level: 28 | ||
jobs: | ||
Build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 30 | ||
permissions: | ||
statuses: write | ||
pull-requests: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup NPM | ||
run: | | ||
nvm install | ||
npm install --global gulp-cli | ||
nvm use | ||
npm ci | ||
- name: Danger | ||
uses: docker://ghcr.io/danger/danger-kotlin:1.2.0 | ||
if: ${{ github.event_name == 'pull_request' }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Set up JDK | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '17' | ||
distribution: 'adopt' | ||
cache: gradle | ||
- name: Validate Gradle Wrapper | ||
uses: gradle/wrapper-validation-action@v1 | ||
- name: Build | ||
run: | | ||
./gradlew assemble${{ env.flavour }}${{ env.config }} -PdisablePreDex | ||
- name: Tokens check | ||
run: | | ||
./gradlew generateTokens -PdisablePreDex | ||
./scripts/check-no-changes.sh | ||
- name: Detekt check | ||
run: ./gradlew detekt -PdisablePreDex | ||
- name: Lint check | ||
run: ./gradlew lint${{ env.flavour }}${{ env.config }} -PdisablePreDex | ||
- name: Unit Tests | ||
run: ./gradlew test${{ env.flavour }}${{ env.config }}UnitTest -PdisablePreDex | ||
Android: | ||
name: Android tests | ||
runs-on: macos-latest | ||
timeout-minutes: 30 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Set up JDK | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '17' | ||
distribution: 'adopt' | ||
cache: gradle | ||
- name: AVD cache | ||
uses: actions/cache@v3 | ||
id: avd-cache | ||
with: | ||
path: | | ||
~/.android/avd/* | ||
~/.android/adb* | ||
key: avd-${{ env.api-level }} | ||
- name: create AVD and generate snapshot for caching | ||
if: steps.avd-cache.outputs.cache-hit != 'true' | ||
uses: reactivecircus/android-emulator-runner@v2 | ||
with: | ||
profile: Nexus 4 | ||
sdcard-path-or-size: 512M | ||
api-level: ${{ env.api-level }} | ||
force-avd-creation: false | ||
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none | ||
avd-name: avd-x86-default-28 | ||
disable-animations: false | ||
script: echo "Generated AVD snapshot for caching." | ||
- name: Android Tests | ||
uses: reactivecircus/android-emulator-runner@v2 | ||
with: | ||
profile: Nexus 4 | ||
sdcard-path-or-size: 512M | ||
api-level: ${{ env.api-level }} | ||
force-avd-creation: false | ||
avd-name: avd-x86-default-28 | ||
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none | ||
disable-animations: true | ||
script: | | ||
# uninstall first to avoid signature error. see https://github.com/ReactiveCircus/android-emulator-runner/issues/319 | ||
adb uninstall net.skyscanner.backpack || : | ||
adb uninstall net.skyscanner.backpack.test || : | ||
adb uninstall net.skyscanner.backpack.compose.test || : | ||
adb uninstall net.skyscanner.backpack.common.test || : | ||
./gradlew :Backpack:connected${{ env.config }}AndroidTest :backpack-compose:connected${{ env.config }}AndroidTest :backpack-common:connected${{ env.config }}AndroidTest | ||
Screenshots: | ||
name: Screenshots tests | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
contents: write | ||
timeout-minutes: 20 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Set up JDK | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '17' | ||
distribution: 'adopt' | ||
cache: gradle | ||
- name: Screenshot Tests | ||
id: screenshotTests | ||
run: | | ||
./scripts/record_screenshot_tests.sh | ||
changedFiles=`git status --porcelain` && echo "CHANGED_FILES=${changedFiles//$'\n'/'%0A'}" >> $GITHUB_OUTPUT | ||
- name: Check snapshot changes | ||
id: checkSnapshotChanges | ||
if: ${{ github.event_name != 'pull_request' }} | ||
run: ./scripts/check-no-changes.sh | ||
- name: Commit changes | ||
if: ${{ github.event_name == 'pull_request' && steps.screenshotTests.outputs.CHANGED_FILES != '' }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
git config --local user.email "github-actions[bot]@users.noreply.github.com" | ||
git config --local user.name "github-actions[bot]" | ||
git remote set-url origin https://x-access-token:[email protected]/${{ github.repository }} | ||
git fetch origin $GITHUB_HEAD_REF | ||
git checkout $GITHUB_HEAD_REF | ||
git add app/screenshots/* | ||
git diff-index --quiet HEAD || git commit -m "Updated snapshots'" | ||
git push |