Merge pull request #15 from protegeproject/WHO-setup #21
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
on: | |
push: | |
branches: | |
- main | |
- main-who | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
if: ${{ github.actor != 'protegeproject-bot[bot]' }} | |
steps: | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{secrets.DOCKER_USERNAME}} | |
password: ${{secrets.DOCKER_PASSWORD}} | |
- uses: actions/create-github-app-token@v1 | |
id: app-token | |
with: | |
app-id: ${{ vars.PROTEGEPROJECT_BOT_APP_ID }} | |
private-key: ${{ secrets.PROTEGEPROJECT_BOT_APP_PRIVATE_KEY }} | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ steps.app-token.outputs.token }} | |
ref: ${{ github.head_ref }} | |
- name: Set up Maven Central Repository | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'adopt' | |
server-id: docker.io | |
server-username: DOCKER_USERNAME | |
server-password: DOCKER_PASSWORD | |
- name: Get current version | |
id: get-version | |
run: | | |
current_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) | |
echo "Current version: $current_version" | |
echo "::set-output name=current_version::$current_version" | |
- name: Bump version | |
id: bump | |
run: | | |
current_version=${{ steps.get-version.outputs.current_version }} | |
branch=${GITHUB_REF##*/} | |
echo "Current branch: $branch" | |
# Extract the base version without suffix | |
base_version=$(echo $current_version | sed -E 's/(-.*)?$//') | |
# Increment the base version (assuming semantic versioning) | |
IFS='.' read -r -a version_parts <<< "$base_version" | |
version_parts[2]=$((version_parts[2] + 1)) | |
new_base_version="${version_parts[0]}.${version_parts[1]}.${version_parts[2]}" | |
if [[ "$branch" == "main-who" ]]; then | |
new_version="${new_base_version}-WHO" | |
else | |
new_version="$new_base_version" | |
fi | |
echo "New version: $new_version" | |
mvn versions:set -DnewVersion=$new_version -DgenerateBackupPoms=false | |
echo ":: set-output name=new_version::$new_version" | |
- name: Commit new version | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add pom.xml | |
git commit -m "Bump version to ${{ steps.bump.outputs.new_version }}" | |
git tag ${{ steps.bump.outputs.new_version }} | |
git push origin HEAD:${GITHUB_REF##*/} | |
git push origin ${{ steps.bump.outputs.new_version }} | |
- name: Build and Publish package | |
run: mvn --batch-mode -Prelease package dockerfile:push | |
- name: Release | |
uses: softprops/action-gh-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.bump.outputs.new_version }} | |
generate_release_notes: true | |
env: | |
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}} | |
DOCKER_TOKEN: ${{secrets.DOCKER_PASSWORD}} |