Skip to content

Commit

Permalink
refactor: PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
thomvaill committed Nov 20, 2024
1 parent 8af84e4 commit 15f7789
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,4 @@ jobs:
steps:
- uses: actions/setup-node@v4
- name: Wait
run: |
echo "Checking if ${{ inputs.npm-package }}@${{ inputs.npm-version }} is available on NPM (waiting max ${{ inputs.wait-minutes }} min)..."
i=0
while ! npm view ${{ inputs.npm-package }} versions --json | jq -e 'index("${{ inputs.npm-version }}")' &> /dev/null
do
if [[ ${i} -gt ${{ inputs.wait-minutes }} ]]
then
echo "Failure for more than ${{ inputs.wait-minutes }} minutes"
echo "Available versions:"
npm view ${{ inputs.npm-package }} versions --json
echo "Abort"
exit 1
fi
echo "${{ inputs.npm-package }}@${{ inputs.npm-version }} is not available yet on NPM. Let's wait 60s..."
sleep 60
((i=i+1))
done
echo "${{ inputs.npm-package }}@${{ inputs.npm-version }} is available"
run: ./scripts/wait-for-npm-version-to-be-published.sh "${{ inputs.npm-package }}" "${{ inputs.npm-version }}" "${{ inputs.wait-minutes }}"
10 changes: 5 additions & 5 deletions .github/workflows/scheduled-weekly-new-nodejs-lts-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ jobs:
- name: Get latest Node.js LTS versions
run: |
curl -s https://nodejs.org/dist/index.json | jq '[.[] | select(.lts != false)] | .[0]' > latest-lts.json
CURRENT_LTS=$(jq -r '.version' latest-lts.json | sed 's/v//')
echo "Latest LTS version: $CURRENT_LTS"
CURRENT_LTS="$(jq -r '.version' latest-lts.json | sed 's/v//')"
echo "Latest LTS version: ${CURRENT_LTS}"
- name: Compare with supported versions
id: check-version
run: |
SUPPORTED_VERSIONS="${{ needs.load-nodejs-supported-versions.outputs.node_versions }}"
if [[ ! "$SUPPORTED_VERSIONS" =~ "$CURRENT_LTS" ]]
if [[ ! "${SUPPORTED_VERSIONS}" =~ "${CURRENT_LTS}" ]]
then
echo "A new Node.js LTS version is available: $CURRENT_LTS"
echo "::set-output name=new_lts_version::$CURRENT_LTS"
echo "A new Node.js LTS version is available: ${CURRENT_LTS}"
echo "::set-output name=new_lts_version::${CURRENT_LTS}"
else
echo "No new Node.js LTS version detected"
fi
Expand Down
52 changes: 52 additions & 0 deletions scripts/wait-for-npm-version-to-be-published.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
set -euo pipefail

package_name="${1:-}"
package_version="${2:-}"
wait_minutes="${3:-}"

usage() {
echo "Usage: $0 <package_name> <package_version> <wait_minutes>"
}

if [[ -z "${package_name}" ]]
then
echo "Missing package_name"
usage
exit 1
fi

if [[ -z "${package_version}" ]]
then
echo "Missing package_version"
usage
exit 1
fi

if [[ -z "${wait_minutes}" ]] || ! [[ "${wait_minutes}" =~ ^-?[0-9]+$ ]]
then
echo "Missing wait_minutes or is not a valid integer"
usage
exit 1
fi

echo "Checking if ${package_name}@${package_version} is available on NPM (waiting max ${wait_minutes} min)..."

i=0
while ! npm view "${package_name}" versions --json | jq -e --arg package_version "${package_version}" 'index($package_version)' &> /dev/null
do
if [[ ${i} -gt ${wait_minutes} ]]
then
echo "Failure for more than ${wait_minutes} minutes"
echo "Available versions:"
npm view "${package_name}" versions --json
echo "Abort"
exit 1
fi

echo "${package_name}@${package_version} is not available yet on NPM. Let's wait 60s..."
sleep 60
((i=i+1))
done

echo "${package_name}@${package_version} is available"

0 comments on commit 15f7789

Please sign in to comment.