diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2021-11-11 16:27:34 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-11 16:27:34 +0300 |
commit | c35d4e5a55bcfe21e972a9fb8b6250e3ff4ebe22 (patch) | |
tree | 5d3d484200ef7aa3169fa48ac3e66ca7ca028e40 | |
parent | 7b2434b8638e6145cd06f8e6f531cb0aac56acf0 (diff) | |
parent | 8a789afb03bd08c67cffe530ea586c2efe9708df (diff) |
Merge pull request #36 from nextcloud/feat/dispatch-npm-node-engines-versions
-rw-r--r-- | .github/workflows/dispatch-npm-engines.yml | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/.github/workflows/dispatch-npm-engines.yml b/.github/workflows/dispatch-npm-engines.yml new file mode 100644 index 0000000..23c9134 --- /dev/null +++ b/.github/workflows/dispatch-npm-engines.yml @@ -0,0 +1,78 @@ +# 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 + # 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 "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 "::set-output name=matrix::$REPOS" + + dispatch: + runs-on: ubuntu-latest + needs: repositories + + strategy: + fail-fast: false + matrix: + repositories: ${{ fromJSON(needs.repositories.outputs.matrix) }} + + env: + NODE_VERSION: "^14.0.0" + NPM_VERSION: "^7.0.0" + + steps: + - name: Checkout target repository + uses: actions/checkout@v2 + with: + repository: ${{ github.repository_owner }}/${{ matrix.repositories }} + + - name: Set node version to ${{ env.NODE_VERSION }} + run: jq --tab '.engines.node = "${{ env.NODE_VERSION }}"' package.json > package-new.json && mv package-new.json package.json + + - name: Set npm version to ${{ env.NPM_VERSION }} + run: jq --tab '.engines.npm = "${{ env.NPM_VERSION }}"' package.json > package-new.json && mv package-new.json package.json + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + body: Automated update of the npm and node engines versions + branch: feat/package-node-npm-engines-update + commit-message: Update npm and node engines versions + committer: Nextcloud bot <bot@nextcloud.com> + author: Nextcloud bot <bot@nextcloud.com> + signoff: true + title: Update npm and node engines versions + labels: dependencies + token: ${{ secrets.COMMAND_BOT_PAT }} |