Create main.yml #1
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] | |
pull_request: | |
branches: [main] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
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 |