Skip to content

Commit b79868a

Browse files
committed
Split into separate release and publish workflows with PAT support
- release.yml: Creates tag and GitHub release using RELEASE_PAT - publish.yml: Triggers on tag push to publish to pub.dev - Using PAT allows tag push to trigger the publish workflow
1 parent d24f4c3 commit b79868a

2 files changed

Lines changed: 93 additions & 60 deletions

File tree

.github/workflows/publish.yml

Lines changed: 21 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,42 @@
1-
name: Release and Publish
1+
name: Publish to pub.dev
22

33
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.
138

149
jobs:
15-
release-and-publish:
10+
publish:
1611
runs-on: ubuntu-latest
1712
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
2014
steps:
2115
- 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
2519
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
2727
echo "working_directory=." >> "$GITHUB_OUTPUT"
28-
echo "tag_prefix=v" >> "$GITHUB_OUTPUT"
28+
echo "📦 Package: mcp_dart"
2929
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"
5031
exit 1
5132
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
7233
7334
- uses: dart-lang/setup-dart@v1
7435

7536
- name: Install dependencies
76-
working-directory: ${{ steps.set-config.outputs.working_directory }}
37+
working-directory: ${{ steps.package-info.outputs.working_directory }}
7738
run: dart pub get
7839

7940
- name: Publish to pub.dev
80-
working-directory: ${{ steps.set-config.outputs.working_directory }}
41+
working-directory: ${{ steps.package-info.outputs.working_directory }}
8142
run: dart pub publish --force

.github/workflows/release.yml

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

0 commit comments

Comments
 (0)