forked from bitfocus/companion
-
Notifications
You must be signed in to change notification settings - Fork 0
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
3 changed files
with
90 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
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,56 @@ | ||
name: Check for NodeJS updates | ||
on: | ||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
# Run every week | ||
schedule: | ||
- cron: '43 5 * * 0' | ||
|
||
env: | ||
COMPANION_BRANCH: master | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
jobs: | ||
update-nodejs: | ||
if: ${{ github.repository_owner == 'bitfocus' }} | ||
|
||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
submodules: true | ||
ref: ${{ env.COMPANION_BRANCH }} | ||
token: ${{ secrets.SYNC_MODULES_PAT }} | ||
|
||
- name: Use Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: '.node-version' | ||
|
||
- name: Setup environment | ||
run: | | ||
corepack enable | ||
yarn | ||
- name: Run script | ||
run: | | ||
node tools/update_nodejs_versions.mjs | ||
- name: Create Pull Request | ||
uses: peter-evans/create-pull-request@v7 | ||
with: | ||
commit-message: 'chore: update Node.js versions' | ||
title: 'chore: update Node.js versions' | ||
body: 'This PR updates the Node.js versions in the Companion.' | ||
delete-branch: true | ||
branch: 'chore/update-nodejs' | ||
committer: 'Companion Bot <[email protected]>' | ||
author: 'Companion Bot <[email protected]>' | ||
add-paths: 'nodejs-versions.json' | ||
token: ${{ secrets.SYNC_MODULES_PAT }} |
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,32 @@ | ||
import fs from 'node:fs/promises' | ||
import { fileURLToPath } from 'node:url' | ||
import { SemVer } from 'semver' | ||
|
||
const nodejsVersionsPath = fileURLToPath(new URL('../nodejs-versions.json', import.meta.url)) | ||
|
||
const existingVersionsStr = await fs.readFile(nodejsVersionsPath, 'utf8') | ||
const existingVersions = JSON.parse(existingVersionsStr) | ||
|
||
console.log('existing versions:', existingVersions) | ||
|
||
const apiReleases = await fetch('https://nodejs.org/download/release/index.json').then((res) => res.json()) | ||
console.log(`Found ${apiReleases.length} nodejs releases!`) | ||
|
||
const newVersions = { ...existingVersions } | ||
|
||
for (const [versionName, currentVersion] of Object.entries(existingVersions)) { | ||
if (!versionName.startsWith('node')) continue | ||
|
||
let latestVersion = new SemVer(currentVersion) | ||
for (const apiRelease of apiReleases) { | ||
const apiSemver = new SemVer(apiRelease.version) | ||
if (apiSemver.major === latestVersion.major && apiSemver.compare(latestVersion) > 0) { | ||
latestVersion = apiSemver | ||
} | ||
} | ||
|
||
console.log(`Latest version for ${versionName}: ${latestVersion}`) | ||
newVersions[versionName] = latestVersion.version | ||
} | ||
|
||
await fs.writeFile(nodejsVersionsPath, JSON.stringify(newVersions, null, '\t') + '\n') |