Skip to content

Commit 7ef334d

Browse files
author
Augusto Moura
authored
[FX-4724] Add action for updating dependencies to the latest (#259)
* Add updated dependency package * Add changeset * fixup! Add updated dependency package
1 parent 8f1777b commit 7ef334d

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

.changeset/nervous-rats-argue.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'davinci-github-actions': minor
3+
---
4+
5+
### update-dependency-to-latest
6+
7+
- add action for updating a npm dependency to the latest available

update-dependency-to-latest/README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## Update dependency to latest
2+
3+
Create a PR for updating a dependency to the latest version
4+
5+
### Description
6+
7+
### Inputs
8+
9+
The list of arguments, that are used in GH Action:
10+
11+
| name | type | required | default | description |
12+
| ------------------ | ------ | -------- | ------------------------- | ----------------------------------------------------------------------------------------------- |
13+
| `dependency-regex` | string || | Regex pattern for NPM package names that should be updated, leave it blank to update everything |
14+
| `pr-title` | string | | | Title for the PR created |
15+
| `branch-name` | string | | davinci-dependencies-bump | Name of the branch to be created |
16+
| `main-branch` | string | | master | Name of the branch that the PR will be based upon |
17+
18+
### Outputs
19+
20+
Not specified
21+
22+
### ENV Variables
23+
24+
Not specified
25+
26+
### Usage
27+
28+
```yaml
29+
# Updating picasso and davinci packages
30+
- uses: toptal/davinci-github-actions/update-dependency-to-latest
31+
with:
32+
dependency-regex: "@toptal/(picasso|davinci)"
33+
pr-title: Bump Picasso and Davinci
34+
```
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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

Comments
 (0)