Skip to content

Commit b6a763d

Browse files
authored
fix: use official pub.dev trusted publishing workflow (#8)
1 parent 7240636 commit b6a763d

2 files changed

Lines changed: 73 additions & 112 deletions

File tree

.github/workflows/publish.yml

Lines changed: 3 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -2,121 +2,12 @@ name: Publish to pub.dev
22

33
on:
44
push:
5-
branches: [main]
65
tags:
76
- 'v*'
7+
workflow_dispatch:
88

99
jobs:
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

.github/workflows/release.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Prepare release
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
prepare-release:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
token: ${{ secrets.GITHUB_TOKEN }}
17+
- uses: subosito/flutter-action@v2
18+
with:
19+
flutter-version: '3.24.0'
20+
channel: 'stable'
21+
- run: flutter pub get
22+
- run: flutter analyze
23+
- run: flutter test
24+
- name: Determine version bump and push tag
25+
run: |
26+
CURRENT=$(grep '^version:' pubspec.yaml | awk '{print $2}')
27+
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
28+
29+
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
30+
if [ -n "$LAST_TAG" ]; then
31+
COMMITS=$(git log "$LAST_TAG"..HEAD --pretty=format:"%s")
32+
else
33+
COMMITS=$(git log --pretty=format:"%s" -20)
34+
fi
35+
36+
BUMP="patch"
37+
if echo "$COMMITS" | grep -qiE "^feat(\(.*\))?!:|BREAKING CHANGE"; then
38+
if [ "$MAJOR" -ge 1 ]; then
39+
BUMP="major"
40+
else
41+
BUMP="minor"
42+
fi
43+
elif echo "$COMMITS" | grep -qiE "^feat(\(.*\))?:"; then
44+
BUMP="minor"
45+
fi
46+
47+
case $BUMP in
48+
major) NEW_VERSION="$((MAJOR + 1)).0.0" ;;
49+
minor) NEW_VERSION="$MAJOR.$((MINOR + 1)).0" ;;
50+
patch) NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))" ;;
51+
esac
52+
53+
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "https://pub.dev/api/packages/libre_location/versions/$CURRENT")
54+
55+
if [ "$HTTP_CODE" = "200" ]; then
56+
echo "Version $CURRENT exists — bumping $BUMP to $NEW_VERSION"
57+
sed -i "s/^version: .*/version: $NEW_VERSION/" pubspec.yaml
58+
git config user.name "github-actions[bot]"
59+
git config user.email "github-actions[bot]@users.noreply.github.com"
60+
git add pubspec.yaml
61+
git commit -m "chore: bump version to $NEW_VERSION [skip ci]"
62+
VERSION_TO_TAG="$NEW_VERSION"
63+
git push
64+
else
65+
echo "Version $CURRENT not yet published — tagging current version"
66+
VERSION_TO_TAG="$CURRENT"
67+
fi
68+
69+
git tag "v$VERSION_TO_TAG" 2>/dev/null || true
70+
git push --tags

0 commit comments

Comments
 (0)