diff --git a/.github/workflows/incrementVersionName.py b/.github/workflows/incrementVersionName.py new file mode 100644 index 00000000..aefde24a --- /dev/null +++ b/.github/workflows/incrementVersionName.py @@ -0,0 +1,57 @@ +import fileinput +import sys +import os + +#input validation +if not sys.argv[2]: + print("Error: no position argument given", file = sys.stderr ) + +print("file is: " + sys.argv[1]) +print("position argument is: " + sys.argv[2]) + + +position = sys.argv[2] + +INCREMENT = 0 +OVERRIDE = 1 + + + +if position in ["M","m","p"]: + print(f"increment ({position})") + operation = INCREMENT +else: + print(f"override old version with ({position})") + operation = OVERRIDE + + +def increment(versionName, severity): + (major, minor, patch) = versionName.split('.') + if severity == 'M': + major = str(int(major) + 1) + elif position == 'm': + minor = str(int(minor) + 1) + else: + patch = str(int(patch) + 1) + + versionNameIncremented = '.'.join((major, minor, patch)) + os.environ['NEW_VERSION_NAME'] = versionNameIncremented + return versionNameIncremented + + +for line in fileinput.input(files=(sys.argv[1]), inplace=True): + if line.find("android:versionName=") >= 0: + versionName = line.split('"')[1] + + if operation == INCREMENT: + newVersionName = increment(versionName, position) + else: + os.environ['NEW_VERSION_NAME'] = position + newVersionName = position + + line = line.replace(versionName, newVersionName) + print(line, end='') + +#save to file so we can use it later +with open("new_version_name.txt", "w") as f: + f.write(newVersionName) diff --git a/.github/workflows/version-bump-Commit.yml b/.github/workflows/version-bump-Commit.yml new file mode 100644 index 00000000..a0a0f149 --- /dev/null +++ b/.github/workflows/version-bump-Commit.yml @@ -0,0 +1,63 @@ +# This is a basic workflow to help you get started with Actions + +name: 'bump versionCode, versionName, commit' + +on: + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + inputs: + changeSeverity: + description: 'how severe are the changes? chose from (M)ajor, (m)inor, (p)atch, or write out the new version' + required: true + default: 'p' + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + increase-version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: increase version code + id: increase_version_code + env: + FILE: sudoq-app/sudoqapp/src/main/AndroidManifest.xml + run: | + echo "$(pwd)" + echo "get line number" + LINE_NUMBER=$(grep -n "android:versionCode=" $FILE | cut -f1 -d:) + echo "get version" + VERSION=$(sed -n ${LINE_NUMBER}p $FILE | grep -oE '[0-9]+') + echo "current version: ${VERSION}" + echo "replace version" + NEW_VERSION_CODE=$((VERSION+1)) + echo "new version code: ${NEW_VERSION_CODE}" + sed -i "${LINE_NUMBER}s/${VERSION}/${NEW_VERSION_CODE}/" $FILE + echo "::set-output name=new_version_code::$NEW_VERSION_CODE" + + # sets NEW_VERSION_NAME + - name: increase version name + id: increase_version_name + env: + FILE: sudoq-app/sudoqapp/src/main/AndroidManifest.xml + SCRIPT: .github/workflows/incrementVersionName.py + run : | + python $SCRIPT $FILE ${{ github.event.inputs.changeSeverity }} + echo "$NEW_VERSION_NAME" + echo "::set-output name=new_version_name::$(cat new_version_name.txt)" + + - name: commit files + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add -A + NEW_VERSION_CODE=${{ steps.increase_version_code.outputs.new_version_code }} + NEW_VERSION_NAME=${{ steps.increase_version_name.outputs.new_version_name }} + git commit -m "Version bump: code: ${NEW_VERSION_CODE}, name: ${NEW_VERSION_NAME}" -a + + - name: push changes + uses: ad-m/github-push-action@v0.6.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ github.ref }} diff --git a/.github/workflows/version-bump-PR.yml b/.github/workflows/version-bump-PR.yml new file mode 100644 index 00000000..6fc3688d --- /dev/null +++ b/.github/workflows/version-bump-PR.yml @@ -0,0 +1,61 @@ +# This is a basic workflow to help you get started with Actions + +name: bump versionCode, versionName, create PR + +on: + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + inputs: + changeSeverity: + description: 'how severe are the changes? chose from (M)ajor, (m)inor, (p)atch, or write out the new version' + required: true + default: 'p' +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + increase-version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: increase version code + id: increase_version_code + env: + FILE: sudoq-app/sudoqapp/src/main/AndroidManifest.xml + run: | + echo "$(pwd)" + echo "get line number" + LINE_NUMBER=$(grep -n "android:versionCode=" $FILE | cut -f1 -d:) + echo "get version" + VERSION=$(sed -n ${LINE_NUMBER}p $FILE | grep -oE '[0-9]+') + echo "current version: ${VERSION}" + echo "replace version" + NEW_VERSION_CODE=$((VERSION+1)) + echo "new version code: ${NEW_VERSION_CODE}" + sed -i "${LINE_NUMBER}s/${VERSION}/${NEW_VERSION_CODE}/" $FILE + echo "::set-output name=new_version_code::$NEW_VERSION_CODE" + + # sets NEW_VERSION_NAME + - name: increase version name + id: increase_version_name + env: + FILE: sudoq-app/sudoqapp/src/main/AndroidManifest.xml + SCRIPT: .github/workflows/incrementVersionName.py + run : | + python $SCRIPT $FILE ${{ github.event.inputs.changeSeverity }} + echo "$NEW_VERSION_NAME" + echo "::set-output name=new_version_name::$(cat new_version_name.txt)" + + - name: commit files + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: >- + Version bump: code: ${{ steps.increase_version_code.outputs.new_version_code }}, + name: ${{ steps.increase_version_code.outputs.new_version_name }} + title: '[Experiment] increase version' + body: > + This PR is auto-generated by + [create-pull-request](https://github.com/peter-evans/create-pull-request). + labels: report, automated pr + diff --git a/.github/workflows/version-code-bump-Commit.yml b/.github/workflows/version-code-bump-Commit.yml new file mode 100644 index 00000000..e2813652 --- /dev/null +++ b/.github/workflows/version-code-bump-Commit.yml @@ -0,0 +1,51 @@ +# This is a basic workflow to help you get started with Actions + +name: 'bump versionCode, commit' + +on: + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + inputs: + changeSeverity: + description: 'how severe are the changes? chose from (M)ajor, (m)inor, (p)atch, or write out the new version' + required: true + default: 'p' + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + increase-version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: increase version code + id: increase_version_code + env: + FILE: sudoq-app/sudoqapp/src/main/AndroidManifest.xml + run: | + echo "$(pwd)" + echo "get line number" + LINE_NUMBER=$(grep -n "android:versionCode=" $FILE | cut -f1 -d:) + echo "get version" + VERSION=$(sed -n ${LINE_NUMBER}p $FILE | grep -oE '[0-9]+') + echo "current version: ${VERSION}" + echo "replace version" + NEW_VERSION_CODE=$((VERSION+1)) + echo "new version code: ${NEW_VERSION_CODE}" + sed -i "${LINE_NUMBER}s/${VERSION}/${NEW_VERSION_CODE}/" $FILE + echo "::set-output name=new_version_code::$NEW_VERSION_CODE" + + - name: commit files + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add -A + NEW_VERSION_CODE=${{ steps.increase_version_code.outputs.new_version_code }} + git commit -m "Version code bump: code: ${NEW_VERSION_CODE}" -a + + - name: push changes + uses: ad-m/github-push-action@v0.6.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ github.ref }}