Skip to content

Commit

Permalink
Abstract workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
jheng-hao-lin-cko committed Oct 16, 2023
1 parent ba6c2b3 commit 17de1b0
Show file tree
Hide file tree
Showing 12 changed files with 301 additions and 44 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/android-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
on:
workflow_call:
inputs:
module:
description: 'Module to run'
required: true
type: string
jobs:
android-lint:
uses: ./.github/workflows/gradle-task.yml
with:
module: ${{ inputs.module }}
task: lint
task-name: Run Android Lint Check
18 changes: 18 additions & 0 deletions .github/workflows/assemble-module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on:
workflow_call:
inputs:
module:
description: 'Module to run'
required: true
type: string
variant:
description: 'Variant to build'
required: true
type: string
jobs:
assemble:
uses: ./.github/workflows/gradle-task.yml
with:
module: ${{ inputs.module }}
task: assemble${{inputs.variant}}
task-name: Assemble ${{inputs.module}} - ${{inputs.variant}}
40 changes: 40 additions & 0 deletions .github/workflows/gradle-task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
on:
workflow_call:
inputs:
module:
description: 'Module to run'
required: true
type: string
task:
description: 'Task to run'
required: true
type: string
task-name:
description: 'Task Name'
required: true
type: string

jobs:
task:
name: ${{ inputs.task-name }}
runs-on: [ self-hosted, cko-mobile-default-runners-github-runners ]
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Cache Gradle and wrapper
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
- name: Run unit tests with Gradle
run: ./gradlew :${{ inputs.module }}:${{ inputs.task }}
14 changes: 14 additions & 0 deletions .github/workflows/ktlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
on:
workflow_call:
inputs:
module:
description: 'Module to run'
required: true
type: string
jobs:
ktlint:
uses: ./.github/workflows/gradle-task.yml
with:
module: ${{ inputs.module }}
task: ktlint
task-name: Run Ktlint Check
53 changes: 10 additions & 43 deletions .github/workflows/ui-test.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
name: UI Test

on:
pull_request:
types: [ opened, synchronize, reopened ]
branches: [ "**" ]
workflow_call:
inputs:
module:
description: 'Module to run'
required: true
type: string

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
connected-check:
name: Run Connected Check
connected-android-tests:
name: Run Connected Android Tests
# Run on macOS because we need to run the emulator and the emulator is not supported on Linux
runs-on: macos-latest
strategy:
Expand Down Expand Up @@ -44,41 +47,5 @@ jobs:
- name: Launch Emulator
run: chmod +x ./scripts/launch-emulator.sh && ./scripts/launch-emulator.sh

- name: Run UI Test
run: ./gradlew connectedCheck --stacktrace
frames-android-tests:
name: Run Frames Android Tests
# Run on macOS because we need to run the emulator and the emulator is not supported on Linux
runs-on: macos-latest
strategy:
fail-fast: true

steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Cache Gradle and wrapper
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}

- name: Launch Emulator
run: chmod +x ./scripts/launch-emulator.sh && ./scripts/launch-emulator.sh

- name: Run UI Test
run: ./gradlew connectedDebugAndroidTest --stacktrace
- name: Run UI Test on ${{ inputs.module }}
run: ./gradlew :${{ inputs.module }}:connectedAndroidTest --stacktrace
14 changes: 14 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
on:
workflow_call:
inputs:
module:
description: 'Module to run'
required: true
type: string
jobs:
unit-test:
uses: ./.github/workflows/gradle-task.yml
with:
module: ${{ inputs.module }}
task: test
task-name: Run Unit Tests
77 changes: 77 additions & 0 deletions .github/workflows/verification-flow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Verification

