Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Windows compatibility #76

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 34 additions & 49 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
on:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

jobs:
test-apk:
runs-on: ubuntu-latest
Expand All @@ -13,10 +17,10 @@ jobs:
distribution: temurin
java-version: 21

- name: Get old version of Andorid Auto app for test purposes
- name: Get old version of Android Auto app for test purposes
run: wget "https://github.com/usefulness/storage/raw/master/android-auto-old.apk" -O old-apk.apk

- name: Get new version of Andorid Auto app for test purposes
- name: Get new version of Android Auto app for test purposes
run: wget "https://github.com/usefulness/storage/raw/master/android-auto-new.apk" -O new-apk.apk

- id: diffuse
Expand Down Expand Up @@ -83,10 +87,10 @@ jobs:
distribution: temurin
java-version: 21

- name: Get very old version of Andorid Auto app for test purposes
- name: Get very old version of Android Auto app for test purposes
run: wget "https://github.com/usefulness/storage/raw/master/android-auto-very-old.apk" -O very-old-apk.apk

- name: Get new version of Andorid Auto app for test purposes
- name: Get new version of Android Auto app for test purposes
run: wget "https://github.com/usefulness/storage/raw/master/android-auto-new.apk" -O new-apk.apk

- id: diffuse
Expand Down Expand Up @@ -142,8 +146,12 @@ jobs:
name: diffuse-output-2
path: ${{ steps.diffuse.outputs.diff-file }}

test-windows:
runs-on: windows-latest
smoke-test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
steps:
- uses: actions/checkout@v4

Expand All @@ -152,66 +160,43 @@ jobs:
distribution: temurin
java-version: 21

- uses: actions/setup-python@v5
with:
python-version: '3.x'

- run: python -m pip install requests

- name: Get old version of Andorid Auto app for test purposes
run: curl.exe --output old-apk.apk "https://github.com/usefulness/storage/raw/master/android-auto-old.apk"
- run: python3 -m pip install requests
shell: bash

- name: Get new version of Andorid Auto app for test purposes
run: curl.exe --output new-apk.apk "https://github.com/usefulness/storage/raw/master/android-auto-new.apk"
- name: Get Android Auto app APKs for test purposes
run: |
import requests
responseOld = requests.get("https://github.com/usefulness/storage/raw/master/android-auto-very-old.apk")
open("very-old-apk.apk", "wb").write(responseOld.content)
responseNew = requests.get("https://github.com/usefulness/storage/raw/master/android-auto-new.apk")
open("new-apk.apk", "wb").write(responseNew.content)
shell: python

- id: diffuse
- id: diffuse-custom-repo-hardcoded
uses: ./
if: ${{ false }} # diffuse isn't compatible with windows
with:
old-file-path: old-apk.apk
old-file-path: very-old-apk.apk
new-file-path: new-apk.apk
lib-version: 0.1.0
lib-version: 0.3.0
diffuse-repo: JakeWharton/diffuse
debug: true

- uses: actions/upload-artifact@v4
if: ${{ false }} # diffuse isn't compatible with windows
with:
name: diffuse-output-3
path: ${{ steps.diffuse.outputs.diff-file }}

test-macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21

- uses: actions/setup-python@v5
with:
python-version: '3.x'

- run: python -m pip install requests

- name: Get very old version of Andorid Auto app for test purposes
run: wget "https://github.com/usefulness/storage/raw/master/android-auto-very-old.apk" -O very-old-apk.apk
name: diffuse-custom-repo-hardcoded-${{ matrix.os }}
path: ${{ steps.diffuse-custom-repo-hardcoded.outputs.diff-file }}

- name: Get new version of Andorid Auto app for test purposes
run: wget "https://github.com/usefulness/storage/raw/master/android-auto-new.apk" -O new-apk.apk

- id: diffuse
- id: diffuse-custom-repo-latest
uses: ./
with:
old-file-path: very-old-apk.apk
new-file-path: new-apk.apk
debug: true
lib-version: latest
diffuse-repo: JakeWharton/diffuse
debug: true

