Browse Source
* Added version bump code and tests * Added readme * Added logic for .props file * Updated action test for .propspull/13/head
9 changed files with 246 additions and 0 deletions
@ -0,0 +1,53 @@ |
|||||||
|
--- |
||||||
|
|
||||||
|
name: Test Version Bump Action |
||||||
|
|
||||||
|
on: |
||||||
|
workflow_dispatch: |
||||||
|
inputs: |
||||||
|
version_number: |
||||||
|
description: "New Version" |
||||||
|
required: true |
||||||
|
|
||||||
|
jobs: |
||||||
|
build: |
||||||
|
runs-on: ubuntu-latest |
||||||
|
steps: |
||||||
|
- uses: actions/checkout@v2 |
||||||
|
|
||||||
|
- name: Bump JSON Test |
||||||
|
id: test_json |
||||||
|
uses: ./version-bump |
||||||
|
with: |
||||||
|
version: ${{ github.event.inputs.version_number }} |
||||||
|
file_path: "./version-bump/tests/package-lock.json" |
||||||
|
|
||||||
|
- name: Bump PLIST Test |
||||||
|
id: test_plist |
||||||
|
uses: ./version-bump |
||||||
|
with: |
||||||
|
version: ${{ github.event.inputs.version_number }} |
||||||
|
file_path: "./version-bump/tests/Info.plist" |
||||||
|
|
||||||
|
- name: Bump XML Test |
||||||
|
id: test_xml |
||||||
|
uses: ./version-bump |
||||||
|
with: |
||||||
|
version: ${{ github.event.inputs.version_number }} |
||||||
|
file_path: "./version-bump/tests/AndroidManifest.xml" |
||||||
|
|
||||||
|
- name: Bump Props Test |
||||||
|
id: test_props |
||||||
|
uses: ./version-bump |
||||||
|
with: |
||||||
|
version: ${{ github.event.inputs.version_number }} |
||||||
|
file_path: "./version-bump/tests/dir.build.props" |
||||||
|
|
||||||
|
- name: Validate Outputs |
||||||
|
run: | |
||||||
|
echo "${{ steps.test_json.outputs.status }}" |
||||||
|
echo "${{ steps.test_plist.outputs.status }}" |
||||||
|
echo "${{ steps.test_xml.outputs.status }}" |
||||||
|
echo "${{ steps.test_props.outputs.status }}" |
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,11 @@ |
|||||||
|
FROM python:3-slim |
||||||
|
|
||||||
|
ADD . /app |
||||||
|
|
||||||
|
WORKDIR /app |
||||||
|
|
||||||
|
RUN pip3 install lxml --target=/app |
||||||
|
|
||||||
|
ENV PYTHONPATH /app |
||||||
|
|
||||||
|
ENTRYPOINT [ "python", "/app/main.py" ] |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
# Version Bump Action |
||||||
|
|
||||||
|
A Github Action that will replace versions in JSON, PLIST, and XML files. Specifically created for interacting with AndroidManifest, iOS development plists, and Node package JSON files. |
||||||
|
|
||||||
|
## Usage |
||||||
|
|
||||||
|
```yml |
||||||
|
- name: Bump Android Version |
||||||
|
uses: ./version-bump |
||||||
|
with: |
||||||
|
version: ${{ github.event.inputs.version_number }} |
||||||
|
file_path: "./AndroidManifest.xml" |
||||||
|
``` |
||||||
|
|
||||||
@ -0,0 +1,21 @@ |
|||||||
|
name: "PLIST/XML/JSON Version Bump" |
||||||
|
description: "Replaces versions in PLIST/JSON/XML for easier version updating." |
||||||
|
author: "Bitwarden" |
||||||
|
branding: |
||||||
|
icon: download |
||||||
|
color: blue |
||||||
|
inputs: |
||||||
|
version: |
||||||
|
description: "Newest version to use." |
||||||
|
default: "1.0" |
||||||
|
required: true |
||||||
|
file_path: |
||||||
|
description: "Path to the file to apply the new version." |
||||||
|
default: "./" |
||||||
|
required: true |
||||||
|
outputs: |
||||||
|
status: |
||||||
|
description: "Status" |
||||||
|
runs: |
||||||
|
using: "docker" |
||||||
|
image: "Dockerfile" |
||||||
@ -0,0 +1,81 @@ |
|||||||
|
import os |
||||||
|
import json |
||||||
|
import plistlib |
||||||
|
import lxml.etree as ET |
||||||
|
|
||||||
|
|
||||||
|
def get_file_type(file): |
||||||
|
file_type = os.path.splitext(file)[1] |
||||||
|
return file_type |
||||||
|
|
||||||
|
|
||||||
|
def update_json(version, file): |
||||||
|
with open(file) as json_file: |
||||||
|
data = json.load(json_file) |
||||||
|
data["version"] = version |
||||||
|
try: |
||||||
|
data["packages"][""]["version"] = version |
||||||
|
except KeyError: |
||||||
|
pass |
||||||
|
json.dump(data, open(file, "w"), indent=2) |
||||||
|
|
||||||
|
|
||||||
|
def update_plist(version, file): |
||||||
|
with open(file, "rb") as plist: |
||||||
|
|
||||||
|
pl = plistlib.load(plist) |
||||||
|
pl["CFBundleShortVersionString"] = version |
||||||
|
|
||||||
|
data = pl |
||||||
|
with open(file, "wb") as update_plist: |
||||||
|
plistlib.dump(data, update_plist, sort_keys=False) |
||||||
|
|
||||||
|
|
||||||
|
def update_xml(version, file): |
||||||
|
mytree = ET.parse(file) |
||||||
|
myroot = mytree.getroot() |
||||||
|
|
||||||
|
# Android Manifests |
||||||
|
if myroot.tag == "manifest": |
||||||
|
myroot.attrib[ |
||||||
|
"{http://schemas.android.com/apk/res/android}versionName" |
||||||
|
] = version |
||||||
|
ET.register_namespace( |
||||||
|
"android", "http://schemas.android.com/apk/res/android") |
||||||
|
ET.register_namespace( |
||||||
|
"tools", "http://schemas.android.com/tools") |
||||||
|
mytree.write( |
||||||
|
file, encoding="utf-8", xml_declaration=True, pretty_print=True) |
||||||
|
else: |
||||||
|
# MSBuild Props |
||||||
|
myroot[0][1].text = version |
||||||
|
mytree.write( |
||||||
|
file, encoding="utf-8" |
||||||
|
) |
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__": |
||||||
|
version = os.getenv("INPUT_VERSION") |
||||||
|
file_path = os.getenv("INPUT_FILE_PATH") |
||||||
|
|
||||||
|
# Throw an exception if there is no file path defined. |
||||||
|
try: |
||||||
|
os.path.isfile(file_path) |
||||||
|
except TypeError: |
||||||
|
raise Exception(f"File path for {file_path} not found.") |
||||||
|
|
||||||
|
|
||||||
|
file_type = get_file_type(file_path) |
||||||
|
|
||||||
|
|
||||||
|
# Handle the file based on the extension. |
||||||
|
if file_type == ".xml" or file_type == ".props": |
||||||
|
update_xml(version, file_path) |
||||||
|
elif file_type == ".json": |
||||||
|
update_json(version, file_path) |
||||||
|
elif file_type == ".plist": |
||||||
|
update_plist(version, file_path) |
||||||
|
else: |
||||||
|
raise Exception("No file was recognized as a supported format.") |
||||||
|
|
||||||
|
print(f"::set-output name=status::Updated {file_path}") |
||||||
@ -0,0 +1,20 @@ |
|||||||
|
<?xml version='1.0' encoding='UTF-8'?> |
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:versionCode="1" android:versionName="10.2" android:installLocation="internalOnly" package="com.acme.test"> |
||||||
|
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="30"/> |
||||||
|
<uses-permission android:name="android.permission.INTERNET"/> |
||||||
|
<uses-permission android:name="android.permission.NFC"/> |
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> |
||||||
|
<uses-permission android:name="android.permission.CAMERA"/> |
||||||
|
<uses-permission android:name="android.permission.USE_FINGERPRINT"/> |
||||||
|
<uses-permission android:name="android.permission.USE_BIOMETRIC"/> |
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> |
||||||
|
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> |
||||||
|
<uses-feature android:name="android.hardware.camera" android:required="false"/> |
||||||
|
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/> |
||||||
|
<!-- Package visibility (for Android 11+) --> |
||||||
|
<queries> |
||||||
|
<intent> |
||||||
|
<action android:name="*"/> |
||||||
|
</intent> |
||||||
|
</queries> |
||||||
|
</manifest> |
||||||
@ -0,0 +1,26 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
||||||
|
<plist version="1.0"> |
||||||
|
<dict> |
||||||
|
<key>MinimumOSVersion</key> |
||||||
|
<string>10.0</string> |
||||||
|
<key>CFBundleDisplayName</key> |
||||||
|
<string>Acme</string> |
||||||
|
<key>CFBundleName</key> |
||||||
|
<string>Acme Extension</string> |
||||||
|
<key>CFBundleIdentifier</key> |
||||||
|
<string>com.org.Acme.ext</string> |
||||||
|
<key>CFBundleShortVersionString</key> |
||||||
|
<string>6.20</string> |
||||||
|
<key>CFBundleLocalizations</key> |
||||||
|
<key>CFBundleDevelopmentRegion</key> |
||||||
|
<string>en</string> |
||||||
|
<key>CFBundleInfoDictionaryVersion</key> |
||||||
|
<string>6.0</string> |
||||||
|
<key>CFBundlePackageType</key> |
||||||
|
<string>XPC!</string> |
||||||
|
<key>CFBundleSignature</key> |
||||||
|
<string>????</string> |
||||||
|
<key>UIDeviceFamily</key> |
||||||
|
</dict> |
||||||
|
</plist> |
||||||
@ -0,0 +1,9 @@ |
|||||||
|
<Project> |
||||||
|
|
||||||
|
<PropertyGroup> |
||||||
|
<TargetFramework>net5.0</TargetFramework> |
||||||
|
<Version>5.8</Version> |
||||||
|
<RootNamespace>Acme.$(MSBuildProjectName)</RootNamespace> |
||||||
|
</PropertyGroup> |
||||||
|
|
||||||
|
</Project> |
||||||
Loading…
Reference in new issue