Skip to content

Update nvmrc

Update nvmrc #16

Workflow file for this run

name: Update .nvmrc
on:
pull_request:
branches:
- main
paths:
- 'Dockerfile'
types: [opened, synchronize]
jobs:
update-nvmrc:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # pin@v3
with:
fetch-depth: 0
- name: Extract Node.js version from Dockerfile
id: extract_version
run: |
VERSION=$(grep -m 1 -oP 'FROM node:\K[0-9]+\.[0-9]+\.[0-9]+' Dockerfile)
VERSION=$(echo $VERSION | tr -d '\n\r')
echo "NODE_VERSION=$VERSION" >> $GITHUB_ENV
- name: Read current .nvmrc version
id: read_nvmrc
run: |
if [ -f .nvmrc ]; then
CURRENT_VERSION=$(cat .nvmrc | tr -d '\n\r')
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
else
echo "CURRENT_VERSION=" >> $GITHUB_ENV
fi
- name: Check if versions are different
id: check_diff
run: |
if [ "$NODE_VERSION" = "$CURRENT_VERSION" ]; then
echo "Versions are the same. No update needed."
echo "create_pr=false" >> $GITHUB_ENV
else
echo "Versions are different. Update needed."
echo "create_pr=true" >> $GITHUB_ENV
fi
- name: Set up Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Create a new branch if update is needed
if: env.create_pr == 'true'
id: create_branch
run: |
BRANCH_NAME=update-nvmrc-${{ github.sha }}
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV
git checkout -b $BRANCH_NAME
- name: Update .nvmrc if update is needed
if: env.create_pr == 'true'
run: |
echo "$NODE_VERSION" > .nvmrc
git add .nvmrc
git commit -m "Update .nvmrc to Node.js version $NODE_VERSION"
- name: Push changes to new branch if update is needed
if: env.create_pr == 'true'
run: |
git push origin $BRANCH_NAME
- name: Create pull request if update is needed
if: env.create_pr == 'true'
uses: peter-evans/create-pull-request@5874ea5902f1f64af5cc21e1112355f468bb9e7a
with:
token: ${{ secrets.DEV_PAT_NVMRC_ACTION }}
commit-message: "Update .nvmrc to Node.js version ${{ env.NODE_VERSION }}"
branch: ${{ env.BRANCH_NAME }}
title: "Update .nvmrc to Node.js version ${{ env.NODE_VERSION }}"
body: "This PR updates .nvmrc to Node.js version ${{ env.NODE_VERSION }}"
base: main