Skip to content

Update NPM dependencies #52

Update NPM dependencies

Update NPM dependencies #52

name: Update NPM dependencies
on:
workflow_dispatch:
inputs:
target-branch:
description: "Branch to update"
required: true
type: choice
default: 'main'
options:
- "main"
- "2.2"
- "2.1"
- "1.0"
schedule:
- cron: '0 2 * * *'
permissions:
pull-requests: write
contents: write
jobs:
compute-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Compute matrix
id: set-matrix
run: |
if [[ -z "${{ inputs.target-branch }}" ]]; then
echo 'matrix={ "branch": ["main","2.2","2.1","1.0"] }' >> "$GITHUB_OUTPUT"
else
echo 'matrix={ "branch": ["${{ inputs.target-branch }}"] }' >> "$GITHUB_OUTPUT"
fi
update-npm-deps:
runs-on: ubuntu-latest
needs: [compute-matrix]
name: Update NPM dependencies
strategy:
fail-fast: false
matrix: ${{fromJson(needs.compute-matrix.outputs.matrix)}}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: refs/heads/${{ matrix.branch }}
fetch-depth: 0
- name: Setup Java
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'
- name: Search existing PR
id: searchpr
run: |
existingPR=$(gh pr list --author "app/quarkus-hilla-bot" --json id,title,baseRefName,headRefName,number | \
jq '.[] | select( .baseRefName == "${{ matrix.branch }}" and .headRefName == "chore/update_npm_deps_${{ matrix.branch }}" ) | .number')
echo "prNumber=${existingPR:-0}" >> "$GITHUB_OUTPUT"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout and rebase PR
if: ${{ steps.searchpr.outputs.prNumber != '0' }}
run: |
gh pr checkout ${{ steps.searchpr.outputs.prNumber }}
git -c user.name="quarkus-hilla-bot[bot]" -c user.email="141157179+quarkus-hilla-bot[bot]@users.noreply.github.com" \
rebase ${{ matrix.branch }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build
run: |
set -x -e -o pipefail
mvn -V -e -ntp install -Pdefault-modules,it-tests,production -DskipTests
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
id: commit-changes
with:
commit_message: "chore(npm-deps): update npm dependencies"
commit_user_name: "quarkus-hilla-bot[bot]"
commit_user_email: "141157179+quarkus-hilla-bot[bot]@users.noreply.github.com"
branch: "chore/update_npm_deps_${{ matrix.branch }}"
create_branch: ${{ steps.searchpr.outputs.prNumber == '0' }}
file_pattern: ':(glob)**/package*.json'
push_options: '--force-with-lease'
- name: Generate token
uses: tibdex/github-app-token@v1
if: ${{ steps.commit-changes.outputs.changes_detected == 'true' && steps.searchpr.outputs.prNumber == '0' }}
id: generate-token
with:
app_id: ${{ secrets.QUARKUS_HILLA_BOT_ID }}
private_key: ${{ secrets.QUARKUS_HILLA_BOT_PRIVATE_KEY }}
- name: Create PR
if: ${{ steps.commit-changes.outputs.changes_detected == 'true' && steps.searchpr.outputs.prNumber == '0' }}
run: |
gh pr create --head chore/update_npm_deps_${{ matrix.branch }} --base ${{ matrix.branch }} \
--title "chore(npm-deps): update npm dependencies (${{ matrix.branch }})" \
--body "" --label "dependencies" >> "$GITHUB_STEP_SUMMARY" 2>&1
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}