Skip to content

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kael-shipman committed Jan 12, 2024
1 parent 3eda0fb commit 1275ddc
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 74 deletions.
56 changes: 0 additions & 56 deletions .github/actions/setup-env/action.yml

This file was deleted.

16 changes: 5 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ jobs:
contents: 'read'
actions: 'read'
outputs:
node-version: ${{ steps.initial-vars.outputs.NODE_VERSION }}
pnpm-version: ${{ steps.initial-vars.outputs.PNPM_VERSION }}
affected-shas-base: ${{ steps.get-affected-sha-spread.outputs.base }}
affected-shas-head: ${{ steps.get-affected-sha-spread.outputs.head }}
pnpmFilter: ${{ steps.get-pnpm-params.outputs.pnpmFilter }}
Expand All @@ -57,7 +55,7 @@ jobs:
run: |
# Replace this with 'v1.x' or another branch to simulate a CI run on that branch
REFNAME=$GITHUB_REF_NAME
REFNAME=v1.x
#REFNAME=v1.x
echo "REFNAME=$REFNAME"
echo "REFNAME=$REFNAME" >> $GITHUB_ENV
Expand All @@ -66,11 +64,7 @@ jobs:
echo "BASEBRANCH=$BASEBRANCH"
echo "BASEBRANCH=$BASEBRANCH" >> $GITHUB_ENV
NODE_VERSION="$(./scripts/.internal/getEngineVersion.js node)"
echo "NODE_VERSION=$NODE_VERSION"
echo "NODE_VERSION=$NODE_VERSION" >> $GITHUB_OUTPUT
PNPM_VERSION="$(./scripts/.internal/getEngineVersion.js pnpm)"
PNPM_VERSION="$(jq -r .engines.pnpm package.json)"
echo "PNPM_VERSION=$PNPM_VERSION"
echo "PNPM_VERSION=$PNPM_VERSION" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -128,7 +122,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-env
- uses: wymp/devops/actions/setup-node-pnpm@v1

- name: ESLint Cache
uses: actions/cache@v3
Expand Down Expand Up @@ -177,7 +171,7 @@ jobs:
service: ${{ fromJson(needs.get-deploy-env.outputs.affectedAppsJson) }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-env
- uses: wymp/devops/actions/setup-node-pnpm@v1

# TODO: Figure out how to set up pnpm cache for building docker containers
# - name: PNPM Cache for Docker
Expand All @@ -198,4 +192,4 @@ jobs:
run: pnpm --sequence --filter "${{ matrix.service }}" docker:build

# TODO: Deployment is highly dependent on your actual setup. Deferring on this for now.
# - name: Deploy
# - name: Deploy
36 changes: 30 additions & 6 deletions scripts/.internal/pkgjson.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ function echo_usage() {
echo " $0 -h|--help - Show this help message and exit"
echo " $0 ([options]) set [key] [value] - Set the given key to the given value in package.json. Keys may be specified in jq format."
echo " $0 ([options]) [del|delete] [key] - Delete the given key from package.json. Keys may be specified in jq format."
echo " $0 ([options]) sort - Sort all the keys in each package.json file alphabetically"
echo
echo "Options:"
echo "Global Options:"
echo " -f|--filter [regex] - Only include packages matching the given regex"
echo " -e|--exclude [regex] - Exclude any packages matching the given regex"
echo " -j|--json - (For set) Interpret the value as JSON"
echo " -m|--merge - (For set) Merge the value with the existing value (implies --json)"
echo " -d|--dry-run - Don't actually modify any files, just output the changes that would be made"
echo
echo "'Set' Options:"
echo " -j|--json - Interpret the value as JSON"
echo " -m|--merge - Merge the value with the existing value (implies --json)"
echo
}

function exit_with_error() {
Expand All @@ -45,6 +48,10 @@ function process_del_args() {
if [ -n "$2" ]; then exit_with_error "Unknown argument: '$2'"; fi
}

function process_sort_args() {
if [ -n "$1" ]; then exit_with-error "Unknown argument: '$1'"; fi
}

function apply_cmd() {
local OUTPUT
for pkgjson in "$ROOT/apps"/*/package.json "$ROOT/libs"/*/package.json; do
Expand All @@ -59,6 +66,21 @@ function apply_cmd() {
fi
elif [ "$CMD" == "delete" ]; then
OUTPUT="$(jq "del($DEL_KEY)" "$pkgjson")"
elif [ "$CMD" == "sort" ]; then
local EXTRA
OUTPUT="$(jq --sort-keys . "$pkgjson")"
if jq -e .scripts "$pkgjson" &>/dev/null; then
EXTRA="$(echo "$OUTPUT" | jq --sort-keys '.scripts')"
OUTPUT="$(echo "$OUTPUT" | jq --argjson val "$EXTRA" '.scripts |= $val')"
fi
if jq -e .dependencies "$pkgjson" &>/dev/null; then
EXTRA="$(echo "$OUTPUT" | jq --sort-keys '.dependencies')"
OUTPUT="$(echo "$OUTPUT" | jq --argjson val "$EXTRA" '.dependencies |= $val')"
fi
if jq -e .devDependencies "$pkgjson" &>/dev/null; then
EXTRA="$(echo "$OUTPUT" | jq --sort-keys '.devDependencies')"
OUTPUT="$(echo "$OUTPUT" | jq --argjson val "$EXTRA" '.devDependencies |= $val')"
fi
else
exit_with_error "Unknown command: '$CMD'"
fi
Expand Down Expand Up @@ -115,13 +137,13 @@ while [ $# -gt 0 ]; do
shift
;;

set)
CMD="set"
set|sort|delete)
CMD="$1"
shift
break
;;

del|delete)
del)
CMD="delete"
shift
break
Expand All @@ -147,6 +169,8 @@ if [ "$CMD" == "set" ]; then
process_set_args "$@"
elif [ "$CMD" == "delete" ]; then
process_del_args "$@"
elif [ "$CMD" == "sort" ]; then
process_sort_args "$@"
else
exit_with_error "Unknown command: '$CMD'"
fi
Expand Down
24 changes: 23 additions & 1 deletion scripts/.internal/publish-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ if ! command -v jq &> /dev/null; then
exit 1
fi

CONFIRM=0
while [ "$#" -gt 0 ]; do
case "$1" in
-c|--confirm)
CONFIRM=1
shift
;;
*)
>&2 echo "E: Unknown option $1"
exit 1
;;
esac
done

ROOT="$(dirname "$0")/../.."

for pkg in "$ROOT/libs"/*; do
Expand All @@ -15,8 +29,16 @@ for pkg in "$ROOT/libs"/*; do
NEW_VERSION="$(jq -r .version package.json)"
PUBLISHED_VERSION="$(pnpm view "$PKG_NAME" version 2>/dev/null || echo "0.0.0")"
if [ "$NEW_VERSION" != "$PUBLISHED_VERSION" ]; then
if [ "$CONFIRM" -eq 1 ]; then
read -p "Publish $PKG_NAME@$NEW_VERSION? [Y/n] " -n 1 REPLY
echo
if [[ "$REPLY" =~ ^[Nn]$ ]]; then
echo "Skipping $PKG_NAME@$NEW_VERSION"
continue
fi
fi
echo "Publishing $PKG_NAME@$NEW_VERSION"
pnpm publish $@
pnpm publish "$@"
else
echo "$PKG_NAME@$NEW_VERSION already published"
fi
Expand Down

0 comments on commit 1275ddc

Please sign in to comment.