Open a PR with updated dependencies #17
This file contains hidden or 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
| name: Open a PR with updated dependencies | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| dependencies: | |
| description: JSON-serialized map of dependencies to update | |
| type: string | |
| required: true | |
| upstream_repository: | |
| description: Upstream repository to open the PR in | |
| type: string | |
| required: true | |
| fork_repository: | |
| description: Fork repository to create the branch in | |
| type: string | |
| required: true | |
| jobs: | |
| update: | |
| name: Update dependencies | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Verify dependencies input | |
| env: | |
| DEPENDENCIES: ${{ inputs.dependencies }} | |
| # language=bash | |
| run: | | |
| num_deps=$(jq 'map(select(has("package") and has("version"))) | length' <<< "$DEPENDENCIES") | |
| if [[ "$?" -ne 0 ]]; then | |
| echo "::error:: Invalid dependencies input" | |
| exit 2 | |
| elif [[ "$num_deps" -eq 0 ]]; then | |
| echo "::warning:: No dependencies to update" | |
| exit 1 | |
| else | |
| echo "$num_deps dependencies to update" | |
| fi | |
| - name: Configure git | |
| env: | |
| GH_TOKEN: ${{ secrets.UPDATE_DEPS_KIBANA_REPO_TOKEN }} | |
| run: | | |
| echo "${GH_TOKEN}" | gh auth login --with-token | |
| gh auth setup-git | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com' | |
| - name: Checkout the upstream repository | |
| uses: actions/checkout@v6 | |
| with: | |
| repository: ${{ inputs.upstream_repository }} | |
| fetch-depth: 1 | |
| - name: Configure git remote for the fork | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| # language=bash | |
| run: | | |
| ssh_url=$(gh repo view "${{ inputs.fork_repository }}" --json sshUrl --jq .sshUrl) | |
| if [[ "$?" -ne 0 ]] || [[ -z "$ssh_url" ]]; then | |
| echo "::error::Cannot find the fork repository. Please make sure the fork_repository input points to the correct fork in the format of <repo_owner>/<repo_name>." | |
| exit 1 | |
| fi | |
| git remote add fork "$ssh_url" | |
| echo "::debug::Resolved the fork repository '${{ inputs.fork_repository }}' to '$ssh_url'" | |
| - name: Create new branch | |
| id: git_branch | |
| # language=bash | |
| run: | | |
| branch_name="update-dependencies/$(date +%s)" | |
| git checkout -b "$branch_name" | |
| echo "BRANCH_NAME=$branch_name" >> "$GITHUB_OUTPUT" | |
| echo "::debug::Created branch '$branch_name'" | |
| - name: Setup Node | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version-file: .nvmrc | |
| cache: yarn | |
| package-manager-cache: false | |
| - name: Update dependency versions | |
| env: | |
| DEPENDENCIES: ${{ inputs.dependencies }} | |
| # language=bash | |
| run: | | |
| jq -j '.[] | .package, "\u0000", .version, "\u0000"' <<< "$DEPENDENCIES" | | |
| xargs -0 -n 2 bash -c ' | |
| pkg="$0" | |
| ver="$1" | |
| if [[ $(npm pkg get "devDependencies.$pkg") != "{}" ]]; then | |
| npm pkg set "devDependencies.$pkg=$ver" | |
| elif [[ $(npm pkg get "dependencies.$pkg") != "" ]]; then | |
| npm pkg set "dependencies.$pkg=$ver" | |
| else | |
| echo "::warning:: Skipping $pkg: Not found in either dependencies or devDependencies"; | |
| fi' | |
| - name: Run install script | |
| # TODO: this should be configurable | |
| run: yarn kbn bootstrap | |
| - name: Check changes | |
| run: git status | |
| - name: Commit changed files | |
| # TODO: this should be configurable | |
| # language=bash | |
| run: | | |
| git add package.json yarn.lock src/platform/packages/private/kbn-ui-shared-deps-npm/version_dependencies.txt | |
| git commit -m "chore: update dependencies" | |
| - name: Push branch to forked repository | |
| run: git push fork "${{ steps.git_branch.outputs.BRANCH_NAME }}" --dry-run |