-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
65 lines (52 loc) · 1.93 KB
/
action.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
name: Flutter Bump Version
description: This action increases the version number of a Flutter project when a pull request is merged.
inputs:
token:
description: 'The GitHub token to use'
required: true
branch:
description: 'The branch to checkout and to push the changes to'
required: false
default: 'main'
branding:
icon: 'arrow-up-circle'
color: 'blue'
runs:
using: 'composite'
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
ref: ${{ inputs.branch }}
token: ${{ inputs.token }}
- name: Increase version
id: versioning
shell: bash
run: |
# Extracting the current build number
buildNumber=$(grep 'version: ' pubspec.yaml | sed 's/.*+//')
# Incrementing the build number
newBuildNumber=$((buildNumber + 1))
# Pad the newBuildNumber with leading zeros to ensure it has at least 4 digits
paddedBuildNumber=$(printf "%04d" "$newBuildNumber")
# Extracting parts for the new version
minor=${paddedBuildNumber:${#paddedBuildNumber}-2}
middle=${paddedBuildNumber:${#paddedBuildNumber}-3:1}
major=${paddedBuildNumber:0:${#paddedBuildNumber}-3}
# Construct the new version
newVersion="$major.$middle.$minor"
# Update pubspec.yaml with the new version and build number
sed -i "s/version: .*/version: $newVersion+$newBuildNumber/" pubspec.yaml
echo "::set-output name=version::$newVersion"
- name: Commit changes
shell: bash
run: |
git config --local user.email '[email protected]'
git config --local user.name 'GitHub Action'
git add pubspec.yaml
git commit -m '${{ steps.versioning.outputs.version }}'
- name: Push changes
uses: ad-m/[email protected]
with:
github_token: ${{ inputs.token }}
branch: ${{ inputs.branch }}