Skip to content

Commit

Permalink
chore: publish bot
Browse files Browse the repository at this point in the history
  • Loading branch information
elrrrrrrr authored and aredridel committed Feb 26, 2024
1 parent bdf3322 commit c1a76f6
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/sync-node-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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@v3

- name: Set up Node.js
uses: actions/setup-node@v3
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}}

0 comments on commit c1a76f6

Please sign in to comment.