@@ -3,78 +3,12 @@ name: Publish to pub.dev
33on :
44 push :
55 tags :
6- - ' v[0-9]+.[0-9]+.[0-9]+*' # matches v1.2.3 ; must align with tag-pattern on pub.dev (v{{version}})
6+ - ' v[0-9]+.[0-9]+.[0-9]+*'
77
88jobs :
99 publish :
10- name : Publish package (tag → only if on main)
11- runs-on : ubuntu-latest
1210 permissions :
13- contents : read
14- id-token : write # required for OIDC-based auth to pub.dev
15- environment : pub.dev # include only if you've required a GitHub environment named "pub.dev" on pub.dev
16-
17- steps :
18- - name : Checkout (fetch full history & tags)
19- uses : actions/checkout@v4
20- with :
21- fetch-depth : 0
22-
23- - name : Print context (debug)
24- run : |
25- echo "GITHUB_REF = $GITHUB_REF"
26- echo "GITHUB_SHA = $GITHUB_SHA"
27-
28- - name : Ensure pubspec version matches tag
29- id : check_version
30- run : |
31- TAG=${GITHUB_REF#refs/tags/}
32- echo "Tag: $TAG"
33- # read version from pubspec.yaml, strip build metadata (+...) and optional quotes/spaces
34- VERSION_RAW=$(grep '^version:' pubspec.yaml | sed 's/version:[[:space:]]*//' | tr -d '"')
35- VERSION=$(echo "$VERSION_RAW" | sed 's/+.*//; s/[[:space:]]//g')
36- echo "pubspec version: $VERSION"
37- if [ "$TAG" = "v$VERSION" ] || [ "$TAG" = "$VERSION" ]; then
38- echo "Tag matches pubspec version"
39- else
40- echo "ERROR: Tag ($TAG) does not match pubspec.yaml version ($VERSION)"
41- exit 1
42- fi
43-
44- - name : Ensure tag commit is on origin/main
45- run : |
46- # Fetch remote main and ensure tag commit sha is contained in it.
47- git fetch origin main:refs/remotes/origin/main
48- TAG_COMMIT=${GITHUB_SHA}
49- echo "Tag commit sha: $TAG_COMMIT"
50- if git branch --remote --contains "$TAG_COMMIT" | grep -q 'origin/main'; then
51- echo "Tag commit is contained in origin/main → OK"
52- else
53- echo "ERROR: Tag commit is NOT contained in origin/main."
54- echo "Make sure you create the tag on a commit that is on main or merge main into the commit before tagging."
55- exit 1
56- fi
57-
58- - name : Set Up Flutter
59- uses : subosito/flutter-action@v2
60- with :
61- flutter-version : ' 3.35.4'
62- channel : ' stable'
63-
64- - name : Get dependencies
65- run : flutter pub get
66-
67- - name : Analyze
68- run : flutter analyze
69-
70- - name : Format code
71- run : dart format .
72-
73- # - name: Run tests
74- # run: flutter test
75-
76- - name : Check Publish Warnings (dry-run)
77- run : dart pub publish --dry-run
78-
79- - name : Publish to pub.dev
80- run : flutter pub publish --force
11+ id-token : write
12+ uses : dart-lang/setup-dart/.github/workflows/publish.yml@v1
13+ with :
14+ environment : ' pub.dev'
0 commit comments