Skip to content

Update npm engines versions #18

Update npm engines versions

Update npm engines versions #18

# This workflow needs to be run on demand
# It will search for all repositories containing a package.json
# Then open a pull request to update the Node and Npm engines versions.
name: Update npm engines versions
on:
workflow_dispatch:
jobs:
repositories:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.search-repos.outputs.matrix }}
steps:
- name: Check actor permission
uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3
with:
require: admin
- name: Search repositories using a package.json
id: search-repos
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# This is a simple curl to fetch the list of repos containing a file and extracting the repo names
# We check if the file is <50KB to ignore the lockfile
run: |
echo '' > repos.json
# Retrieve first 10 potential results pages
for i in {0..10}; do
RESULTS=$(curl -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/search/code?q=org%3A${{ github.repository_owner }}+size%3A<50000+filename%3Apackage.json&per_page=100&page=$i" | jq -c '.items')
if [ "$RESULTS" = "null" ]; then
echo "Stopped on page $i"
break
fi
echo "$RESULTS" >> repos.json
done
# Pipe all results arrays and filter duplicate
REPOS=$(cat repos.json | jq '.[]' | jq -sc 'map(.repository.name) | unique')
echo "matrix=$REPOS" >> $GITHUB_OUTPUT
dispatch:
runs-on: ubuntu-latest
needs: repositories
strategy:
fail-fast: false
matrix:
repositories: ${{ fromJSON(needs.repositories.outputs.matrix) }}
env:
NODE_VERSION: "^22.0.0"
NPM_VERSION: "^10.5.0" # node 22.0.0 was shipped with 10.5.1 we should not use older NPM with Node 22
steps:
- name: Checkout target repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
token: ${{ secrets.COMMAND_BOT_PAT }}
repository: ${{ github.repository_owner }}/${{ matrix.repositories }}
- name: Check package.json file existence
id: check_file_existence
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3.0.0
with:
files: package.json
- name: Set node version to ${{ env.NODE_VERSION }}
if: steps.check_file_existence.outputs.files_exists == 'true'
run: jq '.engines.node = "${{ env.NODE_VERSION }}"' package.json > package-new.json && mv package-new.json package.json
- name: Set npm version to ${{ env.NPM_VERSION }}
if: steps.check_file_existence.outputs.files_exists == 'true'
run: jq '.engines.npm = "${{ env.NPM_VERSION }}"' package.json > package-new.json && mv package-new.json package.json
- name: Create Pull Request
id: create_pull_request
if: steps.check_file_existence.outputs.files_exists == 'true'
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
with:
author: Nextcloud bot <bot@nextcloud.com>
committer: nextcloud-command <nextcloud-command@users.noreply.github.com>
title: 'build: update node and npm engines versions'
body: Automated update of the npm and node engines versions according to [Nextcloud standards](https://github.com/nextcloud/standards/issues/5).
commit-message: |
build: update node and npm engines versions
signoff: true
branch: 'feat/package-node-npm-engines-update'
labels: dependencies
token: ${{ secrets.COMMAND_BOT_PAT }}
- name: The pull request already exists
if: failure() && steps.create_pull_request.outputs.pull-request-number
run: |
echo "Pull Request Number - ${{ steps.create_pull_request.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.create_pull_request.outputs.pull-request-url }}"
exit 0