Skip to content

Commit

Permalink
GitHub Action: bump version and commits/PR
Browse files Browse the repository at this point in the history
  • Loading branch information
timo-a committed Jun 10, 2021
1 parent 73d74dc commit 4d61aaa
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/incrementVersionName.py
Original file line number Diff line number Diff line change
@@ -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)
63 changes: 63 additions & 0 deletions .github/workflows/version-bump-Commit.yml
Original file line number Diff line number Diff line change
@@ -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 "[email protected]"
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/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
61 changes: 61 additions & 0 deletions .github/workflows/version-bump-PR.yml
Original file line number Diff line number Diff line change
@@ -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

51 changes: 51 additions & 0 deletions .github/workflows/version-code-bump-Commit.yml
Original file line number Diff line number Diff line change
@@ -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 "[email protected]"
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/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}

0 comments on commit 4d61aaa

Please sign in to comment.