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 ee9e3f2
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 52 deletions.
54 changes: 54 additions & 0 deletions .github/actions/android/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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
run: flutter test

- name: Build Android APK/AAB
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
72 changes: 20 additions & 52 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,13 @@ 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
- 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 +56,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 +68,14 @@ jobs:
run: |
bash scripts/prep-key.sh
- name: Set up Flutter
uses: subosito/flutter-action@v2
- 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 +91,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 +129,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 Down

0 comments on commit ee9e3f2

Please sign in to comment.