Skip to content

Check and Sync Node.js Versions #265

Check and Sync Node.js Versions

Check and Sync Node.js Versions #265

name: Check and Sync Node.js Versions
on:
schedule:
- cron: '0 0 * * *' # everyday
workflow_dispatch:
jobs:
sync-node-versions:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org' # set ~/.npmrc need add repository secrets in the settings
- name: Install dependencies
run: npm ci
- name: Fetch Node.js versions released in the last 30 days
run: |
#set -x
DATE_30_DAYS_AGO=$(date --date='30 days ago' +%Y-%m-%d)
curl -s https://nodejs.org/dist/index.json | jq --arg DATE "$DATE_30_DAYS_AGO" -r '.[] | select(.date >= $DATE) | .version' > versions.txt
echo "Node.js versions released in the last 30 days:"
cat versions.txt
#set +x
- name: Check each version and sync if not published
run: |
#set -x
npm whoami # check token access
while IFS= read -r VERSION; do
echo "Checking version $VERSION..."
if [ -z "$(npm view node@$VERSION)" ]; then
echo "Version $VERSION is not published on npm. Running custom script."
mkdir -p "target/$VERSION" && cd "target/$VERSION"
node ../../index.js $VERSION
for dir in */ ; do
if [ -d "$dir" ]; then
echo "Publishing directory: $dir"
cd "$dir"
npm publish
# npm publish --dry-run
cd ..
else
echo "Directory $dir not found."
fi
done
cd ../../
else
echo "Version $VERSION is already published on npm. Skipping."
fi
done < versions.txt
#set +x
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}