Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: configure workflows for Flutter app #2562

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/actions/android/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: "Android Workflow"

inputs:
STORE_PASS:
AsCress marked this conversation as resolved.
Show resolved Hide resolved
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
AsCress marked this conversation as resolved.
Show resolved Hide resolved
default: '1'

runs:
using: "composite"
steps:
- name: Set up Java
uses: actions/setup-java@v2
with:
java-version: 17
distribution: 'adopt'
cache: 'gradle'

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

- 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

- name: Store APK file
uses: actions/upload-artifact@v4
with:
name: apk-files
path: |
build/app/outputs/flutter-apk
25 changes: 25 additions & 0 deletions .github/actions/common/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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

- name: Run tests
shell: bash
run: flutter test
27 changes: 27 additions & 0 deletions .github/actions/ios/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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: 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
128 changes: 128 additions & 0 deletions .github/workflows/pull-request-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: Comment

on:
workflow_run:
workflows: [ Build ]
types:
- completed

jobs:
comment:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request'
steps:
- name: Download artifact
uses: actions/github-script@v7
with:
script: |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr"
})[0];
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
- run: unzip pr.zip

- name: Build success
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: actions/github-script@v7
with:
script: |
var fs = require('fs')
var issue_number = Number(fs.readFileSync('./NR'));
const owner = context.repo.owner;
const repo = context.repo.repo;
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner,
repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "apk-files"
})[0];
const artifact_url = `https://github.com/${owner}/${repo}/actions/runs/${{ github.event.workflow_run.id }}/artifacts/${matchArtifact.id}`;

const comments = await github.rest.issues.listComments({
owner,
repo,
issue_number
});

let comment_id;
for (const comment of comments.data) {
if (comment.user.login === 'github-actions[bot]') {
comment_id = comment.id;
break;
}
}

const body = `Build successful. APKs to test: ${artifact_url}`;

if (comment_id) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id,
body
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body
});
}

- name: Build failed
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
uses: actions/github-script@v7
with:
script: |
var fs = require('fs')
var issue_number = Number(fs.readFileSync('./NR'));
const owner = context.repo.owner;
const repo = context.repo.repo;

const comments = await github.rest.issues.listComments({
owner,
repo,
issue_number
});

let comment_id;
for (const comment of comments.data) {
if (comment.user.login === 'github-actions[bot]') {
comment_id = comment.id;
break;
}
}

const body = `Build failed`;

if (comment_id) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id,
body
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body
});
}
45 changes: 45 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Build

on:
pull_request:
branches: ["flutter"]

jobs:
common:
name: Common Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Common Workflow
uses: ./.github/actions/common

- name: Save PR number
run: |
mkdir -p ./pr
echo ${{ github.event.number }} > ./pr/NR

- uses: actions/upload-artifact@v3
with:
name: pr
path: pr/

android:
name: Android Flutter Build
needs: common
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Android Workflow
uses: ./.github/actions/android

ios:
name: iOS Flutter Build
needs: common
runs-on: macos-latest
steps:
- uses: actions/checkout@v4

- name: iOS Workflow
uses: ./.github/actions/ios
Loading
Loading