Skip to content

Schedule Node.js LTS download #9370

Schedule Node.js LTS download

Schedule Node.js LTS download #9370

Workflow file for this run

name: Schedule Node.js LTS download
on:
workflow_dispatch: # Allows manual triggering from the Actions tab
schedule:
- cron: '0 0 * * *'
push:
branches:
- action
jobs:
run-node-script:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20' # You can specify your Node.js version here
- name: Install dependencies
run: npm install
- name: Check Node.js LTS Version
run: |
latest_lts_version=$(node src/getLatestNodeVersion.js)
echo "Latest LTS version: $latest_lts_version"
existing_release=$(gh release view --json tagName --jq '.tagName' | sort -V | tail -n 1)
echo "existing_release: $existing_release"
if [ "$(printf "$latest_lts_version\n$existing_release" | sort -V | tail -n 1)" = "$latest_lts_version" ] && [ "$latest_lts_version" != "$existing_release" ]; then
echo "New Node.js LTS version detected: $latest_lts_version"
echo "new_version=$latest_lts_version" >> $GITHUB_ENV
else
echo "No new Node.js LTS version found or existing version is the same."
echo "new_version=" >> $GITHUB_ENV
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download Node
if: env.new_version != ''
run: node src/download.js
- name: Create Draft Release
if: env.new_version != ''
id: create_release
uses: ncipollo/release-action@v1
with:
tag: ${{ env.new_version }}
name: Node.js ${{ env.new_version }} LTS Release
draft: true
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Find Asset Files
if: env.new_version != ''
id: find_assets
run: |
asset_files=$(find src/assets -type f)
asset_files="${asset_files//'%'/'%25'}"
asset_files="${asset_files//$'\n'/'%0A'}"
asset_files="${asset_files//$'\r'/'%0D'}"
echo "asset_files=$asset_files" >> $GITHUB_ENV
- name: Upload Release Assets
if: env.new_version != ''
run: |
asset_files="${{ env.asset_files }}"
asset_files="${asset_files//'%0A'/$'\n'}"
asset_files="${asset_files//'%25'/$'%'}"
asset_files="${asset_files//'%0D'/$'\r'}"
readarray -t asset_files <<< "$asset_files"
for asset_file in "${asset_files[@]}"; do
asset_name=$(basename "$asset_file")
echo "Uploading asset: $asset_file"
gh release upload ${{ env.new_version }} "$asset_file" --clobber -R ${{ github.repository }}
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish Release
if: env.new_version != ''
run: |
release_id="${{ steps.create_release.outputs.id }}"
curl \
-X PATCH \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
--data '{"draft": false}' \
"https://api.github.com/repos/${{ github.repository }}/releases/$release_id"