Skip to content

Commit

Permalink
linting and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pwtyler committed Dec 18, 2023
1 parent ec12b58 commit 7456902
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 41 deletions.
85 changes: 46 additions & 39 deletions .bin/prepare-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,51 @@ new_dev_version_from_current(){
echo "$INCREMENTED"
}

process_file(){
local file="$1"
if [ ! -f "$file" ]; then
return
fi
echo "Checking file '${file}'..."
if [[ "$file" = "$BASE_DIR/package-lock.json" ]];then
# skip package-lock and let `npm i` do it when package.json is processed.
echo "skipping sed of package lock"
return
fi

(
shopt -s nocasematch # make the "if readme" case insensitive
if [[ "${file}" == "$BASE_DIR/readme.txt" ]]; then
echo "adding new heading"
new_heading="### ${NEW_DEV_VERSION}"
awk -v heading="$new_heading" '/## Changelog/ { print; print ""; print heading; print ""; next } 1' "$file" > tmp.md
mv tmp.md "$file"
git add "$file"
return
elif [[ "${file}" == "$BASE_DIR/readme.md" ]]; then
echo "adding new heading"
new_heading="= ${NEW_DEV_VERSION} ="
awk -v heading="$new_heading" '/== Changelog ==/ { print; print ""; print heading; print ""; next } 1' "$file" > tmp.md
mv tmp.md "$file"
git add "$file"
return
fi
)

echo "search-and-replace with sed"
# Use `sed` to perform the search and replace operation in each file
sed -i.tmp -e "s/${CANONICAL_VERSION}/${NEW_DEV_VERSION}/g" "$file" && rm "$file.tmp"
if [[ "$file" == "$BASE_DIR/package.json" ]];then
# TODO: This seems unsafe as we might update dependencies as well.
# Is it safe to just sed package-lock instead? That also seems wrong.
echo "running 'npm i --package-lock-only' to update package-lock.json"
npm i --package-lock-only
git add "$BASE_DIR/package-lock.json"
fi

git add "$file"
}

main() {
local CANONICAL_VERSION
CANONICAL_VERSION="$(grep 'Stable tag:' < "${CANONICAL_FILE}" | awk '{print $3}')"
Expand All @@ -39,45 +84,7 @@ main() {
echo "Updating ${CANONICAL_VERSION} to ${NEW_DEV_VERSION}"
# Iterate through each file in the top-level directory
for file in "$BASE_DIR"/*; do
if [ -f "$file" ]; then
echo "${file}"
if [[ "$file" = "$BASE_DIR/package-lock.json" ]];then
# skip package-lock and let `npm i` do it.
echo "skipping sed of package lock"
continue
fi
(
shopt -s nocasematch # make the "if readme" case insensitive
if [[ "${file}" == "$BASE_DIR/readme.txt" ]]; then
echo "adding new heading"
new_heading="### ${NEW_DEV_VERSION}"
awk -v heading="$new_heading" '/## Changelog/ { print; print ""; print heading; print ""; next } 1' "$file" > tmp.md
mv tmp.md "$file"
git add "$file"
continue
elif [[ "${file}" == "$BASE_DIR/readme.md" ]]; then
echo "adding new heading"
new_heading="= ${NEW_DEV_VERSION} ="
awk -v heading="$new_heading" '/== Changelog ==/ { print; print ""; print heading; print ""; next } 1' "$file" > tmp.md
mv tmp.md "$file"
git add "$file"
continue
fi
)

echo "search-and-replace with sed"
# Use `sed` to perform the search and replace operation in each file
sed -i.tmp -e "s/${CANONICAL_VERSION}/${NEW_DEV_VERSION}/g" "$file" && rm "$file.tmp"
if [[ "$file" == "$BASE_DIR/package.json" ]];then
# TODO: This seems unsafe as we might update dependencies as well.
# Is it safe to just sed package-lock instead? That also seems wrong.
echo "running 'npm i --package-lock-only' to update package-lock.json"
npm i --package-lock-only
git add "$BASE_DIR/package-lock.json"
fi

git add "$file"
fi
process_file "$file"
done
# Who am I?
git config user.email "${GIT_USER}"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
DB_HOST: localhost
steps:
- uses: actions/checkout@v3
- name: Run shell linter
run: make lint-shell
- name: Install NPM & Composer dependencies
run: |
composer install
Expand Down
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
lint:


lint-shell:
shellcheck .bin/prepare-dev.sh .bin/release-pr.sh
composer lint
lint: lint-shell
composer lint

test:
composer test

0 comments on commit 7456902

Please sign in to comment.