Skip to content

Commit

Permalink
chore: use general workflows to share steps
Browse files Browse the repository at this point in the history
  • Loading branch information
adityastic committed Jun 26, 2024
1 parent 2011bb5 commit 1a63f0f
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 98 deletions.
56 changes: 56 additions & 0 deletions .github/actions/android/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: "Android Workflow"

inputs:
STORE_PASS:
description: 'Store Password'
required: false
default: ''
ALIAS:
description: 'Certificate Alias'
required: false
default: ''
KEY_PASS:
description: 'Key Password'
required: false
default: ''
VERSION_NAME:
description: 'Version Name to be used for build'
required: false
default: '1.0.0'
VERSION_CODE:
description: 'Version Code to be used for build'
required: true
default: '1'

runs:
using: "composite"
steps:
- uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
cache: true

- name: Run tests
shell: bash
run: flutter test

- name: Build Android APK/AAB
shell: bash
env:
STORE_PASS: ${{ inputs.STORE_PASS }}
ALIAS: ${{ inputs.ALIAS }}
KEY_PASS: ${{ inputs.KEY_PASS }}
VERSION_NAME: ${{inputs.VERSION_NAME}}
VERSION_CODE: ${{inputs.VERSION_CODE}}
run: |
flutter build apk --build-name $VERSION_NAME --build-number $VERSION_CODE
flutter build appbundle --build-name $VERSION_NAME --build-number $VERSION_CODE
21 changes: 21 additions & 0 deletions .github/actions/common/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "Common Workflow"

runs:
using: "composite"
steps:
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
cache: true

- name: Fetch Flutter Dependencies
shell: bash
run: flutter pub get

- name: Validate Code Format
shell: bash
run: dart format --output=none --set-exit-if-changed .

- name: Analyze Code
shell: bash
run: flutter analyze
31 changes: 31 additions & 0 deletions .github/actions/ios/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "iOS Workflow"

inputs:
VERSION_NAME:
description: 'Version Name to be used for build'
required: false
default: '1.0.0'
VERSION_CODE:
description: 'Version Code to be used for build'
required: true
default: '1'

runs:
using: "composite"
steps:
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
cache: true

- name: Run tests
shell: bash
run: flutter test

- name: Build iOS IPA
shell: bash
env:
VERSION_NAME: ${{inputs.VERSION_NAME}}
VERSION_CODE: ${{inputs.VERSION_CODE}}
run: |
flutter build ipa --no-codesign --build-name $VERSION_NAME --build-number $VERSION_CODE
41 changes: 6 additions & 35 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,8 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
cache: true

- name: Fetch Flutter Dependencies
run: flutter pub get

- name: Validate Code Format
run: dart format --output=none --set-exit-if-changed .

- name: Analyze Code
run: flutter analyze
- name: Common Workflow
uses: ./.github/actions/common

android:
name: Android Flutter Build
Expand All @@ -29,18 +18,9 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
cache: true
- name: Android Workflow
uses: ./.github/actions/android

- name: Run tests
run: flutter test

- name: Build Android APK/AAB
run: |
flutter build apk
flutter build appbundle

ios:
name: iOS Flutter Build
Expand All @@ -49,15 +29,6 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
cache: true

- name: Run tests
run: flutter test

- name: Build iOS IPA
run: |
flutter build ipa --no-codesign
- name: iOS Workflow
uses: ./.github/actions/ios

87 changes: 24 additions & 63 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,14 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
cache: true

- name: Fetch Flutter Dependencies
run: flutter pub get

- name: Validate Code Format
run: dart format --output=none --set-exit-if-changed .

- name: Analyze Code
run: flutter analyze
- name: Common Workflow
uses: ./.github/actions/common

- name: Hydrate and Update Version
id: flutter-version
run: |
git config --global user.name "${{ github.workflow }}"
git config --global user.email "gh-actions@${{ github.repository_owner }}"
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git clone --branch=version https://${{ github.repository_owner }}:${{ github.token }}@github.com/${{ github.repository }} version
cd version
Expand Down Expand Up @@ -68,28 +57,6 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Setup Ruby
if: ${{ github.repository == 'fossasia/badgemagic-android' }}
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
bundler-cache: true

- name: Prepare Bundler
if: ${{ github.repository == 'fossasia/badgemagic-android' }}
run: |
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: Pre Checks
run: |
bash scripts/check-screenshots.sh
Expand All @@ -102,25 +69,15 @@ jobs:
run: |
bash scripts/prep-key.sh
- name: Set up Flutter
uses: subosito/flutter-action@v2
- name: Android Workflow
uses: ./.github/actions/android
with:
cache: true

- name: Run tests
run: flutter test

- name: Build Android APK/AAB
env:
STORE_PASS: ${{ secrets.STORE_PASS }}
ALIAS: ${{ secrets.ALIAS }}
KEY_PASS: ${{ secrets.KEY_PASS }}
VERSION_NAME: ${{needs.common.outputs.VERSION_NAME}}
VERSION_CODE: ${{needs.common.outputs.VERSION_CODE}}
run: |
flutter build apk --build-name $VERSION_NAME --build-number $VERSION_CODE
flutter build appbundle --build-name $VERSION_NAME --build-number $VERSION_CODE

- name: Upload APK
uses: actions/upload-artifact@v4
with:
Expand All @@ -136,8 +93,8 @@ jobs:
- name: Upload APK/AAB to apk branch
if: ${{ github.repository == 'fossasia/badgemagic-android' }}
run: |
git config --global user.name "${{ github.workflow }}"
git config --global user.email "gh-actions@${{ github.repository_owner }}"
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git clone --branch=apk https://${{ github.repository_owner }}:${{ github.token }}@github.com/${{ github.repository }} apk
cd apk
Expand Down Expand Up @@ -174,6 +131,19 @@ jobs:
git branch -m apk
git push --force origin apk
- name: Setup Ruby
if: ${{ github.repository == 'fossasia/badgemagic-android' }}
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
bundler-cache: true

- name: Prepare Bundler
if: ${{ github.repository == 'fossasia/badgemagic-android' }}
run: |
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: Update app in Open Testing track
if: ${{ github.repository == 'fossasia/badgemagic-android' }}
run: |
Expand All @@ -189,20 +159,11 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Flutter
uses: subosito/flutter-action@v2
- name: iOS Workflow
uses: ./.github/actions/ios
with:
cache: true

- name: Run tests
run: flutter test

- name: Build iOS IPA
env:
VERSION_NAME: ${{needs.common.outputs.VERSION_NAME}}
VERSION_CODE: ${{needs.common.outputs.VERSION_CODE}}
run: |
flutter build ipa --no-codesign --build-name $VERSION_NAME --build-number $VERSION_CODE

update-release:
needs: [common, android, ios]
Expand Down

0 comments on commit 1a63f0f

Please sign in to comment.