Skip to content

Commit 1291dae

Browse files
committed
chore: Update publish workflow to use Flutter commands and improve package validation
This commit modifies the GitHub Actions workflow for publishing packages by replacing Dart commands with Flutter commands for publishing. It also enhances the validation job name to reflect the specific package being validated. Additionally, it introduces a permissions section for write access to contents and refines the conditions for publishing engine plugins, ensuring better control over which packages are published based on the event type and input parameters.
1 parent 6a16019 commit 1291dae

1 file changed

Lines changed: 74 additions & 140 deletions

File tree

.github/workflows/publish.yml

Lines changed: 74 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ on:
2222
default: true
2323
type: boolean
2424

25+
permissions:
26+
contents: write
27+
2528
jobs:
2629
# Validate all packages before publishing
2730
validate:
28-
name: Validate Packages
31+
name: Validate ${{ matrix.package.name }}
2932
runs-on: ubuntu-latest
3033
strategy:
3134
matrix:
@@ -61,7 +64,7 @@ jobs:
6164

6265
- name: Validate package
6366
working-directory: ${{ matrix.package.path }}
64-
run: dart pub publish --dry-run
67+
run: flutter pub publish --dry-run
6568

6669
# Publish gameframework (core package) first
6770
publish-gameframework:
@@ -70,7 +73,7 @@ jobs:
7073
runs-on: ubuntu-latest
7174
if: |
7275
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) ||
73-
(github.event_name == 'workflow_dispatch' &&
76+
(github.event_name == 'workflow_dispatch' &&
7477
(github.event.inputs.package == 'all' || github.event.inputs.package == 'gameframework'))
7578
steps:
7679
- name: Checkout repository
@@ -96,12 +99,12 @@ jobs:
9699
- name: Publish to pub.dev (dry-run)
97100
if: github.event.inputs.dry_run == 'true'
98101
working-directory: packages/gameframework
99-
run: dart pub publish --dry-run
102+
run: flutter pub publish --dry-run
100103

101104
- name: Publish to pub.dev
102105
if: github.event.inputs.dry_run != 'true'
103106
working-directory: packages/gameframework
104-
run: dart pub publish --force
107+
run: flutter pub publish --force
105108

106109
- name: Extract version
107110
if: github.event.inputs.dry_run != 'true'
@@ -112,124 +115,24 @@ jobs:
112115
echo "version=$VERSION" >> $GITHUB_OUTPUT
113116
echo "Published gameframework v$VERSION"
114117
115-
# Publish Unity plugin individually (manual dispatch only)
116-
publish-unity:
117-
name: Publish gameframework_unity
118-
needs: [validate, publish-gameframework]
119-
runs-on: ubuntu-latest
120-
if: |
121-
always() &&
122-
github.event_name == 'workflow_dispatch' &&
123-
github.event.inputs.package == 'gameframework_unity'
124-
steps:
125-
- name: Checkout repository
126-
uses: actions/checkout@v4
127-
128-
- name: Setup Flutter
129-
uses: subosito/flutter-action@v2
130-
with:
131-
flutter-version: '3.27.x'
132-
channel: 'stable'
133-
cache: true
134-
135-
- name: Wait for gameframework availability
136-
if: github.event.inputs.dry_run != 'true'
137-
run: |
138-
echo "Waiting 60 seconds for gameframework to be available on pub.dev..."
139-
sleep 60
140-
141-
- name: Get dependencies
142-
working-directory: engines/unity/dart
143-
run: flutter pub get
144-
145-
- name: Setup pub credentials
146-
if: github.event.inputs.dry_run != 'true'
147-
run: |
148-
mkdir -p $HOME/.pub-cache
149-
echo '${{ secrets.PUB_CREDENTIALS }}' > $HOME/.pub-cache/credentials.json
150-
151-
- name: Publish to pub.dev (dry-run)
152-
if: github.event.inputs.dry_run == 'true'
153-
working-directory: engines/unity/dart
154-
run: dart pub publish --dry-run
155-
156-
- name: Publish to pub.dev
157-
if: github.event.inputs.dry_run != 'true'
158-
working-directory: engines/unity/dart
159-
run: dart pub publish --force
160-
161-
- name: Extract version
162-
if: github.event.inputs.dry_run != 'true'
163-
id: version
164-
working-directory: engines/unity/dart
165-
run: |
166-
VERSION=$(grep '^version:' pubspec.yaml | awk '{print $2}')
167-
echo "version=$VERSION" >> $GITHUB_OUTPUT
168-
echo "Published gameframework_unity v$VERSION"
169-
170-
# Publish Unreal plugin individually (manual dispatch only)
171-
publish-unreal:
172-
name: Publish gameframework_unreal
173-
needs: [validate, publish-gameframework]
174-
runs-on: ubuntu-latest
175-
if: |
176-
always() &&
177-
github.event_name == 'workflow_dispatch' &&
178-
github.event.inputs.package == 'gameframework_unreal'
179-
steps:
180-
- name: Checkout repository
181-
uses: actions/checkout@v4
182-
183-
- name: Setup Flutter
184-
uses: subosito/flutter-action@v2
185-
with:
186-
flutter-version: '3.27.x'
187-
channel: 'stable'
188-
cache: true
189-
190-
- name: Wait for gameframework availability
191-
if: github.event.inputs.dry_run != 'true'
192-
run: |
193-
echo "Waiting 60 seconds for gameframework to be available on pub.dev..."
194-
sleep 60
195-
196-
- name: Get dependencies
197-
working-directory: engines/unreal/dart
198-
run: flutter pub get
199-
200-
- name: Setup pub credentials
201-
if: github.event.inputs.dry_run != 'true'
202-
run: |
203-
mkdir -p $HOME/.pub-cache
204-
echo '${{ secrets.PUB_CREDENTIALS }}' > $HOME/.pub-cache/credentials.json
205-
206-
- name: Publish to pub.dev (dry-run)
207-
if: github.event.inputs.dry_run == 'true'
208-
working-directory: engines/unreal/dart
209-
run: dart pub publish --dry-run
210-
211-
- name: Publish to pub.dev
212-
if: github.event.inputs.dry_run != 'true'
213-
working-directory: engines/unreal/dart
214-
run: dart pub publish --force
215-
216-
- name: Extract version
217-
if: github.event.inputs.dry_run != 'true'
218-
id: version
219-
working-directory: engines/unreal/dart
220-
run: |
221-
VERSION=$(grep '^version:' pubspec.yaml | awk '{print $2}')
222-
echo "version=$VERSION" >> $GITHUB_OUTPUT
223-
echo "Published gameframework_unreal v$VERSION"
224-
225-
# Publish Unity and Unreal plugins in parallel (after core package)
118+
# Publish engine plugins after core package
119+
# matrix is NOT available in job-level `if`, so per-package filtering
120+
# is handled at the step level via the should_publish check.
226121
publish-engine-plugins:
227122
name: Publish ${{ matrix.package.name }}
228-
needs: publish-gameframework
123+
needs: [validate, publish-gameframework]
229124
runs-on: ubuntu-latest
125+
# always() is required so this job isn't auto-skipped when publish-gameframework is skipped
126+
# (e.g. when dispatching for a single engine plugin only).
127+
# We gate on validate succeeding and publish-gameframework not having failed.
230128
if: |
231-
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) ||
232-
(github.event_name == 'workflow_dispatch' && github.event.inputs.package == 'all')
129+
always() &&
130+
needs.validate.result == 'success' &&
131+
(needs.publish-gameframework.result == 'success' || needs.publish-gameframework.result == 'skipped') &&
132+
(
133+
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) ||
134+
(github.event_name == 'workflow_dispatch' && github.event.inputs.package != 'gameframework')
135+
)
233136
strategy:
234137
matrix:
235138
package:
@@ -238,58 +141,91 @@ jobs:
238141
- name: gameframework_unreal
239142
path: engines/unreal/dart
240143
steps:
144+
# Determine at step level whether this specific matrix entry should publish.
145+
# matrix context IS available in step-level expressions.
146+
- name: Check if this package should be published
147+
id: should_publish
148+
run: |
149+
if [[ "${{ github.event_name }}" == "push" ]] || \
150+
[[ "${{ github.event.inputs.package }}" == "all" ]] || \
151+
[[ "${{ github.event.inputs.package }}" == "${{ matrix.package.name }}" ]]; then
152+
echo "publish=true" >> $GITHUB_OUTPUT
153+
else
154+
echo "publish=false" >> $GITHUB_OUTPUT
155+
echo "Skipping ${{ matrix.package.name }} (not selected)"
156+
fi
157+
241158
- name: Checkout repository
159+
if: steps.should_publish.outputs.publish == 'true'
242160
uses: actions/checkout@v4
243161