on:
workflow_call:
inputs:
module:
description: 'Module to run'
required: true
type: string
run-android-lint:
description: 'Should Run Android Lint'
required: false
type: boolean
default: false
run-ktlint:
description: 'Should Run Ktlint'
required: false
type: boolean
default: false
run-assemble:
description: 'Should Run Assemble'
required: false
type: boolean
default: false
assemble-variant:
description: 'Variant to Run Assemble'
required: false
type: string
default: ''
run-unit-test:
description: 'Should Run Unit Tests'
required: false
type: boolean
default: false
run-ui-test:
description: 'Should Run UI Tests'
required: false
type: boolean
default: false

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
android-lint:
if: ${{ inputs.run-android-lint }}
uses: ./.github/workflows/android-lint.yml
with:
module: ${{ inputs.module }}
ktlint:
if: ${{ inputs.run-ktlint }}
uses: ./.github/workflows/ktlint.yml
with:
module: ${{ inputs.module }}
assemble:
if: ${{ inputs.run-assemble }}
uses: ./.github/workflows/assemble-module.yml
# Add ktlint after ktlint is applied to all modules
needs: android-lint
with:
module: ${{ inputs.module }}
variant: ${{ inputs.assemble-variant }}
unit-test:
if: ${{ inputs.run-unit-test }}
uses: ./.github/workflows/unit-test.yml
# Add ktlint after ktlint is applied to all modules
needs: android-lint
with:
module: ${{ inputs.module }}
ui-test:
if: ${{ inputs.run-ui-test }}
uses: ./.github/workflows/ui-test.yml
# Add ktlint after ktlint is applied to all modules
needs: android-lint
with:
module: ${{ inputs.module }}
28 changes: 28 additions & 0 deletions .github/workflows/verify-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Verify App

on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
types: [ opened, synchronize, reopened ]
branches: [ master, "bugfix/*", "feature/*", "release/*" ]
paths:
- 'app/**'
- 'checkout/**'
- 'frames/**'
- 'buildSrc/**'
- 'build.gradle.kt'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
verify-app:
uses: ./.github/workflows/verification-flow.yml
with:
module: app
run-android-lint: true
run-assemble: true
run-unit-test: true
27 changes: 27 additions & 0 deletions .github/workflows/verify-checkout.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Verify Checkout

on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
types: [ opened, synchronize, reopened ]
branches: [ master, "bugfix/*", "feature/*", "release/*" ]
paths:
- 'checkout/**'
- 'buildSrc/**'
- 'build.gradle.kt'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
verify-app:
uses: ./.github/workflows/verification-flow.yml
with:
module: checkout
run-android-lint: true
run-ktlint: true
run-assemble: true
run-unit-test: true
29 changes: 29 additions & 0 deletions .github/workflows/verify-example-app-frames.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Verify Example App Frames

on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
types: [ opened, synchronize, reopened ]
branches: [ master, "bugfix/*", "feature/*", "release/*" ]
paths:
- 'checkout/**'
- 'frames/**'
- 'example_app_frames/**'
- 'buildSrc/**'
- 'build.gradle.kt'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
verify-app:
uses: ./.github/workflows/verification-flow.yml
with:
module: example_app_frames
run-android-lint: true
run-ktlint: true
run-assemble: true
run-unit-test: true
29 changes: 29 additions & 0 deletions .github/workflows/verify-frames.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Verify Frames

on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
types: [ opened, synchronize, reopened ]
branches: [ master, "bugfix/*", "feature/*", "release/*" ]
paths:
- 'checkout/**'
- 'frames/**'
- 'buildSrc/**'
- 'build.gradle.kt'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
verify-app:
uses: ./.github/workflows/verification-flow.yml
with:
module: frames
run-android-lint: true
run-ktlint: true
run-assemble: true
run-unit-test: true
run-ui-test: true
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/FramesConfig.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
object FramesConfig {
const val productVersion = "4.1.0"
const val productVersion = "4.1.1"
const val productArtefactId = "frames-android"
const val productGroupId = "com.github.checkout"
const val loggingGroupId = "com.checkout"
Expand Down

0 comments on commit 17de1b0

Please sign in to comment.