-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (71 loc) · 2.96 KB
/
bump-mobile-version.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
name: Bump versions of Mobile App
on:
workflow_dispatch:
pull_request:
paths:
- "mobile-app/**"
branches:
- staging
jobs:
bump-version:
name: Bump version of package.json and app.json
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT }}
fetch-depth: 2
- name: Check recent commit messages
id: check_commits
shell: bash
run: |
# Fetch the PR base branch
git fetch origin ${{ github.base_ref }}
# Get the merge base between the PR head and base
MERGE_BASE=$(git merge-base HEAD origin/${{ github.base_ref }})
# Check the commits between the merge base and HEAD
COMMIT_MESSAGES=$(git log $MERGE_BASE..HEAD --format='%s')
echo "Commit messages since merge base:"
echo "$COMMIT_MESSAGES"
if echo "$COMMIT_MESSAGES" | grep -q "chore: minor mobile app version bump"; then
echo "has_version_bump=true" >> $GITHUB_OUTPUT
echo "A recent commit contains the version bump message. Stopping the workflow."
exit 0 # This will stop the workflow without failing it
else
echo "has_version_bump=false" >> $GITHUB_OUTPUT
echo "No version bump commit found. Continuing the workflow."
fi
- name: Setup Node.js
if: steps.check_commits.outputs.has_version_bump != 'true'
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Bump version
if: steps.check_commits.outputs.has_version_bump != 'true'
run: |
cd mobile-app
# Read current version from package.json
current_version=$(node -p "require('./package.json').version")
echo "Current version: $current_version"
# Increment patch version
new_version=$(node -e "
const [major, minor, patch] = '$current_version'.split('.');
console.log(\`\${major}.\${minor}.\${parseInt(patch) + 1}\`);
")
echo "New version: $new_version"
# Update package.json
jq --arg version "$new_version" '.version = $version' package.json > package.json.tmp && mv package.json.tmp package.json
# Update app.json
jq --arg version "$new_version" '.expo.version = $version' app.json > app.json.tmp && mv app.json.tmp app.json
echo "Updated version in package.json and app.json to $new_version"
- run: npm ci && npm run format
if: steps.check_commits.outputs.has_version_bump != 'true'
working-directory: mobile-app
- uses: stefanzweifel/git-auto-commit-action@v5
if: steps.check_commits.outputs.has_version_bump != 'true'
with:
commit_message: "chore: minor mobile app version bump"