244162
- name: Setup Flutter
163+
if: steps.should_publish.outputs.publish == 'true'
245164
uses: subosito/flutter-action@v2
246165
with:
247166
flutter-version: '3.27.x'
248167
channel: 'stable'
249168
cache: true
250169

251-
# Wait for gameframework to be available on pub.dev
252-
- name: Wait for gameframework availability
253-
if: github.event.inputs.dry_run != 'true'
170+
# Only wait if the core package was actually published (not skipped/dry-run)
171+
- name: Wait for gameframework availability on pub.dev
172+
if: |
173+
steps.should_publish.outputs.publish == 'true' &&
174+
github.event.inputs.dry_run != 'true' &&
175+
needs.publish-gameframework.result == 'success'
254176
run: |
255177
echo "Waiting 60 seconds for gameframework to be available on pub.dev..."
256178
sleep 60
257179
258180
- name: Get dependencies
181+
if: steps.should_publish.outputs.publish == 'true'
259182
working-directory: ${{ matrix.package.path }}
260183
run: flutter pub get
261184

262185
- name: Setup pub credentials
263-
if: github.event.inputs.dry_run != 'true'
186+
if: |
187+
steps.should_publish.outputs.publish == 'true' &&
188+
github.event.inputs.dry_run != 'true'
264189
run: |
265190
mkdir -p $HOME/.pub-cache
266191
echo '${{ secrets.PUB_CREDENTIALS }}' > $HOME/.pub-cache/credentials.json
267192
268193
- name: Publish to pub.dev (dry-run)
269-
if: github.event.inputs.dry_run == 'true'
194+
if: |
195+
steps.should_publish.outputs.publish == 'true' &&
196+
github.event.inputs.dry_run == 'true'
270197
working-directory: ${{ matrix.package.path }}
271-
run: dart pub publish --dry-run
198+
run: flutter pub publish --dry-run
272199

