Skip to content

Commit 5c7f7a6

Browse files
committed
add git action to automatically run updater
1 parent f2b0fe7 commit 5c7f7a6

File tree

3 files changed

+67
-7
lines changed

3 files changed

+67
-7
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Update Dockerfile Dependencies
2+
3+
on:
4+
schedule:
5+
- cron: '0 12 * * * *'
6+
push:
7+
branches:
8+
- update-dependencies
9+
10+
permissions:
11+
pull-requests: write
12+
13+
jobs:
14+
update:
15+
name: update
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Load .env file
22+
uses: xom9ikk/[email protected]
23+
with:
24+
path: ~/node/git_commit_message.env
25+
load-mode: strict
26+
27+
- name: view env
28+
run: echo ${{ env.TITLE }}
29+
30+
# - name: build dependency updater
31+
# run: go build ./dependency_updater
32+
33+
# - name: build dependency updater
34+
# env:
35+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
# run: ./dependency_updater --repo ~/node --commit true
37+
38+
# - name: create pull request
39+
# uses: peter-evans/create-pull-request@v7
40+
# with:
41+
# title: ${{ env.TITLE }}
42+
# commit-message: ${{ env.TITLE }}
43+
# body: ${{ env.DESC }}
44+
# branch: update-dependencies

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
/reth-data/
44
/nethermind-data/
55
/dependency_updater/dependency_updater
6+
/git_commit_message.env
67
.DS_Store

dependency_updater/dependency_updater.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
"log"
1515
"os"
16-
"os/exec"
1716
"strings"
1817
)
1918

@@ -112,7 +111,7 @@ func updater(token string, repoPath string, commit bool) error {
112111
}
113112

114113
if commit && updatedDependencies != nil {
115-
err := createCommitMessage(updatedDependencies)
114+
err := createCommitMessage(updatedDependencies, repoPath)
116115
if err != nil {
117116
return fmt.Errorf("error creating commit message: %s", err)
118117
}
@@ -126,7 +125,7 @@ func updater(token string, repoPath string, commit bool) error {
126125
return nil
127126
}
128127

129-
func createCommitMessage(updatedDependencies []VersionUpdateInfo) error {
128+
func createCommitMessage(updatedDependencies []VersionUpdateInfo, repoPath string) error {
130129
var repos []string
131130
commitTitle := "chore: updated "
132131
commitDescription := "Updated dependencies for: \n"
@@ -136,12 +135,13 @@ func createCommitMessage(updatedDependencies []VersionUpdateInfo) error {
136135
commitDescription += repo + " => " + tag + " (" + dependency.DiffUrl + ")" + "\n"
137136
repos = append(repos, repo)
138137
}
138+
commitDescription = strings.TrimSuffix(commitDescription, "\n")
139139

140140
commitTitle += strings.Join(repos, ", ")
141-
cmd := exec.Command("git", "commit", "-am", commitTitle, "-m", commitDescription)
142-
143-
if err := cmd.Run(); err != nil {
144-
return fmt.Errorf("error running git commit -m: %s", err)
141+
commitDescription = "\"" + commitDescription + "\""
142+
err := createGitMessageEnv(commitTitle, commitDescription, repoPath)
143+
if err != nil {
144+
return fmt.Errorf("error creating git commit message: %s", err)
145145
}
146146
return nil
147147
}
@@ -318,6 +318,21 @@ func createVersionsEnv(repoPath string, dependencies Dependencies) error {
318318
return nil
319319
}
320320

321+
func createGitMessageEnv(title string, description string, repoPath string) error {
322+
file, err := os.Create(repoPath + "/git_commit_message.env")
323+
if err != nil {
324+
return fmt.Errorf("error creating git_commit_message.env file: %s", err)
325+
}
326+
defer file.Close()
327+
328+
envString := "export TITLE=" + title + "\nexport DESC=" + description
329+
_, err = file.WriteString(envString)
330+
if err != nil {
331+
return fmt.Errorf("error writing to git_commit_message.env file: %s", err)
332+
}
333+
return nil
334+
}
335+
321336
func generateGithubRepoUrl(dependencies Dependencies, dependencyType string) string {
322337
return "https://github.com/" + dependencies[dependencyType].Owner + "/" + dependencies[dependencyType].Repo
323338
}

0 commit comments

Comments
 (0)