upgrade-node #450
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: upgrade-node | |
on: | |
schedule: | |
- cron: "39 5 * * 1-5" | |
workflow_dispatch: | |
inputs: | |
version: | |
description: "Node.js version to upgrade to, in the format: 12.34.56" | |
required: false | |
type: string | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
jobs: | |
version: | |
name: Determine version to upgrade to | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
outputs: | |
current: ${{ steps.current_version.outputs.value }} | |
latest: ${{ steps.latest_version.outputs.value }} | |
major: ${{ steps.latest_version.outputs.major }} | |
should_upgrade: ${{ steps.latest_version.outputs.is_newer }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: Setup Node.js | |
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 | |
with: | |
node-version: "18" | |
- 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_MAJOR=$(cut -d "." -f 1 <<< "$CURRENT_VERSION") | |
CURRENT_VERSION_MINOR=$(cut -d "." -f 2 <<< "$CURRENT_VERSION") | |
echo "CURRENT_NODEJS_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV | |
echo "CURRENT_NODEJS_VERSION_MAJOR=$CURRENT_VERSION_MAJOR" >> $GITHUB_ENV | |
echo "CURRENT_NODEJS_VERSION_MINOR=$CURRENT_VERSION_MINOR" >> $GITHUB_ENV | |
echo "value=$CURRENT_VERSION" >> $GITHUB_OUTPUT | |
- name: Get the earliest supported Node.js version whose EOL date is at least a month away | |
if: ${{ ! inputs.version }} | |
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
with: | |
script: |- | |
const script = require('./scripts/check-node-versions.js') | |
await script({github, context, core}) | |
- name: Save the manually-input version to environment variables for comparison | |
if: ${{ inputs.version }} | |
env: | |
NEW_VERSION: ${{ inputs.version }} | |
run: |- | |
NEW_VERSION_MAJOR=$(cut -d "." -f 1 <<< "$NEW_VERSION") | |
NEW_VERSION_MINOR=$(cut -d "." -f 2 <<< "$NEW_VERSION") | |
echo "NEW_NODEJS_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
echo "NEW_NODEJS_VERSION_MAJOR=$NEW_VERSION_MAJOR" >> $GITHUB_ENV | |
echo "NEW_NODEJS_VERSION_MINOR=$NEW_VERSION_MINOR" >> $GITHUB_ENV | |
- name: Output env variables for use in the next job | |
id: latest_version | |
run: |- | |
echo "value=$NEW_NODEJS_VERSION" >> $GITHUB_OUTPUT | |
echo "major=$NEW_NODEJS_VERSION_MAJOR" >> $GITHUB_OUTPUT | |
[[ "$NEW_NODEJS_VERSION_MAJOR" > "$CURRENT_NODEJS_VERSION_MAJOR" || ("$NEW_NODEJS_VERSION_MAJOR" == "$CURRENT_NODEJS_VERSION_MAJOR" && "$NEW_NODEJS_VERSION_MINOR" > "$CURRENT_NODEJS_VERSION_MINOR") ]] && IS_NEWER=true | |
echo "is_newer=$IS_NEWER" >> $GITHUB_OUTPUT | |
upgrade: | |
name: Upgrade Node.js | |
needs: version | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
if: always() && needs.version.outputs.should_upgrade | |
steps: | |
- name: Checkout | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: Setup Node.js | |
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 | |
with: | |
node-version: ${{ needs.version.outputs.major }} | |
- name: Install | |
run: yarn install | |
- name: Update the package with the new minimum Node version and update @types/node | |
env: | |
NEW_NODEJS_VERSION: ${{ needs.version.outputs.latest }} | |
NEW_NODEJS_VERSION_MAJOR: ${{ needs.version.outputs.major }} | |
run: |- | |
npm pkg set engines.node=">= $NEW_NODEJS_VERSION" | |
yarn add -D @types/node@~$NEW_NODEJS_VERSION_MAJOR | |
- name: Set the new minNodeVersion in the Projen template | |
env: | |
NEW_NODEJS_VERSION: ${{ needs.version.outputs.latest }} | |
run: 'sed -i "s/minNodeVersion: \".*\",/minNodeVersion: \"$NEW_NODEJS_VERSION\",/" ./projenrc.template.js' | |
- name: Update the Node version used in GitHub Actions workflows | |
env: | |
NEW_NODEJS_VERSION_MAJOR: ${{ needs.version.outputs.major }} | |
run: 'find ./.github/workflows -type f -name "*.yml" -print0 | xargs -0 sed -i "s/node-version: \".*\"/node-version: \"$NEW_NODEJS_VERSION_MAJOR\"/g"' | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@67ccf781d68cd99b580ae25a5c18a1cc84ffff1f # v7.0.6 | |
with: | |
commit-message: "chore!: increase minimum supported Node.js version to ${{ needs.version.outputs.major }}" | |
branch: auto/upgrade-node-${{ needs.version.outputs.major }} | |
base: main | |
title: "chore!: increase minimum supported Node.js version to ${{ needs.version.outputs.major }}" | |
body: This PR increases the minimum supported Node.js version to `${{ needs.version.outputs.latest }}` from `${{ needs.version.outputs.current }}` because the latter is less than 30 days away from EOL. | |
labels: automerge,automated,security | |
token: ${{ secrets.GH_TOKEN_ACTIONS_UPDATER }} | |
author: team-tf-cdk <github-team-tf-cdk@hashicorp.com> | |
committer: team-tf-cdk <github-team-tf-cdk@hashicorp.com> | |
signoff: true | |
delete-branch: true |