Browse Source

Feature/version bump action (#14)

* Added version bump code and tests

* Added readme

* Added logic for .props file

* Updated action test for .props
pull/13/head
Micaiah Martin 4 years ago committed by GitHub
parent
commit
0c263b3963
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 53
      .github/workflows/test-version-bump.yml
  2. 11
      version-bump/Dockerfile
  3. 14
      version-bump/README.md
  4. 21
      version-bump/action.yml
  5. 81
      version-bump/main.py
  6. 20
      version-bump/tests/AndroidManifest.xml
  7. 26
      version-bump/tests/Info.plist
  8. 9
      version-bump/tests/dif.build.props
  9. 11
      version-bump/tests/package-lock.json

53
.github/workflows/test-version-bump.yml

@ -0,0 +1,53 @@ @@ -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 }}"

11
version-bump/Dockerfile

@ -0,0 +1,11 @@ @@ -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" ]

14
version-bump/README.md

@ -0,0 +1,14 @@ @@ -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"
```

21
version-bump/action.yml

@ -0,0 +1,21 @@ @@ -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"

81
version-bump/main.py

@ -0,0 +1,81 @@ @@ -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}")

20
version-bump/tests/AndroidManifest.xml

@ -0,0 +1,20 @@ @@ -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>

26
version-bump/tests/Info.plist

@ -0,0 +1,26 @@ @@ -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>

9
version-bump/tests/dif.build.props

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
<Project>
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>5.8</Version>
<RootNamespace>Acme.$(MSBuildProjectName)</RootNamespace>
</PropertyGroup>
</Project>

11
version-bump/tests/package-lock.json generated

@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
{
"name": "acme-test",
"version": "1.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"version": "1.0",
}
}
}
Loading…
Cancel
Save