Skip to content

Commit fce6a9e

Browse files
authored
chore: configure workflows for Flutter app (#2562)
1 parent 38d9692 commit fce6a9e

File tree

6 files changed

+457
-0
lines changed

6 files changed

+457
-0
lines changed

.github/actions/android/action.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: "Android Workflow"
2+
3+
inputs:
4+
STORE_PASS:
5+
description: 'Store Password'
6+
required: false
7+
default: ''
8+
ALIAS:
9+
description: 'Certificate Alias'
10+
required: false
11+
default: ''
12+
KEY_PASS:
13+
description: 'Key Password'
14+
required: false
15+
default: ''
16+
VERSION_NAME:
17+
description: 'Version Name to be used for build'
18+
required: false
19+
default: '1.0.0'
20+
VERSION_CODE:
21+
description: 'Version Code to be used for build'
22+
required: true
23+
default: '1'
24+
25+
runs:
26+
using: "composite"
27+
steps:
28+
- name: Set up Java
29+
uses: actions/setup-java@v2
30+
with:
31+
java-version: 17
32+
distribution: 'adopt'
33+
cache: 'gradle'
34+
35+
- name: Set up Flutter
36+
uses: subosito/flutter-action@v2
37+
with:
38+
cache: true
39+
40+
- name: Build Android APK/AAB
41+
shell: bash
42+
env:
43+
STORE_PASS: ${{ inputs.STORE_PASS }}
44+
ALIAS: ${{ inputs.ALIAS }}
45+
KEY_PASS: ${{ inputs.KEY_PASS }}
46+
VERSION_NAME: ${{inputs.VERSION_NAME}}
47+
VERSION_CODE: ${{inputs.VERSION_CODE}}
48+
run: |
49+
flutter build apk --build-name $VERSION_NAME --build-number $VERSION_CODE
50+
flutter build appbundle --build-name $VERSION_NAME --build-number $VERSION_CODE
51+
52+
- name: Store APK file
53+
uses: actions/upload-artifact@v4
54+
with:
55+
name: apk-files
56+
path: |
57+
build/app/outputs/flutter-apk

.github/actions/common/action.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: "Common Workflow"
2+
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Set up Flutter
7+
uses: subosito/flutter-action@v2
8+
with:
9+
cache: true
10+
11+
- name: Fetch Flutter Dependencies
12+
shell: bash
13+
run: flutter pub get
14+
15+
- name: Validate Code Format
16+
shell: bash
17+
run: dart format --output=none --set-exit-if-changed .
18+
19+
- name: Analyze Code
20+
shell: bash
21+
run: flutter analyze
22+
23+
- name: Run tests
24+
shell: bash
25+
run: flutter test

.github/actions/ios/action.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: "iOS Workflow"
2+
3+
inputs:
4+
VERSION_NAME:
5+
description: 'Version Name to be used for build'
6+
required: false
7+
default: '1.0.0'
8+
VERSION_CODE:
9+
description: 'Version Code to be used for build'
10+
required: true
11+
default: '1'
12+
13+
runs:
14+
using: "composite"
15+
steps:
16+
- name: Set up Flutter
17+
uses: subosito/flutter-action@v2
18+
with:
19+
cache: true
20+
21+
- name: Build iOS IPA
22+
shell: bash
23+
env:
24+
VERSION_NAME: ${{inputs.VERSION_NAME}}
25+
VERSION_CODE: ${{inputs.VERSION_CODE}}
26+
run: |
27+
flutter build ipa --no-codesign --build-name $VERSION_NAME --build-number $VERSION_CODE
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: Comment
2+
3+
on:
4+
workflow_run:
5+
workflows: [ Build ]
6+
types:
7+
- completed
8+
9+
jobs:
10+
comment:
11+
runs-on: ubuntu-latest
12+
if: >
13+
github.event.workflow_run.event == 'pull_request'
14+
steps:
15+
- name: Download artifact
16+
uses: actions/github-script@v7
17+
with:
18+
script: |
19+
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
20+
owner: context.repo.owner,
21+
repo: context.repo.repo,
22+
run_id: ${{github.event.workflow_run.id }},
23+
});
24+
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
25+
return artifact.name == "pr"
26+
})[0];
27+
var download = await github.rest.actions.downloadArtifact({
28+
owner: context.repo.owner,
29+
repo: context.repo.repo,
30+
artifact_id: matchArtifact.id,
31+
archive_format: 'zip',
32+
});
33+
var fs = require('fs');
34+
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
35+
- run: unzip pr.zip
36+
37+
- name: Build success
38+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
39+
uses: actions/github-script@v7
40+
with:
41+
script: |
42+
var fs = require('fs')
43+
var issue_number = Number(fs.readFileSync('./NR'));
44+
const owner = context.repo.owner;
45+
const repo = context.repo.repo;
46+
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
47+
owner,
48+
repo,
49+
run_id: ${{github.event.workflow_run.id }},
50+
});
51+
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
52+
return artifact.name == "apk-files"
53+
})[0];
54+
const artifact_url = `https://github.com/${owner}/${repo}/actions/runs/${{ github.event.workflow_run.id }}/artifacts/${matchArtifact.id}`;
55+
56+
const comments = await github.rest.issues.listComments({
57+
owner,
58+
repo,
59+
issue_number
60+
});
61+
62+
let comment_id;
63+
for (const comment of comments.data) {
64+
if (comment.user.login === 'github-actions[bot]') {
65+
comment_id = comment.id;
66+
break;
67+
}
68+
}
69+
70+
const body = `Build successful. APKs to test: ${artifact_url}`;
71+
72+
if (comment_id) {
73+
await github.rest.issues.updateComment({
74+
owner,
75+
repo,
76+
comment_id,
77+
body
78+
});
79+
} else {
80+
await github.rest.issues.createComment({
81+
owner,
82+
repo,
83+
issue_number,
84+
body
85+
});
86+
}
87+
88+
- name: Build failed
89+
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
90+
uses: actions/github-script@v7
91+
with:
92+
script: |
93+
var fs = require('fs')
94+
var issue_number = Number(fs.readFileSync('./NR'));
95+
const owner = context.repo.owner;
96+
const repo = context.repo.repo;
97+
98+
const comments = await github.rest.issues.listComments({
99+
owner,
100+
repo,
101+
issue_number
102+
});
103+
104+
let comment_id;
105+
for (const comment of comments.data) {
106+
if (comment.user.login === 'github-actions[bot]') {
107+
comment_id = comment.id;
108+
break;
109+
}
110+
}
111+
112+
const body = `Build failed`;
113+
114+
if (comment_id) {
115+
await github.rest.issues.updateComment({
116+
owner,
117+
repo,
118+
comment_id,
119+
body
120+
});
121+
} else {
122+
await github.rest.issues.createComment({
123+
owner,
124+
repo,
125+
issue_number,
126+
body
127+
});
128+
}

.github/workflows/pull-request.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Build
2+
3+
on:
4+
pull_request:
5+
branches: ["flutter"]
6+
7+
jobs:
8+
common:
9+
name: Common Build
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Common Workflow
15+
uses: ./.github/actions/common
16+
17+
- name: Save PR number
18+
run: |
19+
mkdir -p ./pr
20+
echo ${{ github.event.number }} > ./pr/NR
21+
22+
- uses: actions/upload-artifact@v3
23+
with:
24+
name: pr
25+
path: pr/
26+
27+
android:
28+
name: Android Flutter Build
29+
needs: common
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
34+
- name: Android Workflow
35+
uses: ./.github/actions/android
36+
37+
ios:
38+
name: iOS Flutter Build
39+
needs: common
40+
runs-on: macos-latest
41+
steps:
42+
- uses: actions/checkout@v4
43+
44+
- name: iOS Workflow
45+
uses: ./.github/actions/ios

0 commit comments

Comments
 (0)