Skip to content

Commit

Permalink
moved unused style script into workflow actions
Browse files Browse the repository at this point in the history
  • Loading branch information
gedu committed Sep 11, 2023
1 parent ff2174b commit 261adb0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
22 changes: 13 additions & 9 deletions scripts/find-unused-keys.sh → .github/scripts/findUnusedKeys.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#!/bin/bash

# Configurations
readonly SRC_DIR="src"
readonly STYLES_FILE="src/styles/styles.js"
readonly UTILITIES_STYLES_FILE="src/styles/utilities"
readonly STYLES_KEYS_FILE="scripts/style_keys_list_temp.txt"
readonly UTILITY_STYLES_KEYS_FILE="scripts/utility_keys_list_temp.txt"
readonly REMOVAL_KEYS_FILE="scripts/removal_keys_list_temp.txt"
declare LIB_PATH
LIB_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd ../../ && pwd)"

readonly SRC_DIR="${LIB_PATH}/src"
readonly STYLES_DIR="${LIB_PATH}/src/styles"
readonly STYLES_FILE="${LIB_PATH}/src/styles/styles.js"
readonly UTILITIES_STYLES_FILE="${LIB_PATH}/src/styles/utilities"
readonly STYLES_KEYS_FILE="${LIB_PATH}/scripts/style_keys_list_temp.txt"
readonly UTILITY_STYLES_KEYS_FILE="${LIB_PATH}/scripts/utility_keys_list_temp.txt"
readonly REMOVAL_KEYS_FILE="${LIB_PATH}/scripts/removal_keys_list_temp.txt"
readonly AMOUNT_LINES_TO_SHOW=3

readonly FILE_EXTENSIONS=('-name' '*.js' '-o' '-name' '*.jsx' '-o' '-name' '*.ts' '-o' '-name' '*.tsx')
Expand All @@ -23,7 +27,7 @@ source scripts/shellUtils.sh
trap ctrl_c INT

delete_temp_files() {
find scripts -name "*keys_list_temp*" -type f -exec rm -f {} \;
find "${LIB_PATH}/scripts" -name "*keys_list_temp*" -type f -exec rm -f {} \;
}

# shellcheck disable=SC2317 # Don't warn about unreachable commands in this function
Expand Down Expand Up @@ -156,7 +160,7 @@ find_utility_styles_store_prefix() {

echo "$variable_trimmed" >> "$UTILITY_STYLES_KEYS_FILE"
done < <(grep -E -o './utilities/[a-zA-Z0-9_-]+' "$file" | grep -v '\/\/' | grep -vE '\/\*.*\*\/')
done < <(find 'src/styles' -type f \( "${FILE_EXTENSIONS[@]}" \))
done < <(find $STYLES_DIR -type f \( "${FILE_EXTENSIONS[@]}" \))

# Sort and remove duplicates from the temporary file
sort -u -o "${UTILITY_STYLES_KEYS_FILE}" "${UTILITY_STYLES_KEYS_FILE}"
Expand Down Expand Up @@ -195,7 +199,7 @@ lookfor_unused_utilities() {
remove_keyword "${variable}"
remove_keyword "${match}"
done < <(grep -E -o "$original_keyword\.[a-zA-Z0-9_-]+" "$file" | grep -v '\/\/' | grep -vE '\/\*.*\*\/')
done < <(find 'src/styles' -type f \( "${FILE_EXTENSIONS[@]}" \))
done < <(find $STYLES_DIR -type f \( "${FILE_EXTENSIONS[@]}" \))
done < "$UTILITY_STYLES_KEYS_FILE"
}

Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/findUnusedStyles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Find Unused styles

on:
pull_request:
types: [opened, synchronize]
branches-ignore: [staging, production]

jobs:
perf-tests:
if: ${{ github.actor != 'OSBotify' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup NodeJS
uses: Expensify/App/.github/actions/composite/setupNode@main

- name: Run unused style searcher
shell: bash
run: ./.github/scripts/findUnusedKeys.sh

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"symbolicate:android": "npx metro-symbolicate android/app/build/generated/sourcemaps/react/release/index.android.bundle.map",
"symbolicate:ios": "npx metro-symbolicate main.jsbundle.map",
"test:e2e": "node tests/e2e/testRunner.js --development",
"find-missing-keys": "scripts/find-unused-keys.sh"
"gh-actions-unused-styles": "./.github/scripts/findUnusedKeys.sh"
},
"dependencies": {
"@expensify/react-native-web": "0.18.15",
Expand Down

0 comments on commit 261adb0

Please sign in to comment.