|
| 1 | +name: Update dependency to latest |
| 2 | +description: Create a PR for updating a dependency to the latest version |
| 3 | + |
| 4 | +inputs: |
| 5 | + dependency-regex: |
| 6 | + required: true |
| 7 | + description: Regex pattern for NPM package names that should be updated, leave it blank to update everything |
| 8 | + pr-title: |
| 9 | + description: Title for the PR created |
| 10 | + branch-name: |
| 11 | + description: Name of the branch to be created |
| 12 | + default: davinci-dependencies-bump |
| 13 | + main-branch: |
| 14 | + description: Name of the branch that the PR will be based upon |
| 15 | + default: master |
| 16 | + |
| 17 | +runs: |
| 18 | + using: composite |
| 19 | + steps: |
| 20 | + - shell: bash |
| 21 | + name: Bump dependencies to the latest version |
| 22 | + id: bump-versions |
| 23 | + env: |
| 24 | + FILTER_REGEX: ${{ inputs.dependency-regex }} |
| 25 | + run: | |
| 26 | + # Wrapper function on syncpack |
| 27 | + syncpack() { |
| 28 | + npx --yes syncpack@11 "$@" |
| 29 | + } |
| 30 | +
|
| 31 | + old_versions=$(syncpack list --filter "$FILTER_REGEX" | sort) |
| 32 | +
|
| 33 | + echo | syncpack update --filter "$FILTER_REGEX" |
| 34 | +
|
| 35 | + new_versions=$(syncpack list --filter "$FILTER_REGEX" | sort) |
| 36 | +
|
| 37 | + changed_versions=$(comm -13 <(cat <<< "$old_versions") <(cat <<< "$new_versions")) |
| 38 | +
|
| 39 | + printf "changed-versions<<EOF\n" >> "$GITHUB_OUTPUT" |
| 40 | + printf "%s\n" "$changed_versions" >> "$GITHUB_OUTPUT" |
| 41 | + printf "EOF\n" >> "$GITHUB_OUTPUT" |
| 42 | +
|
| 43 | + yarn install |
| 44 | +
|
| 45 | + - name: Commit changes to new branch and create PR |
| 46 | + shell: bash |
| 47 | + env: |
| 48 | + BRANCH_NAME: ${{ inputs.branch-name }} |
| 49 | + MAIN_BRANCH: ${{ inputs.main-branch }} |
| 50 | + PR_TITLE: ${{ inputs.pr-title }} |
| 51 | + CHANGED_VERSIONS: ${{ steps.bump-versions.outputs.changed-versions }} |
| 52 | + run: | |
| 53 | + set -x |
| 54 | + git config --global user.email "[email protected]" |
| 55 | + git config --global user.name "toptal-devbot" |
| 56 | +
|
| 57 | + git fetch origin master |
| 58 | + git checkout -B "$BRANCH_NAME" origin/"$MAIN_BRANCH" |
| 59 | +
|
| 60 | + git add . |
| 61 | + git commit --no-verify -m "$PR_TITLE" |
| 62 | + git push --no-verify -u origin "$BRANCH_NAME" --force |
| 63 | +
|
| 64 | + # Only create a PR if not already created |
| 65 | + if ! (( $(gh pr list --state open --head "$BRANCH_NAME" --json number --jq length) )); then |
| 66 | + gh pr create \ |
| 67 | + --title "$PR_TITLE" \ |
| 68 | + --body "$(printf 'Updating packages to the latest versions available. It was created automatically.\n\nVersions changed:\n\n%s' "$CHANGED_VERSIONS")" \ |
| 69 | + --base "$MAIN_BRANCH" \ |
| 70 | + --head "$BRANCH_NAME" |
| 71 | + fi |
0 commit comments