- uses: actions/upload-artifact@v4
with:
name: diffuse-output-4
path: ${{ steps.diffuse.outputs.diff-file }}
name: diffuse-custom-repo-latest-${{ matrix.os }}
path: ${{ steps.diffuse-custom-repo-latest.outputs.diff-file }}

5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ branding:
runs:
using: 'composite'
steps:
- run: python3 -m pip install requests
shell: bash

- id: run-diffuse
env:
INPUT_OLD_FILE: ${{ inputs.old-file-path }}
Expand All @@ -99,5 +102,5 @@ runs:
INPUT_DIFFUSE_REPO: ${{ inputs.diffuse-repo }}
INPUT_DEBUG: ${{ inputs.debug }}
INPUT_GITHUB_TOKEN: ${{ github.token }}
run: python3 '${{ github.action_path }}'/entrypoint.py
run: python3 entrypoint.py
shell: bash
36 changes: 19 additions & 17 deletions entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import uuid
import zipfile
import stat
import sys
from itertools import zip_longest


Expand Down Expand Up @@ -45,37 +46,36 @@ def is_debug():
return os.getenv("INPUT_DEBUG", False)


def _escape(message):
return message.replace('\x00', '') \
.replace("\"", "")
def is_windows():
return os.name == "nt"


def github_output(key, message):
delimiter = str(uuid.uuid4())

os.system(f"echo \"{key}<<${delimiter}\" >> $GITHUB_OUTPUT")
os.system(f"echo \"{_escape(message)}\" >> $GITHUB_OUTPUT")
os.system(f"echo \"${delimiter}\" >> $GITHUB_OUTPUT")
with open(os.environ['GITHUB_OUTPUT'], mode='a', encoding='UTF-8') as fh:
print(f'{key}<<${delimiter}', file=fh)
print(message, file=fh)
print(f'${delimiter}', file=fh)


def section(_title, _content):
return f"""
<details>
<summary>{_title}</summary>

\\`\\`\\`
```
{_content}
\\`\\`\\`
```
</details>

"""


def header(_content):
return f"""
\\`\\`\\`
```
{_content}
\\`\\`\\`
```
"""


Expand Down Expand Up @@ -107,18 +107,20 @@ def sizeof_fmt(num, suffix='B', sign=False):
downloadArgs += "-q"

if url.endswith(".jar"):
os.system(f"wget \"{url}\" {downloadArgs} -O diffuse.jar")
r = requests.get(url, allow_redirects=True)
open("diffuse.jar", "wb").write(r.content)
exec_call = ["java", "-jar", "diffuse.jar"]
else:
os.system(f"wget \"{url}\" {downloadArgs} -O diffuse.zip")
r = requests.get(url, allow_redirects=True)
open("diffuse.zip", "wb").write(r.content)
with zipfile.ZipFile("diffuse.zip", "r") as zip_ref:
zip_ref.extractall("diffuse_extracted")

if os.name == "nt":
if is_windows():
executable_name = "diffuse.bat"
else:
executable_name = "diffuse"
runnable = f"diffuse_extracted/diffuse-{lib_version}/bin/{executable_name}"
runnable = os.path.join("diffuse_extracted", f"diffuse-{lib_version}", "bin", executable_name)
st = os.stat("diffuse_extracted")
os.chmod(runnable, st.st_mode | stat.S_IEXEC)
exec_call = [runnable]
Expand Down Expand Up @@ -165,11 +167,11 @@ def sizeof_fmt(num, suffix='B', sign=False):
process = subprocess.Popen(exec_call, stdout=subprocess.PIPE)
out, _ = process.communicate()

diff = out.decode(encoding=sys.stdout.encoding).strip()

if process.returncode != 0:
raise Exception("Error while executing diffuse")

diff = out.decode("utf-8").strip()

if is_debug():
print(f"Diff size: {len(diff)}")

Expand Down