-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} |