Update main.yml #8
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: Version Tracker | |
on: | |
push: | |
branches: [main] | |
jobs: | |
build: | |
runs-on: self-hosted | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Get Current Version | |
id: get_version | |
run: | | |
VERSION=$(grep versionName app/build.gradle | awk -F'"' '{print $2}') | |
echo "::set-output name=current_version::$VERSION" | |
VERSION_CODE=$(grep versionCode app/build.gradle | awk '{print $2}') | |
echo "::set-output name=current_version_code::$VERSION_CODE" | |
- name: Increment Version | |
id: increment_version | |
shell: bash | |
run: | | |
CURRENT_VERSION="${{ steps.get_version.outputs.current_version }}" | |
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION" | |
patch=$((patch + 1)) | |
NEW_VERSION="v$major.$minor.$patch" | |
echo "::set-output name=new_version::$NEW_VERSION" | |
VERSION_CODE=$(( ${{ steps.get_version.outputs.current_version_code }} + 1 )) | |
echo "::set-output name=version_code::$VERSION_CODE" | |
- name: Update Version Code and Version Name in Gradle | |
run: | | |
sed -i "s/versionCode [0-9]\+/versionCode ${{ steps.increment_version.outputs.version_code }}/g" app/build.gradle | |
sed -i "s/versionName \"[0-9.]\+\"/versionName \"${{ steps.increment_version.outputs.new_version }}\"/g" app/build.gradle | |
git diff # Debug: Check changes | |
cat app/build.gradle # Debug: Check file content | |
git status # Debug: Check git status | |
- name: Commit changes | |
run: | | |
git config --global user.name "GitHub Actions Bot" | |
git config --global user.email "actions@github.com" | |
git add app/build.gradle # Or the specific file(s) you modified | |
git commit -m "Updated version to ${{ steps.increment_version.outputs.new_version }}" | |
git push |