Skip to content

Commit 4e95207

Browse files
committed
Refactor: Extract tag setup to reusable GitHub Action
This commit extracts the logic for setting up the tag and updating `pubspec.yaml` into a reusable GitHub Action. This simplifies the main workflow file and promotes code reuse. The `setup-tag` job has been removed from `release_flutter_app.yaml`, and its steps are now encapsulated in the new `.github/actions/setup-tag/action.yml` file. The `build-android` and `build-ios` jobs now use this new reusable action.
1 parent 6e291f3 commit 4e95207

2 files changed

Lines changed: 22 additions & 17 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: 'Setup Tag'
2+
description: 'Reusable action to setup tag'
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Set up tag
8+
shell: bash
9+
run: |
10+
TAG=${GITHUB_REF#refs/tags/} # e.g., v1.2.3
11+
echo "Using tag $TAG"
12+
# Remove leading 'v' if present
13+
VERSION=${TAG#v}
14+
echo "Setting version to $VERSION"
15+
# Update pubspec.yaml
16+
sed -i "s/^version:.*/version: $VERSION+$BUILD_NUMBER/" pubspec.yaml

.github/workflows/release_flutter_app.yaml

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,16 @@ on:
66
- '*' # Trigger on any new tag
77

88
jobs:
9-
setup-tag:
10-
runs-on: ubuntu-latest
11-
steps:
12-
- name: Checkout code
13-
uses: actions/checkout@v4
14-
15-
- name: Set version from tag
16-
run: |
17-
TAG=${GITHUB_REF#refs/tags/} # e.g., v1.2.3
18-
echo "Using tag $TAG"
19-
# Remove leading 'v' if present
20-
VERSION=${TAG#v}
21-
echo "Setting version to $VERSION"
22-
# Update pubspec.yaml
23-
sed -i "s/^version:.*/version: $VERSION+$BUILD_NUMBER/" pubspec.yaml
24-
259
build-android:
2610
runs-on: ubuntu-latest
27-
needs: setup-tag
2811

2912
steps:
3013
- name: Checkout code
3114
uses: actions/checkout@v4
3215

16+
- name: Set up tag
17+
uses: ./.github/actions/setup-tag
18+
3319
- name: Set up Flutter
3420
uses: ./.github/actions/setup-flutter
3521

@@ -53,6 +39,9 @@ jobs:
5339
- name: Checkout code
5440
uses: actions/checkout@v4
5541

42+
- name: Set up tag
43+
uses: ./.github/actions/setup-tag
44+
5645
- name: Set up Flutter
5746
uses: ./.github/actions/setup-flutter
5847

0 commit comments

Comments
 (0)