forked from mpetuska/kmdc
-
Notifications
You must be signed in to change notification settings - Fork 0
69 lines (66 loc) · 2.48 KB
/
resolve-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
name: Resolve Version
on:
workflow_call:
inputs:
desired-version:
type: string
description: Optional desired version
required: false
outputs:
version:
value: ${{ jobs.resolve.outputs.version }}
snapshot:
value: ${{ jobs.resolve.outputs.snapshot }}
concurrency:
cancel-in-progress: true
group: version-${{ github.workflow }}-${{ github.head_ref || github.ref }}
jobs:
resolve:
name: Resolve Version
runs-on: ubuntu-latest
env:
VERSION: ${{ inputs.desired-version }}
outputs:
version: ${{ steps.resolve.outputs.version }}
snapshot: ${{ steps.resolve.outputs.snapshot }}
steps:
- uses: actions/checkout@v4
- name: Resolve
id: resolve
run: |
project_version=$(cat gradle.properties | grep -Po '^version=\K(.+)')
version=${VERSION:=$project_version}
VERSION=${VERSION/v}
echo "PROJECT_VERSION=${project_version}" >> $GITHUB_ENV
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo "::set-output name=version::${VERSION}"
if [[ "$VERSION" != "$project_version" ]]; then
echo "DIFF_VERSION=1" >> $GITHUB_ENV
fi
if [[ "$VERSION" == *-SNAPSHOT ]]; then
echo "::set-output name=snapshot::true"
else
echo "::set-output name=snapshot::false"
fi
- name: Report
run: |
echo "VERSION=${{ env.VERSION }}"
echo "steps.resolve.outputs.version=${{ steps.resolve.outputs.version }}"
- name: Create Snapshot
if: env.DIFF_VERSION == '1'
run: |
main_version=$(echo $VERSION | grep -Po '^([0-9]+.){2}(?=.*)')
patch_version=$(echo $VERSION | grep -Po "^$main_version\\K([0-9]+)(?=.*)")
patch_version=$(expr $patch_version + 1)
SNAPSHOT_VERSION="${main_version}${patch_version}-SNAPSHOT"
echo "SNAPSHOT_VERSION=$SNAPSHOT_VERSION" >> $GITHUB_ENV
sed -Ei "s|^(version=).*\$|\\1$SNAPSHOT_VERSION|" gradle.properties
- name: Create Pull Request for new SNAPSHOT
if: env.DIFF_VERSION == '1' && env.PROJECT_VERSION != env.SNAPSHOT_VERSION
uses: peter-evans/create-pull-request@v6
with:
title: 'New SNAPSHOT - ${{ env.SNAPSHOT_VERSION }}'
commit-message: '[ci skip] New SNAPSHOT - ${{ env.SNAPSHOT_VERSION }}'
branch: ci/version/${{ env.SNAPSHOT_VERSION }}
delete-branch: true
base: master