generated from LarsBodewig/Template
-
Notifications
You must be signed in to change notification settings - Fork 0
68 lines (67 loc) · 2.45 KB
/
set-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
# Updates the maven version and checks in
name: Set version
on:
workflow_dispatch:
inputs:
version:
description: 'Set version'
required: false
type: string
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'oracle'
java-version: '17'
- name: Evaluate old version
if: ${{ inputs.version == '' }}
run: |
echo "oldVersion=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> "$GITHUB_ENV"
- name: Set next snapshot
if: ${{ inputs.version == '' && !endsWith(env.oldVersion, '-SNAPSHOT') }}
run: |
mvn -B versions:set -DgenerateBackupPoms=false -DnextSnapshot=true
echo "commitMsg=Next snapshot version" >> "$GITHUB_ENV"
- name: Remove snapshot
if: ${{ inputs.version == '' && endsWith(env.oldVersion, '-SNAPSHOT') }}
run: |
mvn -B versions:set -DgenerateBackupPoms=false -DremoveSnapshot=true
echo "commitMsg=Remove snapshot version" >> "$GITHUB_ENV"
- name: Set version
if: ${{ inputs.version != '' }}
run: |
mvn -B versions:set -DgenerateBackupPoms=false -DnewVersion=${{ inputs.version }}
echo "commitMsg=Set version to $inputs.version" >> "$GITHUB_ENV"
- name: Evaluate new version
if: ${{ inputs.version == '' && endsWith(env.oldVersion, '-SNAPSHOT') }}
run: |
echo "newVersion=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> "$GITHUB_ENV"
- name: Update version in README
if: ${{ inputs.version == '' && endsWith(env.oldVersion, '-SNAPSHOT') }}
uses: richardrigutins/replace-in-files@v2
with:
files: 'README.md'
search-text: '${{ env.oldVersion }}'
replacement-text: '${{ env.newVersion }}'
encoding: 'utf8'
- name: Commit changes
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "$commitMsg"
- name: Set and push tag
if: ${{ inputs.version == '' && endsWith(env.oldVersion, '-SNAPSHOT') }}
run: |
git tag -a "v$inputs.version" -m "v$inputs.version" -f
git push origin v$inputs.version -f
- name: Push commit
run: |
git push -f