Skip to content

Commit

Permalink
inputs: allow to override repo ref with sha1 form store
Browse files Browse the repository at this point in the history
  • Loading branch information
sgliner-ledger committed Oct 30, 2023
1 parent 3affab4 commit 7de014d
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
25 changes: 24 additions & 1 deletion .github/workflows/build_all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ on:
type: boolean
required: false
default: false

use_sha1_from_live:
type: boolean
required: false
default: false
provider:
type: string
required: false
default: "1"
device:
type: string
required: false
default: "nanos+"
version:
type: string
required: false
default: "1.1.0"

jobs:
setup-devices:
Expand Down Expand Up @@ -168,8 +185,14 @@ jobs:
name: input_${{ matrix.index }}.json

- name: Setup repos
if: ${{ inputs.use_sha1_from_live }}
run: |
python3 scripts/build_and_test/main.py --input_file input_${{ matrix.index }}.json --use_sha1_from_live --provider ${{ inputs.provider }} --device ${{ inputs.device }} --version ${{ inputs.version }}
- name: Setup repos
if: ${{ !inputs.use_sha1_from_live }}
run: |
python3 scripts/build_and_test/main.py --input_file input_${{ matrix.index }}.json
python3 scripts/build_and_test/main.py --input_file input_${{ matrix.index }}.json --use_sha1_from_live --provider ${{ inputs.provider }} --device ${{ inputs.device }} --version ${{ inputs.version }}
- name: Launch build
run: |
Expand Down
20 changes: 20 additions & 0 deletions scripts/build_and_test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from scan_app import scan_all_devices
from device import Devices
from utils import git_setup, merge_json
from sha1 import override_sha1

SDK_NAME = "sdk"
SDK_URL = "https://github.com/LedgerHQ/ledger-secure-sdk.git"
Expand Down Expand Up @@ -37,6 +38,11 @@
default=Path("output_files/error_logs.txt"))
parser.add_argument("--workdir", required=False, type=str, default="workdir")

parser.add_argument("--use_sha1_from_live", required=False, action='store_true')
parser.add_argument("--provider", required=False, type=str)
parser.add_argument("--device", required=False, type=str)
parser.add_argument("--version", required=False, type=str)

args = parser.parse_args()

abs_workdir = Path.cwd()/args.workdir
Expand Down Expand Up @@ -71,6 +77,20 @@
print("Error: input file does not exist")
exit()

if args.use_sha1_from_live:
if not args.provider:
print("Error: you must specify provider")
exit()
if not args.device:
print("Error: you must specify device")
exit()
if not args.version:
print("Error: you must specify version")
exit()

input_json = override_sha1(input_json, args.provider, args.device, args.version)


git_setup(SDK_NAME, args.sdk_ref, SDK_URL, abs_workdir)

output = {}
Expand Down
36 changes: 36 additions & 0 deletions scripts/build_and_test/sha1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import requests
import json

STORE_API = "https://appstore.aws.prd.ldg-tech.com"


def fetch_data_from_api():
request_headers = {'Content-Type': 'application/json'}
r = requests.get(STORE_API + '/api/applications', headers=request_headers)

store_app_list = json.loads(r.text)
return store_app_list


def get_sha1(live_json: dict, provider: str, device: str, version: str):
for version_json in live_json["application_versions"]:
pattern = f"{device}/{version}/"

if version_json["firmware"].startswith(pattern):
if int(provider) in version_json["providers"]:
return version_json["sha1"]
return


def override_sha1(input_json: dict, provider: str, device: str, version: str):
live_json = fetch_data_from_api()

for app_json in input_json:
for live_app_json in live_json:
if app_json["url"] == live_app_json["sourceURL"]:
sha1 = get_sha1(live_app_json, provider, device, version)
if sha1:
app_json["ref"] = sha1
break

return input_json

0 comments on commit 7de014d

Please sign in to comment.