forked from tim3z/SudoQ
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GitHub Action: bump version and commits/PR
- Loading branch information
Showing
4 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
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
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) |
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
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 }} |
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
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 | ||
|
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
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 }} |