Check Latest Node #66
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
name: Check Latest Node | |
on: | |
schedule: | |
- cron: '0 0 * * *' # Run every day at midnight | |
workflow_dispatch: | |
jobs: | |
check: | |
strategy: | |
fail-fast: false # prevent test to stop if one fails | |
matrix: | |
node-version: [18, 20, 22] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Compare versions | |
id: compare | |
run: | | |
# get the latest Node.js version with major version matching the matrix node version | |
LATEST_VERSION=$(curl -s https://nodejs.org/dist/latest-v${{ matrix.node-version }}.x/ | grep -oP 'node-v\K[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -n1) | |
echo "Latest Node.js ${{ matrix.node-version }} version is: $LATEST_VERSION" | |
# get the latest patch version | |
PATCH_VERSION=$(ls patches/node.v${{ matrix.node-version }}.*.patch | grep -oP 'node.v\K[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -n1) | |
echo "Latest patch version for Node.js ${{ matrix.node-version }} is: $PATCH_VERSION" | |
echo "latest_version=$LATEST_VERSION" >> $GITHUB_OUTPUT | |
echo "patch_version=$PATCH_VERSION" >> $GITHUB_OUTPUT | |
# compare the latest patch version with the latest Node.js version | |
if [ "$PATCH_VERSION" != "$LATEST_VERSION" ]; then | |
echo "Patch for Node.js ${{ matrix.node-version }} is outdated" | |
# set the output variable to true | |
echo "outdated=true" >> $GITHUB_OUTPUT | |
fi | |
- name: Create new patch | |
if: steps.compare.outputs.outdated == 'true' | |
run: | | |
echo "Creating new patch for Node.js ${{ matrix.node-version }}" | |
echo "Latest Node.js version: ${{ steps.compare.outputs.latest_version }}" | |
echo "Latest patch version: ${{ steps.compare.outputs.patch_version }}" | |
# trigger the patch-node.yml workflow with the latest Node.js version | |
curl -X POST \ | |
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/actions/workflows/patch-node.yml/dispatches \ | |
-d '{"ref":"main","inputs":{"nodeVersion":"${{ steps.compare.outputs.latest_version }}","patchFile":"${{ steps.compare.outputs.patch_version }}"}}' | |
# send a notification to the repository owner if the patch is outdated | |
- name: Notify | |
if: steps.compare.outputs.outdated == 'true' | |
run: | | |
echo "Sending notification to repository owner" | |
curl -X POST \ | |
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/dispatches \ | |
-d '{"event_type":"notify","client_payload":{"message":"Patch for Node.js ${{ matrix.node-version }} is outdated"}}' |