273200
- name: Publish to pub.dev
274-
if: github.event.inputs.dry_run != 'true'
201+
if: |
202+
steps.should_publish.outputs.publish == 'true' &&
203+
github.event.inputs.dry_run != 'true'
275204
working-directory: ${{ matrix.package.path }}
276-
run: dart pub publish --force
205+
run: flutter pub publish --force
277206

278207
- name: Extract version
279-
if: github.event.inputs.dry_run != 'true'
208+
if: |
209+
steps.should_publish.outputs.publish == 'true' &&
210+
github.event.inputs.dry_run != 'true'
280211
id: version
281212
working-directory: ${{ matrix.package.path }}
282213
run: |
283214
VERSION=$(grep '^version:' pubspec.yaml | awk '{print $2}')
284215
echo "version=$VERSION" >> $GITHUB_OUTPUT
285216
echo "Published ${{ matrix.package.name }} v$VERSION"
286217
287-
# Create GitHub release
218+
# Create GitHub release on tag push after all packages are published
288219
create-release:
289220
name: Create GitHub Release
290221
needs: [publish-gameframework, publish-engine-plugins]
291222
runs-on: ubuntu-latest
292-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
223+
if: |
224+
always() &&
225+
github.event_name == 'push' &&
226+
startsWith(github.ref, 'refs/tags/v') &&
227+
needs.publish-gameframework.result == 'success' &&
228+
needs.publish-engine-plugins.result == 'success'
293229
steps:
294230
- name: Checkout repository
295231
uses: actions/checkout@v4
@@ -301,9 +237,9 @@ jobs:
301237
- name: Read CHANGELOG
302238
id: changelog
303239
run: |
304-
if [ -f CHANGELOG.md ]; then
305-
# Extract the latest changelog entry
306-
CHANGELOG=$(awk '/^## \[?[0-9]/{if(++count==2) exit} count==1' CHANGELOG.md)
240+
CHANGELOG_FILE="packages/gameframework/CHANGELOG.md"
241+
if [ -f "$CHANGELOG_FILE" ]; then
242+
CHANGELOG=$(awk '/^## \[?[0-9]/{if(++count==2) exit} count==1' "$CHANGELOG_FILE")
307243
echo "changelog<<EOF" >> $GITHUB_OUTPUT
308244
echo "$CHANGELOG" >> $GITHUB_OUTPUT
309245
echo "EOF" >> $GITHUB_OUTPUT
@@ -312,20 +248,18 @@ jobs:
312248
fi
313249
314250
- name: Create Release
315-
uses: actions/create-release@v1
316-
env:
317-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
251+
uses: softprops/action-gh-release@v2
318252
with:
319-
tag_name: ${{ github.ref }}
320-
release_name: Release ${{ steps.tag_version.outputs.version }}
253+
tag_name: ${{ github.ref_name }}
254+
name: Release ${{ steps.tag_version.outputs.version }}
321255
body: |
322256
## Flutter Game Framework ${{ steps.tag_version.outputs.version }}
323-
257+
324258
Published packages:
325259
- [gameframework](https://pub.dev/packages/gameframework)
326260
- [gameframework_unity](https://pub.dev/packages/gameframework_unity)
327261
- [gameframework_unreal](https://pub.dev/packages/gameframework_unreal)
328-
262+
329263
### Changelog
330264
${{ steps.changelog.outputs.changelog }}
331265
draft: false

0 commit comments

Comments
 (0)