Skip to content

Commit d5dce63

Browse files
authored
Initial commit
0 parents  commit d5dce63

27 files changed

Lines changed: 1455 additions & 0 deletions

.github/workflows/_base-dart.yaml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: "[base] Dart"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
path:
7+
required: false
8+
type: string
9+
default: '.'
10+
11+
jobs:
12+
is-flutter:
13+
uses: ./.github/workflows/_base-has_flutter.yaml
14+
with:
15+
path: ${{ inputs.path }}
16+
17+
check-tests:
18+
name: "check tests"
19+
runs-on: ubuntu-latest
20+
needs: is-flutter
21+
if: needs.is-flutter.outputs.is_flutter == '0'
22+
outputs:
23+
do_tests: ${{ steps.check-tests.outputs.do_tests }}
24+
steps:
25+
- uses: actions/checkout@v5
26+
# Skip if no test directory
27+
- id: check-tests
28+
run: |
29+
if [ ! -d "${{ inputs.path }}/test" ]; then
30+
echo "No test directory found, skipping tests.";
31+
do_tests=0
32+
else
33+
echo "Test directory found, will run tests.";
34+
do_tests=1
35+
fi
36+
echo "do_tests=$do_tests" >> $GITHUB_OUTPUT
37+
38+
install:
39+
name: "install"
40+
runs-on: ubuntu-latest
41+
needs: [ is-flutter ]
42+
if: needs.is-flutter.outputs.is_flutter == '0'
43+
steps:
44+
- uses: actions/checkout@v5
45+
- uses: dart-lang/setup-dart@v1
46+
with:
47+
sdk: stable
48+
49+
format:
50+
name: "format"
51+
runs-on: ubuntu-latest
52+
needs: install
53+
54+
steps:
55+
- uses: actions/checkout@v5
56+
- uses: dart-lang/setup-dart@v1
57+
with:
58+
sdk: stable
59+
60+
- name: "Get dependencies"
61+
run: dart pub get
62+
working-directory: ${{ inputs.path }}
63+
64+
- name: "dart format"
65+
run: |
66+
echo "Checking Dart formatting...\nFiles displayed below:"
67+
dart format -o none --set-exit-if-changed ./lib/
68+
if [ -d "${{ inputs.path }}/test" ]; then dart format -o none --set-exit-if-changed ./test/; fi
69+
echo "No formatting issues found."
70+
working-directory: ${{ inputs.path }}
71+
72+
analyze:
73+
name: "analyze"
74+
runs-on: ubuntu-latest
75+
needs: install
76+
77+
steps:
78+
- uses: actions/checkout@v5
79+
- uses: dart-lang/setup-dart@v1
80+
with:
81+
sdk: stable
82+
83+
- name: "Get dependencies"
84+
run: dart pub get
85+
working-directory: ${{ inputs.path }}
86+
87+
- name: Run analysis
88+
run: |
89+
dart analyze --fatal-warnings ./lib/
90+
if [ -d "${{ inputs.path }}/test" ]; then dart analyze --fatal-warnings ./test/; fi
91+
working-directory: ${{ inputs.path }}
92+
93+
test:
94+
runs-on: ubuntu-latest
95+
needs: [install, check-tests]
96+
if: needs.check-tests.outputs.do_tests == 1
97+
98+
steps:
99+
- uses: actions/checkout@v5
100+
- uses: dart-lang/setup-dart@v1
101+
with:
102+
sdk: stable
103+
104+
- name: "Get dependencies"
105+
run: dart pub get
106+
working-directory: ${{ inputs.path }}
107+
108+
- name: Run tests
109+
run: dart test --reporter=expanded test/*.dart
110+
working-directory: ${{ inputs.path }}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: "[base] Flutter"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
path:
7+
required: false
8+
type: string
9+
default: '.'
10+
11+
jobs:
12+
is-flutter:
13+
uses: ./.github/workflows/_base-has_flutter.yaml
14+
with:
15+
path: ${{ inputs.path }}
16+
17+
check-tests:
18+
name: "check tests"
19+
runs-on: ubuntu-latest
20+
needs: is-flutter
21+
if: needs.is-flutter.outputs.is_flutter == '1'
22+
outputs:
23+
do_tests: ${{ steps.check-tests.outputs.do_tests }}
24+
steps:
25+
- uses: actions/checkout@v5
26+
# Skip if no test directory
27+
- id: check-tests
28+
run: |
29+
if [ ! -d "${{ inputs.path }}/test" ]; then
30+
echo "No test directory found, skipping tests.";
31+
do_tests=0
32+
else
33+
echo "Test directory found, will run tests.";
34+
do_tests=1
35+
fi
36+
echo "do_tests=$do_tests" >> $GITHUB_OUTPUT
37+
38+
install:
39+
name: "install"
40+
runs-on: ubuntu-latest
41+
needs: [ is-flutter ]
42+
if: needs.is-flutter.outputs.is_flutter == '1'
43+
steps:
44+
- uses: actions/checkout@v5
45+
- uses: subosito/flutter-action@v2
46+
with:
47+
channel: stable
48+
cache: true
49+
50+
- name: "Get dependencies"
51+
run: flutter pub get
52+
working-directory: ${{ inputs.path }}
53+
54+
format:
55+
name: "format"
56+
runs-on: ubuntu-latest
57+
needs: install
58+
59+
steps:
60+
- uses: actions/checkout@v5
61+
- uses: subosito/flutter-action@v2
62+
with:
63+
channel: stable
64+
cache: true
65+
66+
- name: "Get dependencies"
67+
run: flutter pub get
68+
working-directory: ${{ inputs.path }}
69+
70+
- name: "dart format"
71+
run: |
72+
echo "Checking Dart formatting...\nFiles displayed below:"
73+
dart format --set-exit-if-changed .
74+
echo "No formatting issues found."
75+
working-directory: ${{ inputs.path }}
76+
77+
analyze:
78+
name: "analyze"
79+
runs-on: ubuntu-latest
80+
needs: install
81+
82+
steps:
83+
- uses: actions/checkout@v5
84+
- uses: subosito/flutter-action@v2
85+
with:
86+
channel: stable
87+
cache: true
88+
89+
- name: "Get dependencies"
90+
run: flutter pub get
91+
working-directory: ${{ inputs.path }}
92+
93+
- name: Run analysis
94+
run: flutter analyze --fatal-warnings
95+
working-directory: ${{ inputs.path }}
96+
97+
test:
98+
runs-on: ubuntu-latest
99+
needs: [install, check-tests]
100+
if: needs.check-tests.outputs.do_tests == 1
101+
102+
steps:
103+
- uses: actions/checkout@v5
104+
- uses: subosito/flutter-action@v2
105+
with:
106+
channel: stable
107+
cache: true
108+
109+
- name: "Get dependencies"
110+
run: flutter pub get
111+
working-directory: ${{ inputs.path }}
112+
113+
- name: Run tests
114+
run: flutter test --reporter=expanded test/*.dart
115+
working-directory: ${{ inputs.path }}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# filepath: /Users/jamie/Work/OSS/dart-package-template/.github/workflows/_base-has_flutter.yaml
2+
name: "[base] Has Flutter"
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
path:
8+
required: false
9+
type: string
10+
default: '.'
11+
outputs:
12+
is_flutter:
13+
description: "1 if pubspec.yaml uses Flutter SDK, else 0"
14+
value: ${{ jobs.check.outputs.is_flutter }}
15+
16+
jobs:
17+
check:
18+
runs-on: ubuntu-latest
19+
outputs:
20+
is_flutter: ${{ steps.detect.outputs.is_flutter }}
21+
steps:
22+
- uses: actions/checkout@v5
23+
- id: detect
24+
name: Detect Flutter SDK
25+
run: |
26+
PUBSPEC="${{ inputs.path }}/pubspec.yaml"
27+
if [ ! -f "$PUBSPEC" ]; then
28+
echo "pubspec.yaml not found."
29+
echo "is_flutter=0" >> "$GITHUB_OUTPUT"
30+
exit 0
31+
fi
32+
33+
if awk '
34+
$1 == "environment:" { in_env=1 }
35+
in_env && $1 == "sdk:" { in_env=0 }
36+
in_env && $1 == "flutter:" { found=1 }
37+
END { exit(found?0:1) }
38+
' "$PUBSPEC"; then
39+
echo "Flutter SDK detected."
40+
echo "is_flutter=1" >> "$GITHUB_OUTPUT"
41+
else
42+
echo "Flutter SDK not detected."
43+
echo "is_flutter=0" >> "$GITHUB_OUTPUT"
44+
fi

.github/workflows/example.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: "example"
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
- develop
9+
- 'release/**'
10+
paths:
11+
- 'example/**/*.dart'
12+
- 'example/**/*.yaml'
13+
- .github/workflows/_base-dart.yaml
14+
- .github/workflows/_base-flutter.yaml
15+
- .github/workflows/example.yaml
16+
release:
17+
types: [published]
18+
19+
jobs:
20+
dart:
21+
strategy:
22+
matrix:
23+
example: [ basic, advanced_example ]
24+
name: "${{ matrix.example }}"
25+
uses: ./.github/workflows/_base-dart.yaml
26+
with:
27+
path: "example/${{ matrix.example }}"
28+
29+
flutter:
30+
strategy:
31+
matrix:
32+
example: [ basic, advanced_example ]
33+
name: "${{ matrix.example }}"
34+
uses: ./.github/workflows/_base-flutter.yaml
35+
with:
36+
path: "example/${{ matrix.example }}"

