|
1 | | -name: Release and Publish |
| 1 | +name: Publish to pub.dev |
2 | 2 |
|
3 | 3 | on: |
4 | | - workflow_dispatch: |
5 | | - inputs: |
6 | | - package: |
7 | | - description: 'Package to publish' |
8 | | - required: true |
9 | | - type: choice |
10 | | - options: |
11 | | - - mcp_dart |
12 | | - - mcp_dart_cli |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v[0-9]+.[0-9]+.[0-9]+*' # mcp_dart: v1.0.0, v1.0.0-dev, etc. |
| 7 | + - 'mcp_dart_cli-v[0-9]+.[0-9]+.[0-9]+*' # mcp_dart_cli: mcp_dart_cli-v0.1.0, etc. |
13 | 8 |
|
14 | 9 | jobs: |
15 | | - release-and-publish: |
| 10 | + publish: |
16 | 11 | runs-on: ubuntu-latest |
17 | 12 | permissions: |
18 | | - contents: write # Required to create tags and releases |
19 | | - id-token: write # Required for pub.dev OIDC authentication |
| 13 | + id-token: write # Required for authentication using OIDC |
20 | 14 | steps: |
21 | 15 | - uses: actions/checkout@v4 |
22 | | - |
23 | | - - name: Set package configuration |
24 | | - id: set-config |
| 16 | + |
| 17 | + - name: Determine package from tag |
| 18 | + id: package-info |
25 | 19 | run: | |
26 | | - if [ "${{ inputs.package }}" = "mcp_dart" ]; then |
| 20 | + TAG="${{ github.ref_name }}" |
| 21 | + echo "🏷️ Processing tag: $TAG" |
| 22 | + |
| 23 | + if [[ "$TAG" == mcp_dart_cli-v* ]]; then |
| 24 | + echo "working_directory=packages/mcp_dart_cli" >> "$GITHUB_OUTPUT" |
| 25 | + echo "📦 Package: mcp_dart_cli" |
| 26 | + elif [[ "$TAG" == v* ]]; then |
27 | 27 | echo "working_directory=." >> "$GITHUB_OUTPUT" |
28 | | - echo "tag_prefix=v" >> "$GITHUB_OUTPUT" |
| 28 | + echo "📦 Package: mcp_dart" |
29 | 29 | else |
30 | | - echo "working_directory=packages/mcp_dart_cli" >> "$GITHUB_OUTPUT" |
31 | | - echo "tag_prefix=mcp_dart_cli-v" >> "$GITHUB_OUTPUT" |
32 | | - fi |
33 | | -
|
34 | | - - name: Get version from pubspec.yaml |
35 | | - id: get-version |
36 | | - working-directory: ${{ steps.set-config.outputs.working_directory }} |
37 | | - run: | |
38 | | - VERSION=$(grep '^version:' pubspec.yaml | sed 's/version: //') |
39 | | - echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
40 | | - echo "📦 Package: ${{ inputs.package }}" |
41 | | - echo "📦 Detected version: $VERSION" |
42 | | -
|
43 | | - - name: Check if tag already exists |
44 | | - run: | |
45 | | - TAG="${{ steps.set-config.outputs.tag_prefix }}${{ steps.get-version.outputs.version }}" |
46 | | - if git rev-parse "$TAG" >/dev/null 2>&1; then |
47 | | - echo "❌ Error: Tag $TAG already exists!" |
48 | | - echo " This version has already been released." |
49 | | - echo " Please bump the version in pubspec.yaml first." |
| 30 | + echo "❌ Unknown tag format: $TAG" |
50 | 31 | exit 1 |
51 | 32 | fi |
52 | | - echo "✅ Tag $TAG does not exist, proceeding..." |
53 | | -
|
54 | | - - name: Create and push tag |
55 | | - id: create-tag |
56 | | - run: | |
57 | | - TAG="${{ steps.set-config.outputs.tag_prefix }}${{ steps.get-version.outputs.version }}" |
58 | | - git config user.name "github-actions[bot]" |
59 | | - git config user.email "github-actions[bot]@users.noreply.github.com" |
60 | | - git tag -a "$TAG" -m "Release ${{ inputs.package }} ${{ steps.get-version.outputs.version }}" |
61 | | - git push origin "$TAG" |
62 | | - echo "tag=$TAG" >> "$GITHUB_OUTPUT" |
63 | | - echo "🏷️ Created and pushed tag: $TAG" |
64 | | -
|
65 | | - - name: Create GitHub Release |
66 | | - uses: softprops/action-gh-release@v2 |
67 | | - with: |
68 | | - tag_name: ${{ steps.create-tag.outputs.tag }} |
69 | | - name: ${{ inputs.package }} ${{ steps.get-version.outputs.version }} |
70 | | - generate_release_notes: true |
71 | | - draft: false |
72 | 33 |
|
73 | 34 | - uses: dart-lang/setup-dart@v1 |
74 | 35 |
|
75 | 36 | - name: Install dependencies |
76 | | - working-directory: ${{ steps.set-config.outputs.working_directory }} |
| 37 | + working-directory: ${{ steps.package-info.outputs.working_directory }} |
77 | 38 | run: dart pub get |
78 | 39 |
|
79 | 40 | - name: Publish to pub.dev |
80 | | - working-directory: ${{ steps.set-config.outputs.working_directory }} |
| 41 | + working-directory: ${{ steps.package-info.outputs.working_directory }} |
81 | 42 | run: dart pub publish --force |
0 commit comments