Skip to content

Commit

Permalink
added CI pipeline
Browse files Browse the repository at this point in the history
- run lint
- run test
- build example app
- deploy flutter plugin on pub.dev
  • Loading branch information
Shahroz16 committed Dec 11, 2022
1 parent ff8ec0b commit 9cc4ac3
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 1 deletion.
53 changes: 53 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Flutter Build

on:
push:
branches: [main, beta, alpha]

# Cancel jobs and just run the last one
concurrency:
group: ${{ github.head_ref }}-build
cancel-in-progress: true

defaults:
run:
working-directory: example/

jobs:
build_ios:
name: Build iOS
runs-on: macOS-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
with:
java-version: '12.x'
- uses: subosito/flutter-action@v2
with:
flutter-version: '2.8.1'
channel: 'stable'
cache: true
cache-key: flutter # optional, change this to force refresh cache
cache-path: ${{ runner.tool_cache }}/flutter # optional, change this to specify the cache path

- run: flutter pub get
- run: flutter build ios --release --no-codesign

build_android:
name: Build Android
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
with:
java-version: '12.x'
- uses: subosito/flutter-action@v2
with:
flutter-version: '2.8.1'
channel: 'stable'
cache: true
cache-key: flutter # optional, change this to force refresh cache
cache-path: ${{ runner.tool_cache }}/flutter # optional, change this to specify the cache path

- run: flutter pub get
- run: flutter build appbundle
34 changes: 34 additions & 0 deletions .github/workflows/deploy_pubspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Publish Package

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: subosito/flutter-action@v2
with:
flutter-version: '2.8.1'
channel: 'stable'
cache: true
cache-key: flutter # optional, change this to force refresh cache
cache-path: ${{ runner.tool_cache }}/flutter # optional, change this to specify the cache path
- name: Install dependencies
run: pub get

- name: Prepare Env
shell: bash
env:
PUB_DEV_PUBLISH_ACCESS_TOKEN: ${{ secrets.PUB_DEV_PUBLISH_ACCESS_TOKEN }}
PUB_DEV_PUBLISH_REFRESH_TOKEN: ${{ secrets.PUB_DEV_PUBLISH_REFRESH_TOKEN }}
PUB_DEV_PUBLISH_TOKEN_ENDPOINT: ${{ secrets.PUB_DEV_PUBLISH_TOKEN_ENDPOINT }}
PUB_DEV_PUBLISH_EXPIRATION: ${{ secrets.PUB_DEV_PUBLISH_EXPIRATION }}
run: |
sh ./prepare_deploy_env.sh
- name: Check Publish Warnings
run: pub publish --dry-run
- name: Publish Package
run: pub publish -f
28 changes: 28 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Lint

on: [push, pull_request]

# Cancel jobs and just run the last one
concurrency:
group: ${{ github.head_ref }}-lint
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: subosito/flutter-action@v2
with:
flutter-version: '2.8.1'
channel: 'stable'
cache: true
cache-key: flutter # optional, change this to force refresh cache
cache-path: ${{ runner.tool_cache }}/flutter # optional, change this to specify the cache path

- name: Install dependencies
run: flutter pub get

- name: Analyze project source
run: flutter analyze
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test

on: [push, pull_request]

# Cancel jobs and just run the last one
concurrency:
group: ${{ github.head_ref }}-unit-test
cancel-in-progress: true

jobs:
unit_test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: subosito/flutter-action@v2
with:
flutter-version: '2.8.1'
channel: 'stable'
cache: true
cache-key: flutter # optional, change this to force refresh cache
cache-path: ${{ runner.tool_cache }}/flutter # optional, change this to specify the cache path

- name: Install dependencies
run: flutter pub get

- name: Run tests
run: flutter test
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The MIT License (MIT)
MIT License

Copyright (c) 2021 Customer IO

Expand Down
38 changes: 38 additions & 0 deletions prepare_deploy_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This script creates/updates credentials.json file which is used
# to authorize publisher when publishing packages to pub.dev
# Source: https://birju.dev/posts/publish-your-flutter-package-using-github-actions/

# Checking whether the secrets are available as environment
# variables or not.
if [ -z "${PUB_DEV_PUBLISH_ACCESS_TOKEN}" ]; then
echo "Missing PUB_DEV_PUBLISH_ACCESS_TOKEN environment variable"
exit 1
fi

if [ -z "${PUB_DEV_PUBLISH_REFRESH_TOKEN}" ]; then
echo "Missing PUB_DEV_PUBLISH_REFRESH_TOKEN environment variable"
exit 1
fi

if [ -z "${PUB_DEV_PUBLISH_TOKEN_ENDPOINT}" ]; then
echo "Missing PUB_DEV_PUBLISH_TOKEN_ENDPOINT environment variable"
exit 1
fi

if [ -z "${PUB_DEV_PUBLISH_EXPIRATION}" ]; then
echo "Missing PUB_DEV_PUBLISH_EXPIRATION environment variable"
exit 1
fi

# Create credentials.json file.
mkdir -p $HOME/.config/dart
cat <<EOF > $HOME/.config/dart/pub-credentials.json
{
"accessToken":"${PUB_DEV_PUBLISH_ACCESS_TOKEN}",
"refreshToken":"${PUB_DEV_PUBLISH_REFRESH_TOKEN}",
"tokenEndpoint":"${PUB_DEV_PUBLISH_TOKEN_ENDPOINT}",
"idToken":"${PUB_DEV_PUBLISH_TOKEN_ID}",
"scopes":["https://www.googleapis.com/auth/userinfo.email","openid"],
"expiration":${PUB_DEV_PUBLISH_EXPIRATION}
}
EOF

0 comments on commit 9cc4ac3

Please sign in to comment.