.github/workflows/package.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: "package"
2+
3+
on:
4+
schedule:
5+
- cron: "0 12 * * 3"
6+
pull_request:
7+
push:
8+
branches:
9+
- main
10+
- develop
11+
- 'release/**'
12+
paths:
13+
- '**.dart'
14+
- './*.yaml'
15+
- .github/workflows/_base-dart.yaml
16+
- .github/workflows/package.yaml
17+
release:
18+
types: [published]
19+
20+
21+
# call the base workflow with the package path
22+
jobs:
23+
is-flutter:
24+
uses: ./.github/workflows/_base-has_flutter.yaml
25+
with:
26+
path: '.'
27+
28+
dart:
29+
needs: is-flutter
30+
if: needs.is-flutter.outputs.is_flutter == '0'
31+
uses: ./.github/workflows/_base-dart.yaml
32+
with:
33+
path: '.'
34+
35+
flutter:
36+
needs: is-flutter
37+
if: needs.is-flutter.outputs.is_flutter == '1'
38+
uses: ./.github/workflows/_base-flutter.yaml
39+
with:
40+
path: '.'
41+
42+
publish:
43+
runs-on: ubuntu-latest
44+
# Needs dart or flutter job to complete successfully, only skipped if either is failed, but not skipped
45+
needs: [dart, flutter]
46+
if: ${{ always() && (needs.dart.result == 'success' || needs.flutter.result == 'success') && (needs.dart.result != 'failure' && needs.flutter.result != 'failure') && (github.event_name == 'release' && github.event.action == 'published' || github.ref == 'refs/heads/main') }}
47+
steps:
48+
- uses: actions/checkout@v5
49+
- uses: dart-lang/setup-dart@v1
50+
with:
51+
sdk: stable
52+
53+
- name: "Get dependencies"
54+
run: dart pub get
55+
56+
- name: Publish to pub.dev (dry run)
57+
run: dart pub publish --dry-run

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# See https://www.dartlang.org/guides/libraries/private-files
2+
3+
# Files and directories created by pub
4+
.dart_tool/
5+
.packages
6+
build/
7+
# If you're building an application, you may want to check-in your pubspec.lock
8+
pubspec.lock
9+
*.g.dart
10+
11+
# Directory created by dartdoc
12+
# If you don't generate documentation locally you can remove this line.
13+
doc/api/
14+
15+
# dotenv environment variables file
16+
.env*
17+
18+
# Avoid committing generated Javascript files:
19+
*.dart.js
20+
# Produced by the --dump-info flag.
21+
*.info.json
22+
# When generated by dart2js. Don't specify *.js if your
23+
# project includes source files written in JavaScript.
24+
*.js
25+
*.js_
26+
*.js.deps
27+
*.js.map
28+
29+
.flutter-plugins
30+
.flutter-plugins-dependencies

0 commit comments

Comments
 (0)