Skip to content

Mirror Node.JS

Mirror Node.JS #535

Workflow file for this run

name: Mirror Node.JS
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # every day, midnight
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: |
set -e
# https://github.com/nodejs/node#release-keys
gpg --keyserver hkps://keys.openpgp.org --recv-keys \
4ED778F539E3634C779C87C6D7062848A1AB005C \
141F07595B7B3FFE74309A937405533BE57C7D57 \
74F12602B6F1C4E913FAA37AD3A89613643B6201 \
DD792F5973C6DE52C432CBDAC77ABFA00DDBF2B7 \
CC68F5A3106FF448322E48ED27F5E38D5B0A215F \
8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \
C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
890C08DB8579162FEE0DF9DB8BEAB4DFCF555EF4 \
C82FA3AE1CBEDC6BE46B9360C43CEC45C17AB93C \
108F52B48DB57BB0CC439B2997B01419BD92F80A \
A363A499291CBBC940DD62E41F10027AF002F8B0
curl --no-progress-meter -O https://nodejs.org/dist/index.json
versions=$(cat << EOF | node
const fs = require('fs');
const builds = JSON.parse(fs.readFileSync('index.json', 'utf8'));
const versions = builds.map(build => build.version)
.filter(version => parseInt(/^v(\d+)\./.exec(version)[1]) >= 18);
console.log(versions.join('\n'));
EOF
)
for version in $versions; do
if gh release view $version > /dev/null; then
echo "Release $version already exists"
continue
fi
mkdir -p $version
pushd $version
curl --no-progress-meter -O https://nodejs.org/dist/$version/SHASUMS256.txt
curl --no-progress-meter -O https://nodejs.org/dist/$version/SHASUMS256.txt.sig
if ! gpg --verify SHASUMS256.txt.sig SHASUMS256.txt; then
echo "Skipping $version since signature verification failed"
continue
fi
files="SHASUMS256.txt SHASUMS256.txt.sig"
while read -r line; do
hash=$(echo $line | cut -d ' ' -f 1)
file=$(echo $line | cut -d ' ' -f 2)
if [[ $file == */* ]]; then
continue
fi
curl --no-progress-meter -O https://nodejs.org/dist/$version/$file
echo "$hash $file" | sha256sum -c -
files="$files $file"
done < SHASUMS256.txt
gh release create $version $files
echo "Successfully created release $version"
popd
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}