Skip to content

Commit

Permalink
Re-cased var names for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlui committed Oct 20, 2024
1 parent 3561988 commit b87f565
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 48 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/publish-to-amo-on-ff-bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:

- name: Check FF manifest for version bump
run: |
CURRENT_VER=$(cat firefox/extension/manifest.json | grep '"version"' | sed -E 's/.*"version": "(.*)".*/\1/')
PREV_VER=$(git show HEAD^:firefox/extension/manifest.json | grep '"version"' | sed -E 's/.*"version": "(.*)".*/\1/')
if [ "$CURRENT_VER" != "$PREV_VER" ] ; then
echo "Extension updated from $PREV_VER to $CURRENT_VER"
current_ver=$(cat firefox/extension/manifest.json | grep '"version"' | sed -E 's/.*"version": "(.*)".*/\1/')
prev_ver=$(git show HEAD^:firefox/extension/manifest.json | grep '"version"' | sed -E 's/.*"version": "(.*)".*/\1/')
if [ "$current_ver" != "$prev_ver" ] ; then
echo "Extension updated from $prev_ver to $current_ver"
echo "VERSION_CHANGED=true" >> $GITHUB_ENV
else echo "VERSION_CHANGED=false" >> $GITHUB_ENV ; fi
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sync-changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:

fi
done
if [[ "$locales_updated" == true ]] ; then echo "locales_updated=true" >> $GITHUB_ENV ; fi
if [[ "$locales_updated" == true ]] ; then echo "LOCALES_UPDATED=true" >> $GITHUB_ENV ; fi

- name: Sync ** to adamlui/ai-apps/you.com-omnibox/
run: |
Expand All @@ -80,7 +80,7 @@ jobs:
git config --global user.signingkey "${{ secrets.GPG_PRIVATE_ID }}"
- name: Push changes to adamlui/you.com-omnibox
if: env.locales_updated == 'true'
if: env.LOCALES_UPDATED == 'true'
run: |
cd ${{ github.workspace }}/adamlui/you.com-omnibox
git add .
Expand Down
84 changes: 42 additions & 42 deletions utils/bump.sh
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
#!/bin/bash

# Init UI colors
nc="\033[0m" # no color
br="\033[1;91m" # bright red
by="\033[1;33m" # bright yellow
bg="\033[1;92m" # bright green
bw="\033[1;97m" # bright white
NC="\033[0m" # no color
BR="\033[1;91m" # bright red
BY="\033[1;33m" # bright yellow
BG="\033[1;92m" # bright green
BW="\033[1;97m" # bright white

# Init manifest paths
CHROMIUM_MANIFEST="chromium/extension/manifest.json"
FF_MANIFEST="firefox/extension/manifest.json"
chromium_manifest="chromium/extension/manifest.json"
ff_manifest="firefox/extension/manifest.json"

