Set the version number to 0.7.0 #4
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: Sets the version for a release and tags the repo | |
run-name: Set the version number to ${{ inputs.version }} | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'The version to set for the release (e.g. 1.0.0)' | |
required: true | |
jobs: | |
setVersion: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: main | |
# You must use a personal access token when pushing the tag or it won't trigger the next workflow (purposefully done by GH to prevent runaway recursive workflows) | |
token: ${{ secrets.MY_GH_TOKEN }} | |
- name: Set version in build.gradle | |
run: | | |
# Update build.gradle with new version | |
echo "${{ github.event.inputs.version }}" | |
sed -i "s/version \"[^\"]*\"/version \"${{ github.event.inputs.version }}\"/g" MqttLibrary/build.gradle | |
- name: Set version in README example | |
run: | | |
echo "${{ github.event.inputs.version }}" | |
sed -i "s/implementation 'com.craxiom:mqttlibrary:[^\"]*\'/implementation 'com.craxiom:mqttlibrary:${{ github.event.inputs.version }}\'/g" README.md | |
- name: Commit and push changes | |
run: | | |
git config user.email "[email protected]" | |
git config user.name "Github Actions" | |
git add . | |
# Check for changes | |
if git diff --staged --quiet; then | |
echo "No changes to commit" | |
else | |
git commit -m "Bump version to ${{ env.VERSION_NAME }}" | |
git push origin main | |
fi | |
- name: Create and push tag | |
run: | | |
TAG="v${{ github.event.inputs.version }}" | |
git tag $TAG | |
git push origin $TAG |