@@ -2,121 +2,12 @@ name: Publish to pub.dev
22
33on :
44 push :
5- branches : [main]
65 tags :
76 - ' v*'
7+ workflow_dispatch :
88
99jobs :
10- prepare-release :
11- if : github.ref_type == 'branch'
12- runs-on : ubuntu-latest
13- permissions :
14- contents : write
15- outputs :
16- version_to_publish : ${{ steps.version.outputs.version_to_publish }}
17- should_publish : ${{ steps.version.outputs.should_publish }}
18- steps :
19- - uses : actions/checkout@v4
20- with :
21- fetch-depth : 0
22- token : ${{ secrets.GITHUB_TOKEN }}
23- - uses : subosito/flutter-action@v2
24- with :
25- flutter-version : ' 3.24.0'
26- channel : ' stable'
27- - run : flutter pub get
28- - run : flutter analyze
29- - run : flutter test
30- - name : Determine version bump and push tag
31- id : version
32- run : |
33- CURRENT=$(grep '^version:' pubspec.yaml | awk '{print $2}')
34- IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
35-
36- LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
37- if [ -n "$LAST_TAG" ]; then
38- COMMITS=$(git log "$LAST_TAG"..HEAD --pretty=format:"%s")
39- else
40- COMMITS=$(git log --pretty=format:"%s" -20)
41- fi
42-
43- BUMP="patch"
44- if echo "$COMMITS" | grep -qiE "^feat(\(.*\))?!:|BREAKING CHANGE"; then
45- if [ "$MAJOR" -ge 1 ]; then
46- BUMP="major"
47- else
48- BUMP="minor"
49- fi
50- elif echo "$COMMITS" | grep -qiE "^feat(\(.*\))?:"; then
51- BUMP="minor"
52- fi
53-
54- case $BUMP in
55- major) NEW_VERSION="$((MAJOR + 1)).0.0" ;;
56- minor) NEW_VERSION="$MAJOR.$((MINOR + 1)).0" ;;
57- patch) NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))" ;;
58- esac
59-
60- HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "https://pub.dev/api/packages/libre_location/versions/$CURRENT")
61-
62- if [ "$HTTP_CODE" = "200" ]; then
63- echo "Version $CURRENT exists — bumping $BUMP to $NEW_VERSION"
64- sed -i "s/^version: .*/version: $NEW_VERSION/" pubspec.yaml
65- git config user.name "github-actions[bot]"
66- git config user.email "github-actions[bot]@users.noreply.github.com"
67- git add pubspec.yaml
68- git commit -m "chore: bump version to $NEW_VERSION [skip ci]"
69- VERSION_TO_TAG="$NEW_VERSION"
70- git push
71- else
72- echo "Version $CURRENT not yet published — tagging current version"
73- VERSION_TO_TAG="$CURRENT"
74- fi
75-
76- git tag "v$VERSION_TO_TAG" 2>/dev/null || true
77- git push --tags
78-
79- echo "version_to_publish=$VERSION_TO_TAG" >> "$GITHUB_OUTPUT"
80- echo "should_publish=true" >> "$GITHUB_OUTPUT"
81-
82- publish-from-main :
83- if : github.ref_type == 'branch'
84- needs : prepare-release
85- runs-on : ubuntu-latest
86- permissions :
87- id-token : write
88- contents : read
89- steps :
90- - uses : actions/checkout@v4
91- with :
92- fetch-depth : 0
93- ref : v${{ needs.prepare-release.outputs.version_to_publish }}
94- - uses : subosito/flutter-action@v2
95- with :
96- flutter-version : ' 3.24.0'
97- channel : ' stable'
98- - run : flutter pub get
99- - run : flutter analyze
100- - run : flutter test
101- - name : Publish package
102- run : dart pub publish --force
103-
104- publish-from-tag :
105- if : github.ref_type == 'tag'
106- runs-on : ubuntu-latest
10+ publish :
10711 permissions :
10812 id-token : write
109- contents : read
110- steps :
111- - uses : actions/checkout@v4
112- with :
113- fetch-depth : 0
114- - uses : subosito/flutter-action@v2
115- with :
116- flutter-version : ' 3.24.0'
117- channel : ' stable'
118- - run : flutter pub get
119- - run : flutter analyze
120- - run : flutter test
121- - name : Publish package
122- run : dart pub publish --force
13+ uses : dart-lang/setup-dart/.github/workflows/publish.yml@v1
0 commit comments