Skip to content

Commit 3b7b38f

Browse files
committed
feat: add publishing workflow with pana verification
1 parent d6cee5d commit 3b7b38f

2 files changed

Lines changed: 60 additions & 23 deletions

File tree

.github/workflows/publish.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Publish to pub.dev
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
jobs:
9+
publish:
10+
permissions:
11+
id-token: write # Required for authentication using OIDC
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- uses: dart-lang/setup-dart@v1
17+
18+
- name: Install dependencies
19+
run: dart pub get
20+
21+
- name: Validate Version
22+
run: |
23+
# Extract version from pubspec.yaml
24+
PUBSPEC_VERSION=$(grep '^version:' pubspec.yaml | head -n 1 | sed 's/version: //')
25+
# Extract version from tag (remove 'v' prefix)
26+
TAG_VERSION=${GITHUB_REF#refs/tags/v}
27+
28+
echo "Pubspec version: $PUBSPEC_VERSION"
29+
echo "Tag version: $TAG_VERSION"
30+
31+
if [ "$PUBSPEC_VERSION" != "$TAG_VERSION" ]; then
32+
echo "Error: pubspec.yaml version ($PUBSPEC_VERSION) does not match tag version ($TAG_VERSION)"
33+
exit 1
34+
fi
35+
36+
- name: Install Pana
37+
run: dart pub global activate pana
38+
39+
- name: Verify Pana Score (>= 160)
40+
run: |
41+
dart pub global run pana . --no-warning --json > pana_report.json
42+
dart script/verify_pana_score.dart 160
43+
44+
- name: Publish
45+
run: dart pub publish --force

script/verify_pana_score.dart

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,30 @@
11
import 'dart:convert';
22
import 'dart:io';
33

4-
void main() {
5-
final file = File('pana_report.json');
6-
if (!file.existsSync()) {
4+
void main(List<String> args) {
5+
final reportFile = File('pana_report.json');
6+
if (!reportFile.existsSync()) {
77
print('Error: pana_report.json not found.');
88
exit(1);
99
}
1010

11-
final jsonString = file.readAsStringSync();
12-
final Map<String, dynamic> report = jsonDecode(jsonString);
11+
final report = jsonDecode(reportFile.readAsStringSync());
12+
final scores = report['scores'];
13+
final grantedPoints = scores['grantedPoints'] as int;
14+
final maxPoints = scores['maxPoints'] as int;
1315

14-
final scores = report['scores'] as Map<String, dynamic>?;
15-
if (scores == null) {
16-
print('Error: Could not find scores in pana report.');
17-
exit(1);
18-
}
19-
20-
final grantedPoints = scores['grantedPoints'] as int?;
21-
final maxPoints = scores['maxPoints'] as int?;
22-
23-
if (grantedPoints == null) {
24-
print('Error: Could not find grantedPoints in pana report.');
25-
exit(1);
16+
// Default threshold is 140, but can be overridden by argument
17+
int threshold = 140;
18+
if (args.isNotEmpty) {
19+
threshold = int.tryParse(args[0]) ?? 140;
2620
}
2721

28-
print('Pana Score: $grantedPoints / ${maxPoints ?? "Unknown"}');
22+
print('Pana Score: $grantedPoints / $maxPoints');
2923

30-
if (grantedPoints < 160) {
31-
print(
32-
'Failure: Pana score $grantedPoints is below the required threshold of 160.',
33-
);
24+
if (grantedPoints < threshold) {
25+
print('Error: Score is below the threshold of $threshold.');
3426
exit(1);
3527
}
3628

37-
print('Success: Pana score meets the requirement.');
29+
print('Success: Score meets the threshold.');
3830
}

0 commit comments

Comments
 (0)