-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: configure workflows for Flutter app (#2562)
- Loading branch information
Showing
6 changed files
with
457 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
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: | ||
- 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 |
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
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 |
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
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 |
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
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 | ||
}); | ||
} |
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
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 |
Oops, something went wrong.