forked from quarck/CalendarNotification
-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (112 loc) · 4.87 KB
/
version-bump.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
name: Update Version on PR Merge to Master
on:
push:
branches:
- 'master'
workflow_dispatch: # Allow manual triggering of the workflow
jobs:
update-version:
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
# Only run if the commit message does not start with 'build:'
if: startsWith(github.event.head_commit.message, 'build:') != true
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.VERSION_BUMP_DEPLOY_PRIVATE_KEY }}
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
cache: 'yarn'
- name: Expose yarn config as "$GITHUB_OUTPUT"
id: yarn-config
shell: bash
run: |
echo "CACHE_FOLDER=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
# Yarn rotates the downloaded cache archives, @see https://github.com/actions/setup-node/issues/325
# Yarn cache is also reusable between arch and os.
- name: Restore yarn cache
uses: actions/cache@v4
id: yarn-download-cache
with:
path: ${{ steps.yarn-config.outputs.CACHE_FOLDER }}
key: yarn-download-cache-${{ hashFiles('yarn.lock') }}
restore-keys: |
yarn-download-cache-
# Invalidated on yarn.lock changes
- name: Restore yarn install state
id: yarn-install-state-cache
uses: actions/cache@v4
with:
path: .yarn/ci-cache/
key: ${{ runner.os }}-yarn-install-state-cache-${{ hashFiles('yarn.lock', '.yarnrc.yml') }}
- run: yarn install --immutable --inline-builds
env:
# CI optimizations. Overrides yarnrc.yml options (or their defaults) in the CI action.
YARN_ENABLE_GLOBAL_CACHE: 'false' # Use local cache folder to keep downloaded archives
YARN_NM_MODE: 'hardlinks-local' # Hardlinks-(local|global) reduces io / node_modules size
YARN_INSTALL_STATE_PATH: .yarn/ci-cache/install-state.gz # Very small speedup when lock does not change
# Other environment variables
HUSKY: '0' # By default do not run HUSKY install
- name: Get new version
id: get-version
run: |
# Run semantic-release with full output for debugging
set +e # Don't exit on error
SEMANTIC_OUTPUT=$(npx semantic-release --dry-run --debug 2>&1)
SEMANTIC_EXIT_CODE=$?
set -e # Re-enable exit on error
echo "semantic-release output:"
echo "$SEMANTIC_OUTPUT"
if [ $SEMANTIC_EXIT_CODE -ne 0 ]; then
echo "semantic-release failed with exit code $SEMANTIC_EXIT_CODE"
exit 1
fi
# Try to extract the version
VERSION_SPACES=$(echo "$SEMANTIC_OUTPUT" | grep -oP 'Published release \K.*? ' || echo "")
VERSION="${VERSION_SPACES// /}"
if [ -z "$VERSION" ]; then
echo "No new version to be published."
VERSION=""
else
echo "Extracted version: $VERSION"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Log If no version to bump t
if: steps.get-version.outputs.version == ''
run: |
echo "No version to bump to!"
- name: Update versionName in build.gradle
if: steps.get-version.outputs.version != ''
run: |
echo "Updating versionName to ${{ steps.get-version.outputs.version }}"
sed -i 's/versionName ".*"/versionName "${{ steps.get-version.outputs.version }}"/' android/app/build.gradle
- name: Increment versionCode in build.gradle
if: steps.get-version.outputs.version != ''
run: |
# Get the current versionCode
CURRENT_VERSION_CODE=$(grep -oP 'versionCode\s+\K\d+' android/app/build.gradle)
# Increment the versionCode
NEW_VERSION_CODE=$((CURRENT_VERSION_CODE + 1))
# Update the versionCode in build.gradle
sed -i "s/versionCode $CURRENT_VERSION_CODE/versionCode $NEW_VERSION_CODE/" android/app/build.gradle
echo "Incremented versionCode from $CURRENT_VERSION_CODE to $NEW_VERSION_CODE"
- name: Commit and push changes
if: steps.get-version.outputs.version != ''
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add android/app/build.gradle
git commit -m "build: version bump ${{ steps.get-version.outputs.version }}"
git push
- name: Setup tmate session
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3
with:
limit-access-to-actor: true