-
Notifications
You must be signed in to change notification settings - Fork 51
61 lines (55 loc) · 1.98 KB
/
sync-node-version.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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@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}}