Skip to content

Commit 1d3c93f

Browse files
authored
Merge pull request #43 from flyway/auto-version
Create Auto-Versioning Github Action
2 parents 02ce47e + 87c5632 commit 1d3c93f

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

.github/workflows/autoversion.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Auto-Version new contributions to Flyway Community DB Support
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
types:
7+
- closed
8+
jobs:
9+
auto-version:
10+
if: github.event.pull_request.merged == true
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout Flyway Community DB Support
14+
uses: actions/checkout@v4
15+
with:
16+
ref: main
17+
fetch-tags: true
18+
- name: Set up JDK 17
19+
uses: actions/setup-java@v4
20+
with:
21+
java-version: 17
22+
distribution: 'temurin'
23+
cache: 'maven'
24+
- name: Check for new module
25+
id: check_module
26+
run: |
27+
git fetch --tags -q
28+
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
29+
if git diff --diff-filter=ADR --name-only $LATEST_TAG..HEAD -- '*pom.xml' | grep -q pom.xml; then
30+
echo "NEW_MODULE=true" >> $GITHUB_OUTPUT
31+
else
32+
echo "NEW_MODULE=false" >> $GITHUB_OUTPUT
33+
fi
34+
- name: Update version
35+
id: update_version
36+
run: |
37+
if ${{ steps.check_module.outputs.NEW_MODULE }}; then
38+
NEW_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | awk -F'[.-]' '{print $1"."$2+1".0"}')
39+
else
40+
NEW_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | awk -F'[.-]' '{print $1"."$2"."$3+1}')
41+
fi
42+
mvn versions:set -DnewVersion=$NEW_VERSION
43+
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT
44+
- name: Commit and tag
45+
uses: EndBug/add-and-commit@v9
46+
with:
47+
author_name: rg-buildmonkey
48+
author_email: github-buildmonkey@red-gate.com
49+
message: 'Bump Flyway Community DB Support to ${{ steps.update_version.outputs.NEW_VERSION }}'
50+
tag: '${{ steps.update_version.outputs.NEW_VERSION }}'

0 commit comments

Comments
 (0)