Skip to content

upgrade-node

upgrade-node #338

Workflow file for this run

name: upgrade-node
on:
schedule:
- cron: '20 5 * * *'
workflow_dispatch: {}
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
upgrade:
name: Upgrade Node.js
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Install
run: yarn install
- name: Get current Node.js version
id: current_version
run: |-
ENGINES_NODE_VERSION=$(npm pkg get engines.node | tr -d '"')
CURRENT_VERSION=$(cut -d " " -f 2 <<< "$ENGINES_NODE_VERSION")
CURRENT_VERSION_SHORT=$(cut -d "." -f 1 <<< "$CURRENT_VERSION")
echo "CURRENT_NODEJS_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
echo "CURRENT_NODEJS_VERSION_SHORT=$CURRENT_VERSION_SHORT" >> $GITHUB_ENV
echo "value=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "short=$CURRENT_VERSION_SHORT" >> $GITHUB_OUTPUT
- name: Get the earliest supported Node.js version whose EOL date is at least a month away
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |-
const script = require('./.github/scripts/check-node-versions.js')
await script({github, context, core})
- name: Update the package with the new minimum Node version and update @types/node
if: env.CURRENT_NODEJS_VERSION_SHORT < env.NEW_NODEJS_VERSION_SHORT
run: |-
npm pkg set engines.node=">= $NEW_NODEJS_VERSION"
# Use the below hacky workaround if npm and yarn workspaces still conflict for future updates
# sed -i "s/$CURRENT_NODEJS_VERSION/$NEW_NODEJS_VERSION/" ./package.json
yarn add -W -D @types/node@^$NEW_NODEJS_VERSION_SHORT
cd ./frontend/code
yarn add -W @types/node@^$NEW_NODEJS_VERSION_SHORT
cd ../..
- name: Update the Node version used in GitHub Actions workflows
if: env.CURRENT_NODEJS_VERSION_SHORT < env.NEW_NODEJS_VERSION_SHORT
run: 'find ./.github/workflows -type f -name "*.yml" -print0 | xargs -0 sed -i "s/node-version: \".*\"/node-version: \"$NEW_NODEJS_VERSION_SHORT\"/g"'
# If there are other steps you need to take in your project to update Node.js everywhere, add those here
- name: Get values for pull request
id: latest_version
if: env.CURRENT_NODEJS_VERSION_SHORT < env.NEW_NODEJS_VERSION_SHORT
run: |-
echo "value=$NEW_NODEJS_VERSION" >> $GITHUB_OUTPUT
echo "short=$NEW_NODEJS_VERSION_SHORT" >> $GITHUB_OUTPUT
- name: Create Pull Request
if: env.CURRENT_NODEJS_VERSION_SHORT < env.NEW_NODEJS_VERSION_SHORT
uses: peter-evans/create-pull-request@c5a7806660adbe173f04e3e038b0ccdcd758773c # v6.1.0
with:
commit-message: "chore!: increase minimum supported Node.js version to ${{ steps.latest_version.outputs.short }}"
branch: auto/upgrade-node-${{ steps.latest_version.outputs.short }}
base: main
title: "chore!: increase minimum supported Node.js version to ${{ steps.latest_version.outputs.short }}"
body: This PR increases the minimum supported Node.js version to `${{ steps.latest_version.outputs.value }}` from `${{ steps.current_version.outputs.value }}` because version ${{ steps.current_version.outputs.short }} is less than 30 days away from EOL.
labels: automerge,automated,security
token: ${{ secrets.TEAM_TF_CDK }}
author: team-tf-cdk <[email protected]>
committer: team-tf-cdk <[email protected]>
signoff: true
delete-branch: true