upgrade-node #500
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
# ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen". | |
name: upgrade-node | |
on: | |
schedule: | |
- cron: 26 8 * * * | |
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 | |
- name: Setup Node.js | |
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af | |
with: | |
node-version: 20.9.0 | |
- 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 | |
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 | |
env: | |
CI: "true" | |
CHECKPOINT_DISABLE: "1" | |
if: always() && needs.version.outputs.should_upgrade | |
steps: | |
- name: Checkout | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | |
- name: Setup Node.js | |
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af | |
with: | |
node-version: ${{ needs.version.outputs.latest }} | |
- name: Install | |
run: yarn install | |
- name: Run upgrade script | |
run: scripts/update-node.sh ${{ needs.version.outputs.latest }} | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@67ccf781d68cd99b580ae25a5c18a1cc84ffff1f | |
with: | |
base: main | |
branch: auto/upgrade-node-${{ needs.version.outputs.major }} | |
commit-message: "chore: increase Node.js version to ${{ needs.version.outputs.latest }}" | |
title: "chore: increase Node.js version to ${{ needs.version.outputs.latest }}" | |
body: |- | |
This PR initiates the upgrade of Node.js from `v${{ needs.version.outputs.current }}` to `v${{ needs.version.outputs.latest }}`. | |
Unfortunately, not everything can be automated, and the following steps need to be completed manually: | |
- [ ] Check if the `RunsUsing` value should be updated [here](https://github.com/hashicorp/terraform-cdk-action/blob/8b74e0c471bd6eb9ea8869f1a73de83b7129717e/.projenrc.ts#L164). Check [here](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-javascript-actions) for supported options. | |
- Note that the GitHub Actions runners don't automatically support every LTS version - sometimes they skip one. | |
- [ ] Run `npx projen build` | |
Please checkout this PR, complete the above steps, push the changes to this branch, and then mark this PR as ready for review to complete the upgrade. Thanks! | |
labels: automerge,automated,security | |
token: ${{ secrets.PROJEN_GITHUB_TOKEN }} | |
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 | |
draft: true |