-
Notifications
You must be signed in to change notification settings - Fork 12
88 lines (77 loc) · 2.83 KB
/
bump-up-pr.yml
File metadata and controls
88 lines (77 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Bump Go version and Dependencies
on:
workflow_dispatch:
# push:
# branches:
# - <main>
schedule:
# Runs at 00:00 UTC on the 1st day of every month
- cron: "0 0 1 * *"
jobs:
bump:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
# Find the latest stable Go version
- name: Get latest Go version
id: go-version
run: |
# Fetch the latest stable Go version, e.g. "1.25.4"
LATEST=$(curl -s https://go.dev/VERSION?m=text | head -n1 | sed 's/go//')
# Trim it down to major.minor (e.g. "1.25")
MAJMIN=$(echo "$LATEST" | cut -d. -f1,2)
echo "version=$MAJMIN" >> $GITHUB_OUTPUT
- name: Show detected Go version
run: echo "Latest Go version is ${{ steps.go-version.outputs.version }}"
# Update go.mod 'go' directive if needed
- name: Update go.mod Go version
run: |
CURRENT=$(grep '^go ' go.mod | awk '{print $2}')
NEW=${{ steps.go-version.outputs.version }}
if [ "$CURRENT" != "$NEW" ]; then
echo "Updating Go version from $CURRENT to $NEW"
sed -i "s/^go .*/go $NEW/" go.mod
else
echo "Go version already up-to-date ($CURRENT)"
fi
# Update dependencies
- name: Update dependencies
run: |
go get -u ./...
go mod tidy
# Try building the project
- name: Build project
id: build
continue-on-error: true
run: |
echo "Running go build..."
if go build ./...; then
echo "build_status=success" >> $GITHUB_OUTPUT
echo "✅ Build succeeded"
else
echo "build_status=failure" >> $GITHUB_OUTPUT
echo "❌ Build failed"
fi
# Commit and open PR
- name: Create PR
id: cpr
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Bumping up golang version and dependencies"
title: "Bump up golang version and dependencies"
branch: "chore/go-bump"
body: |
This PR updates the Go toolchain version and all dependencies.
**Build status:** ${{ steps.build.outputs.build_status == 'success' && '✅ Successful' || '❌ Failed' }}
---
_Automated bump workflow run by GitHub Actions._
# Add label based on build result
- name: Add PR label
if: steps.cpr.outputs.pull-request-number != ''
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
number: ${{ steps.cpr.outputs.pull-request-number }}
labels: ${{ steps.build.outputs.build_status == 'success' && 'ready to merge' || 'breaking change' }}