Skip to content

Commit

Permalink
firsts step release pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
mafasva committed Mar 7, 2024
1 parent 4803df3 commit 5b176f7
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 21 deletions.
44 changes: 23 additions & 21 deletions .github/workflows/create-release-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,50 +21,52 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: master
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
- name: Create version
id: createVersion
run: |
CURRENT_VERSION=$(./mvnw -q -Dexec.executable='echo' -Dexec.args='${project.version}' --non-recursive exec:exec)
echo $CURRENT_VERSION
CURRENT_VERSION=$(mvn -q -Dexec.executable='echo' -Dexec.args='${project.version}' --non-recursive exec:exec)
echo "Current version: $CURRENT_VERSION"
MAJOR=`echo $CURRENT_VERSION | cut -d. -f1`
MINOR=`echo $CURRENT_VERSION | cut -d. -f2`
PATCH=`echo $CURRENT_VERSION | cut -d. -f3 | cut -d- -f1`
if [ ${{ inputs.release }} == 'major' ]
then
VERSION=${MAJOR+1}.0.0
DEV_VERSION=${MAJOR}.1.0-SNAPSHOT
elif [ ${{ inputs.release }} == 'minor' ]
then
VERSION=${MAJOR}.${MINOR}.0
DEV_VERSION=${MAJOR}.${MINOR+1}.0-SNAPSHOT
if [ ${{ inputs.release }} == 'major' ]; then
MAJOR=$((MAJOR+1))
MINOR=0
PATCH=0
elif [ ${{ inputs.release }} == 'minor' ]; then
MINOR=$((MINOR+1))
PATCH=0
else
VERSION=${MAJOR}.${MINOR-1}.${PATCH+1}
DEV_VERSION=${MAJOR}.${MINOR}.0-SNAPSHOT
PATCH=$((PATCH+1))
fi
echo $VERSION
VERSION=${MAJOR}.${MINOR}.${PATCH}
echo
echo "Release version: $VERSION"
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
- name: Create release branch
env:
VERSION: ${{ steps.createVersion.outputs.VERSION }}
run: |
git branch origin/develop
git branch release/$VERSION
mvn versions:set -DnewVersion=${VERSION}-SNAPSHOT versions:commit
git commit -am "updated project version to ${VERSION}"
git push --set-upstream origin release/$VERSION
- name: Create branch to update develop version
run: |
git branch feature/update_develop_version_${DEV_VERSION}
mvn versions:set -DnewVersion=${DEV_VERSION} versions:commit
git commit -am "updated development version to ${DEV_VERSION}"
git push --set-upstream origin feature/update_develop_version_${DEV_VERSION}
wrong_branch:
if: github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/develop'
Expand Down
110 changes: 110 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: release

on:
workflow_dispatch:
branches: [ 'release/**' ]

env:
RELEASE_VERSION: ''
DEV_VERSION: ''

jobs:

read_version:
runs-on: ubuntu-latest

outputs:
DEV_VERSION: ${{ steps.createVersion.outputs.DEV_VERSION}}
RELEASE_VERSION: ${{ steps.createVersion.outputs.RELEASE_VERSION}}

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
- name: Create new development version
id: createVersion
run: |
RELEASE_VERSION=$(mvn -q -Dexec.executable='echo' -Dexec.args='${project.version}' --non-recursive exec:exec)
echo "Current version: $RELEASE_VERSION"
MAJOR=`echo $RELEASE_VERSION | cut -d. -f1`
MINOR=`echo $RELEASE_VERSION | cut -d. -f2`
DEV_VERSION=${MAJOR}.$((MINOR+1)).0-SNAPSHOT
echo
echo "Release version: $RELEASE_VERSION"
echo "Develop version: $DEV_VERSION"
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "$GITHUB_OUTPUT"
echo "DEV_VERSION=${DEV_VERSION}" >> "$GITHUB_OUTPUT"
update_dev:
needs: read_version
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
- name: Create branch to update develop version
env:
DEV_VERSION: ${{ needs.read_version.outputs.DEV_VERSION }}
run: |
git branch feature/update_develop_${DEV_VERSION}
mvn versions:set -DnewVersion=${DEV_VERSION} versions:commit
git commit -am "updated development version to ${DEV_VERSION}"
git push --set-upstream origin feature/update_develop_${DEV_VERSION}
- name: Create PR to merge changes to Develop and update Version
env:
RELEASE_VERSION: ${{ needs.read_version.outputs.RELEASE_VERSION }}
run: |
gh pr create -B develop --title "Merge release branch '${RELEASE_VERSION} back to develop"
gh pr review --approve
gh pr merge --auto --delete-branch --squash
release:
needs: read_version
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
- name: Create branch to update develop version
env:
DEV_VERSION: ${{ needs.read_version.outputs.DEV_VERSION }}
run: mvn versions:set -DremoveSnapshot
- name: Create PR to merge release branch to main
env:
RELEASE_VERSION: ${{ needs.read_version.outputs.RELEASE_VERSION }}
run: |
gh pr create -B master --title "Merge release branch '${RELEASE_VERSION}"
gh pr review --approve
gh pr merge --auto --delete-branch --squash
wrong_branch:
if: github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/develop'

runs-on: ubuntu-latest

steps:
- name: ERROR
run: echo 'This workflow only runs on develop branch!'

0 comments on commit 5b176f7

Please sign in to comment.