Skip to content

Commit

Permalink
Merge pull request #27 from LedgerHQ/fbe/check_makefile_uses_manifest
Browse files Browse the repository at this point in the history
The check_makefile script now uses the manifest
  • Loading branch information
fbeutin-ledger authored Apr 20, 2023
2 parents 48b60fe + e0569af commit 39ae17c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 22 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/_check_makefile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ on:
required: false
default: ${{ github.event.repository.name }}
type: string
download_manifest_artifact_name:
description: 'The name of the artifact containing the built manifest'
required: true
type: string

jobs:
check_makefile:
Expand All @@ -38,5 +42,11 @@ jobs:
path: app-repository
submodules: recursive

- name: Download manifest
uses: actions/download-artifact@v3
with:
name: ${{ inputs.download_manifest_artifact_name }}
path: ${{ inputs.download_manifest_artifact_name }}

- name: Run script
run: bash ./ledger-app-workflows/scripts/check_makefile.sh app-repository ${{ inputs.repo-name }}
run: bash ./ledger-app-workflows/scripts/check_makefile.sh app-repository ${{ inputs.repo-name }} ${{ inputs.download_manifest_artifact_name }}
3 changes: 2 additions & 1 deletion .github/workflows/reusable_guidelines_enforcer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ jobs:

call_check_makefile:
name: Dispatch check
needs: call_get_workflow_version
needs: [call_get_workflow_version, call_get_app_manifest]
uses: ./.github/workflows/_check_makefile.yml
with:
download_manifest_artifact_name: manifests
ledger-app-workflows_ref: ${{ needs.call_get_workflow_version.outputs.version }}

call_check_readme:
Expand Down
72 changes: 52 additions & 20 deletions scripts/check_makefile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,75 @@ main() (
error=0
repo="$1"
repo_name="$2"
manifests_dir="$3"

# Find the main Makefile of the app
makefile=$(grep -Rl --include="*Makefile*" "^[[:blank:]]*APPNAME" "$repo")
declare -A variants_array
declare -A appnames_array

if ! grep -q "^listvariants:" "$makefile"; then
log_error "The Makefile does not contain the 'listvariants' rule"
error=1
if [[ "$repo_name" == "app-boilerplate" || "$repo_name" == "app-plugin-boilerplate" ]]; then
is_boilerplate=true
else
is_boilerplate=false
fi

if echo "$repo_name" | grep -q "app.*boilerplate"; then
log_warning "APPNAME and VARIANT checks skipped for Boilerplate"
else
while IFS= read -r line; do
if echo "$line" | grep -q -i "boilerplate"; then
log_error "APPNAME should refer to your application's name, not boilerplate"
# Parse all manifest files
manifests_list=$(find "$manifests_dir" -type f -name "*.json")
while IFS= read -r manifest; do
log_info "Checking manifest $manifest"

# Parse all variants of each manifest to grab all appnames and variants
variants_list=$(cat "$manifest" | jq ".VARIANTS | keys[]" | sed 's/"//g')
while IFS= read -r variant; do
log_info "Checking variant $variant"
appname="$(cat "$manifest" | jq ".VARIANTS.$variant.APPNAME" | sed 's/"//g')"

# Store the variant as key of an associative array to auto remove duplicates from variants
variants_array["$variant"]=1
appnames_array["$appname"]=1
done < <(echo "$variants_list")
done < <(echo "$manifests_list")

log_info "All manifests checked"

# Check each appname
for appname in "${!appnames_array[@]}"; do
if "$is_boilerplate"; then
log_success "APPNAME '$appname' is valid for Boilerplate"
else
if [[ "$appname" == "boilerplate" || "$appname" == "Boilerplate" ]]; then
log_error "APPNAME should refer to your application's name, not '$appname'"
error=1
else
log_success "APPNAME name '$appname' is valid"
fi
done < <(grep "^[[:blank:]]*APPNAME" "$makefile")
fi
done

if grep "echo VARIANTS" "$makefile" | grep -q "BOL"; then
log_error "VARIANT name should refer to your coin ticker, not boilerplate's BOL"
error=1
# Check each variant
for variant in "${!variants_array[@]}"; do
if "$is_boilerplate"; then
log_success "VARIANT name '$variant' is valid for Boilerplate"
else
if [[ "$variant" == "BOL" || "$variant" == "boilerplate" || "$variant" == "Boilerplate" ]]; then
log_error "VARIANT name should refer to your coin ticker, not boilerplate's '$variant'"
error=1
else
log_success "VARIANT name '$variant' is valid"
fi
fi
fi
done

if grep -q "HAVE_BOLOS_UX" "$makefile"; then
if grep -qRl --include="*Makefile*" "HAVE_BOLOS_UX" "$repo"; then
log_error "The Makefile contains an outdated flag 'HAVE_BOLOS_UX'"
error=1
fi

if [[ error -eq 0 ]]; then
log_success "Makefile \"$makefile\" is compliant"
log_success "The Makefile is compliant"
else
log_error_no_header "At least one error has been found"
log_error_no_header "To check the Makefile content, run \"cat '$makefile'\""
log_error_no_header "Please check the Makefile content"
fi

return "$error"
)

Expand Down

0 comments on commit 39ae17c

Please sign in to comment.