# Normalize args
ARG=${1#-} ; ARG=${ARG#-} # strip leading dash(es)
arg=${1#-} ; arg=${arg#-} # strip leading dash(es)

# Determine manifests to edit
case "$ARG" in
chrome|chromium) MANIFESTS_TO_EDIT=("$CHROMIUM_MANIFEST") ;;
firefox|ff) MANIFESTS_TO_EDIT=("$FF_MANIFEST") ;;
"") MANIFESTS_TO_EDIT=("$CHROMIUM_MANIFEST" "$FF_MANIFEST") ;;
*) echo -e "${br}Invalid argument. Use 'chrome', 'chromium', 'firefox', 'ff', or leave empty.${nc}" ; exit 1 ;;
case "$arg" in
chrome|chromium) MANIFESTS_TO_EDIT=("$chromium_manifest") ;;
firefox|ff) MANIFESTS_TO_EDIT=("$ff_manifest") ;;
"") MANIFESTS_TO_EDIT=("$chromium_manifest" "$ff_manifest") ;;
*) echo -e "${BR}Invalid argument. Use 'chrome', 'chromium', 'firefox', 'ff', or leave empty.${NC}" ; exit 1 ;;
esac
MULTI_BUMP=$( # flag for echos/git commit msg
multi_bump=$( # flag for echos/git commit msg
[[ ${#MANIFESTS_TO_EDIT[@]} -gt 1 ]] && echo true || echo false)

# Bump versions
if $MULTI_BUMP
then VERSION_LABEL="versions in manifests"
else VERSION_LABEL="version in ${MANIFESTS_TO_EDIT[0]}"
if $multi_bump
then version_label="versions in manifests"
else version_label="version in ${MANIFESTS_TO_EDIT[0]}"
fi
echo -e "${by}\nBumping ${VERSION_LABEL}...${nc}\n"
TODAY=$(date +'%Y.%-m.%-d') # YYYY.M.D format
NEW_VERSIONS=() # for dynamic commit msg
for MANIFEST in "${MANIFESTS_TO_EDIT[@]}" ; do
echo -e "${BY}\nBumping ${version_label}...${NC}\n"
today=$(date +'%Y.%-m.%-d') # YYYY.M.D format
new_versions=() # for dynamic commit msg
for manifest in "${MANIFESTS_TO_EDIT[@]}" ; do

# Determine old/new versions
OLD_VER=$(sed -n 's/.*"version": *"\([0-9.]*\)".*/\1/p' "$MANIFEST")
if [[ $OLD_VER == "$TODAY" ]] # exact match for $TODAY
then # bump to $TODAY.1
NEW_VER="$TODAY.1"
elif [[ $OLD_VER == "$TODAY."* ]] # partial match for $TODAY
then # bump to $TODAY.n+1
LAST_NUMBER=$(echo "$OLD_VER" | awk -F '.' '{print $NF}')
NEW_VER="$TODAY.$((LAST_NUMBER + 1))"
else # no match for $TODAY
# bump to $TODAY
NEW_VER="$TODAY"
old_ver=$(sed -n 's/.*"version": *"\([0-9.]*\)".*/\1/p' "$manifest")
if [[ $old_ver == "$today" ]] # exact match for $today
then # bump to $today.1
new_ver="$today.1"
elif [[ $old_ver == "$today."* ]] # partial match for $today
then # bump to $today.n+1
LAST_NUMBER=$(echo "$old_ver" | awk -F '.' '{print $NF}')
new_ver="$today.$((LAST_NUMBER + 1))"
else # no match for $today
# bump to $today
new_ver="$today"
fi
NEW_VERSIONS+=("$NEW_VER")
new_versions+=("$new_ver")

# Bump old version
sed -i "s/\"version\": \"$OLD_VER\"/\"version\": \"$NEW_VER\"/" "$MANIFEST"
sed -i "s/\"version\": \"$old_ver\"/\"version\": \"$new_ver\"/" "$manifest"
if [[ ${#MANIFESTS_TO_EDIT[@]} -gt 1 ]]; then
echo -e "${MANIFEST}: ${bw}v${OLD_VER}${nc}${bg}v${NEW_VER}${nc}"
echo -e "${manifest}: ${BW}v${old_ver}${NC}${BG}v${new_ver}${NC}"
else
echo -e "${bw}v${OLD_VER}${nc}${bg}v${NEW_VER}${nc}"
echo -e "${BW}v${old_ver}${NC}${BG}v${new_ver}${NC}"
fi
done

# Define commit msg
COMMIT_MSG="Bumped \`version\`"
UNIQUE_VERSIONS=($(printf "%s\n" "${NEW_VERSIONS[@]}" | sort -u))
if [[ ${#UNIQUE_VERSIONS[@]} -eq 1 ]] ; then
COMMIT_MSG+=" to \`${UNIQUE_VERSIONS[0]}\`" ; fi
unique_versions=($(printf "%s\n" "${new_versions[@]}" | sort -u))
if [[ ${#unique_versions[@]} -eq 1 ]] ; then
COMMIT_MSG+=" to \`${unique_versions[0]}\`" ; fi

# Commit/push bump(s)
echo -e "${by}\nCommitting $( [[ $MULTI_BUMP == true ]] && echo bumps || echo bump) to Git...\n${nc}"
echo -e "${BY}\nCommitting $( [[ $multi_bump == true ]] && echo bumps || echo bump) to Git...\n${NC}"
git add ./**/manifest.json
git commit -n -m "$COMMIT_MSG"
git push

# Print final summary
MANIFEST_LABEL=$( [[ $MULTI_BUMP == true ]] && echo "Manifests" || echo "${MANIFESTS_TO_EDIT[0]}")
echo -e "\n${bg}Success! ${MANIFEST_LABEL} updated/committed/pushed to GitHub${nc}"
manifest_label=$( [[ $multi_bump == true ]] && echo "Manifests" || echo "${MANIFESTS_TO_EDIT[0]}")
echo -e "\n${BG}Success! ${manifest_label} updated/committed/pushed to GitHub${NC}"

0 comments on commit b87f565

Please sign in to comment.