Skip to content

Commit

Permalink
Add Update Go Workflow and Update to Go 1.18
Browse files Browse the repository at this point in the history
This workflow runs weekly and updates both the Go version and the Go modules. This will update not just the direct dependencies but also transitive dependencies, which is something Dependabot does not presently do.

The Go version is determined by Pipeline Builder. When the Pipeline Builder workflow runs and updates the pipeline, it will update the required Go version in this workflow. The next time this workflow runs, it'll then bump the Go version. This workflow can be directly triggered as well.

Signed-off-by: Daniel Mikusa <[email protected]>
  • Loading branch information
Daniel Mikusa committed Aug 9, 2022
1 parent 5dc43ce commit d05a581
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 2 deletions.
8 changes: 7 additions & 1 deletion octo/octo.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

const (
CraneVersion = "0.8.0"
GoVersion = "1.17"
GoVersion = "1.18"
PackVersion = "0.27.0"
RichGoVersion = "0.3.10"
YJVersion = "5.0.0"
Expand Down Expand Up @@ -126,6 +126,12 @@ func Contribute(path string) error {
contributions = append(contributions, c)
}

if c, err := ContributeUpdateGo(descriptor); err != nil {
return err
} else {
contributions = append(contributions, c)
}

if err := Remove(descriptor, RemovedFiles); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion octo/statik/statik.go

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions octo/update-go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -euo pipefail

if [ -z "${GO_VERSION:-}" ]; then
echo "No go version set"
exit 1
fi

OLD_GO_VERSION=$(grep -P '^go \d\.\d+' go.mod | cut -d ' ' -f 2)

go mod edit -go="$GO_VERSION"
go mod tidy
go get -u all
go mod tidy

git add go.mod go.sum
git checkout -- .

echo "::set-output name=old-go-version::${OLD_GO_VERSION}"
echo "::set-output name=go-version::${GO_VERSION}"
75 changes: 75 additions & 0 deletions octo/update_go.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2018-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package octo

import (
"fmt"

"github.com/paketo-buildpacks/pipeline-builder/octo/actions"
"github.com/paketo-buildpacks/pipeline-builder/octo/actions/event"
)

func ContributeUpdateGo(descriptor Descriptor) (Contribution, error) {
w := actions.Workflow{
Name: "Update Go",
On: map[event.Type]event.Event{
event.ScheduleType: event.Schedule{{Minute: "0", Hour: "2", DayOfWeek: "1"}},
event.WorkflowDispatchType: event.WorkflowDispatch{},
},
Jobs: map[string]actions.Job{
"update": {
Name: "Update Go",
RunsOn: []actions.VirtualEnvironment{actions.UbuntuLatest},
Steps: []actions.Step{
{
Uses: "actions/setup-go@v3",
With: map[string]interface{}{"go-version": GoVersion},
},
{
Uses: "actions/checkout@v3",
},
{
Id: "update-go",
Name: "Update Go Version",
Run: StatikString("/update-go.sh"),
Env: map[string]string{
"GO_VERSION": GoVersion,
},
},
{
Uses: "peter-evans/create-pull-request@v4",
With: map[string]interface{}{
"token": descriptor.GitHub.Token,
"author": fmt.Sprintf("%[1]s <%[1][email protected]>", descriptor.GitHub.Username),
"commit-message": `Bump Go from ${{ steps.update-go.outputs.old-go-version }} to ${{ steps.update-go.outputs.go-version }}
Bumps Go from ${{ steps.update-go.outputs.old-go-version }} to ${{ steps.update-go.outputs.go-version }}.`,
"signoff": true,
"branch": "update/go",
"delete-branch": true,
"title": "Bump Go from ${{ steps.update-go.outputs.old-version }} to ${{ steps.update-go.outputs.new-version }}",
"body": "Bumps Go from `${{ steps.update-go.outputs.old-version }}` to `${{ steps.update-go.outputs.new-version }}`.\n\n<details>\n<summary>Release Notes</summary>\n${{ steps.pipeline.outputs.release-notes }}\n</details>",
"labels": "semver:minor, type:task",
},
},
},
},
},
}

return NewActionContribution(w)
}

0 comments on commit d05a581

Please sign in to comment.