Update npm engines versions #12
Workflow file for this run
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
# 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@v2 | |
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: "^20.0.0" | |
NPM_VERSION: "^10.0.0" | |
steps: | |
- name: Checkout target repository | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ github.repository_owner }}/${{ matrix.repositories }} | |
- name: Check package.json file existence | |
id: check_file_existence | |
uses: andstor/file-existence-action@20b4d2e596410855db8f9ca21e96fbe18e12930b # v2 | |
with: | |
files: package.json | |
- name: Check out new branch | |
if: steps.check_file_existence.outputs.files_exists == 'true' | |
run: git checkout -b feat/package-node-npm-engines-update | |
- 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: Setup git | |
if: steps.check_file_existence.outputs.files_exists == 'true' | |
run: | | |
git config --local user.email "nextcloud-command@users.noreply.github.com" | |
git config --local user.name "nextcloud-command" | |
- name: Commit and force push | |
run: | | |
git add . | |
git commit --signoff -m 'Update npm and node engines versions' | |
git push --force origin feat/package-node-npm-engines-update | |
- name: Create Pull Request | |
if: steps.check_file_existence.outputs.files_exists == 'true' | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
body: Automated update of the npm and node engines versions | |
branch: feat/package-node-npm-engines-update | |
author: Nextcloud bot <bot@nextcloud.com> | |
title: Update npm and node engines versions | |
labels: dependencies | |
token: ${{ secrets.COMMAND_BOT_PAT }} |