-
Notifications
You must be signed in to change notification settings - Fork 12
136 lines (113 loc) · 4.11 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: Publish hypersdkflutter to pub.dev
on:
pull_request_target:
branches:
- main
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
types:
- closed
permissions:
contents: write
jobs:
dry-run:
runs-on: ubuntu-latest
name: Flutter Pub Publish --dry-run
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.13.0'
- name: Install dependencies
run: flutter pub get
- name: Run flutter pub publish --dry-run
run: flutter pub publish --dry-run
publish:
if: (github.event.pull_request.merged == true && !contains(github.event.pull_request.title, '[skip ci]')) || github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
name: Publish Package to Pub.dev
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.13.0'
- name: Install dependencies
run: flutter pub get
- name: Determine release type
id: determine-release
run: |
shopt -s nocasematch
# Determine release type based on pull request title
if [[ "${{ github.event.pull_request.title }}" =~ (\[breaking\]|\[major\]) ]]; then
echo "release_type=major" >> $GITHUB_OUTPUT
elif [[ "${{ github.event.pull_request.title }}" =~ \[minor\] ]]; then
echo "release_type=minor" >> $GITHUB_OUTPUT
else
echo "release_type=patch" >> $GITHUB_OUTPUT
fi
shopt -u nocasematch
shell: bash
- name: Generate new version
id: new_version
run: |
# Get the current version from pubspec.yaml
CURRENT_VERSION=$(grep 'version: ' pubspec.yaml | sed 's/version: //;s/+.*//')
echo "Current version is: $CURRENT_VERSION"
# Split the current version into major, minor, and patch
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION"
echo "major : $major"
echo "minor : $minor"
echo "patch : $patch"
# Check if the version parts are valid
if [[ -z "$major" || -z "$minor" || -z "$patch" ]]; then
echo "Invalid version format: $CURRENT_VERSION"
exit 1
fi
# Determine the release type (major, minor, or patch) based on PR title
RELEASE_TYPE="${{ steps.determine-release.outputs.release_type }}"
if [[ "$RELEASE_TYPE" == "major" ]]; then
NEW_MAJOR=$((major + 1))
NEW_MINOR=0
NEW_PATCH=0
NEW_VERSION="$NEW_MAJOR.0.0"
elif [[ "$RELEASE_TYPE" == "minor" ]]; then
NEW_MINOR=$((minor + 1))
NEW_PATCH=0
NEW_VERSION="$major.$NEW_MINOR.0"
else
NEW_PATCH=$((patch + 1))
NEW_VERSION="$major.$minor.$NEW_PATCH"
fi
echo "New version will be: $NEW_VERSION"
echo "new_version=$NEW_VERSION" >> $GITHUB_ENV
shell: bash
- name: Stash changes
run: git reset --hard
- name: git config
run: |
git config --local user.name 'hyper-sdk-app[bot]'
git config --local user.email '163947841+hyper-sdk-app[bot]@users.noreply.github.com'
- name: Update version in pubspec.yaml
run: |
# Update the version in pubspec.yaml
sed -i "s/^version: .*/version: ${{ env.new_version }}/" pubspec.yaml
# Commit the updated pubspec.yaml file
git add pubspec.yaml
git commit -m "chore: bump version to ${{ env.new_version }}"
shell: bash
- name: Tag the new version
run: |
git tag "v${{ env.new_version }}"
git push origin "v${{ env.new_version }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to pub.dev
uses: k-paxian/[email protected]
with:
credentialJson: ${{ secrets.PUB_PUBLISH_TOKEN }}
flutter: true
skipTests: true