Skip to content

Commit 3456c03

Browse files
committed
add support for manually running updater, and change yml updater command
1 parent 4e13318 commit 3456c03

File tree

2 files changed

+41
-37
lines changed

2 files changed

+41
-37
lines changed
Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
name: Update Dockerfile Dependencies
22
on:
3-
# schedule:
4-
# - cron: '0 12 * * * *'
5-
pull_request:
3+
schedule:
4+
- cron: '0 12 * * * *'
5+
worfklow_dispatch:
66

77
permissions:
88
contents: write
99
pull-requests: write
1010

11-
env:
12-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13-
1411
jobs:
1512
update:
1613
name: update
@@ -20,35 +17,29 @@ jobs:
2017
with:
2118
ref: main
2219

23-
- name: make test pr
24-
run: echo "this is a test PR" >> test-pr.txt
25-
26-
# - name: build dependency updater
27-
# run: cd dependency_updater && go build
20+
- name: build dependency updater
21+
run: cd dependency_updater && go build
2822

29-
# - name: run dependency updater
30-
# env:
31-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32-
# run: cd dependency_updater && ./dependency_updater --repo ../ --commit true
23+
- name: run dependency updater
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
run: cd dependency_updater && ./dependency_updater --repo ../ --github-action true
3327

34-
# - name: Load .env file
35-
# uses: aarcangeli/[email protected]
36-
# with:
37-
# filenames: 'commit_message.env'
28+
- name: Load .env file
29+
uses: aarcangeli/[email protected]
30+
with:
31+
filenames: 'commit_message.env'
3832

39-
# - name: view env
40-
# run: echo ${{ env.TITLE }}
33+
- name: view env
34+
run: echo ${{ env.TITLE }}
4135

4236
- name: create pull request
4337
uses: peter-evans/[email protected]
4438
with:
4539
author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>
4640
committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
47-
# title: ${{ env.TITLE }}
48-
# commit-message: ${{ env.TITLE }}
49-
# body: ${{ env.DESC }}
50-
title: "Test PR"
51-
commit-message: This is a test PR
52-
body: This is a test PR
41+
title: ${{ env.TITLE }}
42+
commit-message: ${{ env.TITLE }}
43+
body: ${{ env.DESC }}
5344
branch: run-dependency-updater
5445
delete-branch: true

dependency_updater/dependency_updater.go

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

1414
"log"
1515
"os"
16+
"os/exec"
1617
"strings"
1718
)
1819

@@ -56,9 +57,14 @@ func main() {
5657
Usage: "Stages updater changes and creates commit message",
5758
Required: false,
5859
},
60+
&cli.BoolFlag{
61+
Name: "github-action",
62+
Usage: "Specifies whether tool is being used through github action workflow",
63+
Required: false,
64+
},
5965
},
6066
Action: func(ctx context.Context, cmd *cli.Command) error {
61-
err := updater(string(cmd.String("token")), string(cmd.String("repo")), cmd.Bool("commit"))
67+
err := updater(string(cmd.String("token")), string(cmd.String("repo")), cmd.Bool("commit"), cmd.Bool("github-action"))
6268
if err != nil {
6369
return fmt.Errorf("error running updater: %s", err)
6470
}
@@ -71,7 +77,7 @@ func main() {
7177
}
7278
}
7379

74-
func updater(token string, repoPath string, commit bool) error {
80+
func updater(token string, repoPath string, commit bool, githubAction bool) error {
7581
var err error
7682
var dependencies Dependencies
7783
var updatedDependencies []VersionUpdateInfo
@@ -110,8 +116,8 @@ func updater(token string, repoPath string, commit bool) error {
110116
}
111117
}
112118

113-
if commit && updatedDependencies != nil {
114-
err := createCommitMessage(updatedDependencies, repoPath)
119+
if (commit && updatedDependencies != nil) || (githubAction && updatedDependencies != nil) {
120+
err := createCommitMessage(updatedDependencies, repoPath, githubAction)
115121
if err != nil {
116122
return fmt.Errorf("error creating commit message: %s", err)
117123
}
@@ -125,7 +131,7 @@ func updater(token string, repoPath string, commit bool) error {
125131
return nil
126132
}
127133

128-
func createCommitMessage(updatedDependencies []VersionUpdateInfo, repoPath string) error {
134+
func createCommitMessage(updatedDependencies []VersionUpdateInfo, repoPath string, githubAction bool) error {
129135
var repos []string
130136
commitTitle := "chore: updated "
131137
commitDescription := "Updated dependencies for: \n"
@@ -137,11 +143,18 @@ func createCommitMessage(updatedDependencies []VersionUpdateInfo, repoPath strin
137143
}
138144
commitDescription = strings.TrimSuffix(commitDescription, "\n")
139145

140-
commitTitle += strings.Join(repos, ", ")
141-
commitDescription = "\"" + commitDescription + "\""
142-
err := createGitMessageEnv(commitTitle, commitDescription, repoPath)
143-
if err != nil {
144-
return fmt.Errorf("error creating git commit message: %s", err)
146+
if githubAction {
147+
commitTitle += strings.Join(repos, ", ")
148+
commitDescription = "\"" + commitDescription + "\""
149+
err := createGitMessageEnv(commitTitle, commitDescription, repoPath)
150+
if err != nil {
151+
return fmt.Errorf("error creating git commit message: %s", err)
152+
}
153+
} else if !githubAction {
154+
cmd := exec.Command("git", "commit", "-am", commitTitle, "-m", commitDescription)
155+
if err := cmd.Run(); err != nil {
156+
return fmt.Errorf("error running git commit -m: %s", err)
157+
}
145158
}
146159
return nil
147160
}

0 commit comments

Comments
 (0)