Skip to content

Create release

Create release #41

name: Create release
on:
workflow_dispatch:
inputs:
dry_run:
description: "Dry run"
required: false
type: boolean
default: false
workflow_run:
workflows: [ "Build" ]
types:
- completed
jobs:
check_version_and_release:
if: >
${{ github.event_name == 'workflow_dispatch' ||
(github.event_name == 'workflow_run' &&
github.event.workflow_run.head_branch == 'main' &&
github.event.workflow_run.conclusion == 'success')
}}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Resolve dry run flags
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "dry_run=${{ github.event.inputs.dry_run }}" >> $GITHUB_ENV
else
echo "dry_run=false" >> $GITHUB_ENV
fi
- name: Extract VERSION from Gradle properties
id: extract_version
run: |
# Extract the current version
CURRENT_VERSION=$(grep "^VERSION=" gradle.properties | cut -d'=' -f2)
echo "current_version=$CURRENT_VERSION" >> $GITHUB_ENV
# Get the previous commit hash for comparison
PREV_COMMIT=$(git rev-parse HEAD^)
# Extract the previous version from the previous commit
PREV_VERSION=$(git show $PREV_COMMIT:gradle.properties | grep "^VERSION=" | cut -d'=' -f2)
echo "previous_version=$PREV_VERSION" >> $GITHUB_ENV
- name: Check for version update
id: check_version_update
run: |
echo "Current version: $current_version"
echo "Previous version: $previous_version"
if [[ "$current_version" != "$previous_version" ]]; then
echo "VERSION has changed: $previous_version -> $current_version"
echo "version_changed=true" >> $GITHUB_ENV
else
echo "VERSION has not changed."
echo "version_changed=false" >> $GITHUB_ENV
fi
- name: Create release on version changes
if: env.dry_run == 'false' && env.version_changed == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "$current_version" \
--title "$current_version" \
--generate-notes \
git tag "$current_version"
git push origin "$current_version"