Skip to content

Commit d8378c7

Browse files
authored
fix: adding golang update strategy (#34)
# Conflicts: # golang/README.md # golang/action.yml
1 parent 4e5cf6f commit d8378c7

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

golang/README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This GitHub Action automatically updates Go module dependencies and creates a pull request with the changes.
44

55
> [!IMPORTANT]
6-
> This action updates dependencies using `go get -u` and thus does not update to new major versions.
6+
> This action updates dependencies using `go get -u` (by default) and thus does not update to new major versions. You can customize this behavior using the `strategy` input parameter.
77
88
## :rocket: Usage
99

@@ -24,6 +24,7 @@ jobs:
2424
token: ${{ github.token }}
2525
base-branch: 'main'
2626
branch-prefix: 'update-go-deps'
27+
strategy: 'controlled' # or 'direct', 'everything'
2728
```
2829
2930
## :gear: Inputs
@@ -36,6 +37,40 @@ jobs:
3637
| `pr-title` | Title for the pull request | :x: | `Update Golang Dependencies` |
3738
| `commit-message` | Commit message for the update | :x: | `Update Golang dependencies` |
3839
| `auto-merge` | Wether automatic merge should be enabled for the PR | :x: | `false` |
40+
| `strategy` | Dependency update strategy | :x: | `controlled` |
41+
42+
## 📋 Update Strategies
43+
44+
The `strategy` parameter controls how dependencies are updated:
45+
46+
### `controlled` (default)
47+
48+
Updates direct dependencies and their transitive dependencies while respecting version constraints. Uses `go get -t -u ./...` for a safe, tested update approach.
49+
50+
**Best for:** Most use cases where stability and compatibility are important.
51+
52+
### `direct`
53+
54+
Updates only direct dependencies (those explicitly listed in `go.mod`) to their latest versions, ignoring indirect dependencies.
55+
56+
```bash
57+
go list -m -f '{{if not .Indirect}}{{.Path}}{{end}}' all \
58+
| xargs -n1 go get -u
59+
```
60+
61+
**Best for:** When you want to update only the dependencies you directly control.
62+
63+
### `everything`
64+
65+
Updates all dependencies, including indirect ones, to their latest available versions. This is the most aggressive strategy and may introduce breaking changes.
66+
67+
```bash
68+
go list -m -u all \
69+
| awk '/\[/ { print $1 "@" substr($2,2,length($2)-2) }' \
70+
| xargs -n1 go get
71+
```
72+
73+
**Best for:** When you want the absolute latest versions and are willing to handle breaking changes.
3974

4075
## :warning: Prerequisites
4176

golang/action.yml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ inputs:
3333
description: 'Whether a successful PR should be automatically merged'
3434
default: 'false'
3535

36+
strategy:
37+
required: false
38+
description: 'Strategy for updating dependencies (controlled, direct, or everything)'
39+
default: 'controlled'
40+
3641
runs:
3742
using: 'composite'
3843
steps:
@@ -48,12 +53,30 @@ runs:
4853
cache: true
4954
cache-dependency-path: '**/go.sum'
5055

51-
- name: Update dependencies
56+
- name: Update dependencies (controlled)
57+
if: ${{ inputs.strategy == 'controlled' }}
5258
shell: bash
5359
run: |
5460
go get -t -u ./...
5561
go mod tidy
5662
63+
- name: Update dependencies (direct)
64+
if: ${{ inputs.strategy == 'direct' }}
65+
shell: bash
66+
run: |
67+
go list -m -f '{{if not .Indirect}}{{.Path}}{{end}}' all \
68+
| xargs -n1 go get -u
69+
go mod tidy
70+
71+
- name: Update dependencies (everything)
72+
if: ${{ inputs.strategy == 'everything' }}
73+
shell: bash
74+
run: |
75+
go list -m -u all \
76+
| awk '$NF ~ /^\[v/ { v=$NF; gsub(/[\[\]]/, "", v); print $1 "@" v }'
77+
| xargs -n1 go get
78+
go mod tidy
79+
5780
- name: Check for changes
5881
id: check_changes
5982
uses: alchemaxinc/composite-toolbox/check-changes@v1
@@ -76,6 +99,14 @@ runs:
7699
77100
This pull request automatically updates Go module dependencies to their latest versions.
78101
102+
## :gear: Update Strategy
103+
104+
**Strategy Used:** `${{ inputs.strategy }}`
105+
106+
- **controlled**: Updates direct dependencies and their transitive dependencies while maintaining version constraints
107+
- **direct**: Updates only direct dependencies to their latest versions
108+
- **everything**: Updates all dependencies including indirect ones to their latest versions
109+
79110
## :warning: Important Notes
80111
81112
- :robot: This PR was **automatically generated**

0 commit comments

Comments
 (0)