Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make auto-generated files read-only #2323

Merged
merged 1 commit into from Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion github/gen-accessors.go
Expand Up @@ -186,10 +186,18 @@ func (t *templateData) dump() error {
}

logf("Writing %v...", filename)
if err := ioutil.WriteFile(filename, clean, 0644); err != nil {
if err := os.Chmod(filename, 0644); err != nil {
return fmt.Errorf("os.Chmod(%q, 0644): %v", filename, err)
}

if err := ioutil.WriteFile(filename, clean, 0444); err != nil {
return err
}

if err := os.Chmod(filename, 0444); err != nil {
return fmt.Errorf("os.Chmod(%q, 0444): %v", filename, err)
}

return nil
}

Expand Down Expand Up @@ -329,6 +337,8 @@ const source = `// Copyright {{.Year}} The go-github AUTHORS. All rights reserve
// license that can be found in the LICENSE file.

// Code generated by gen-accessors; DO NOT EDIT.
// Instead, please run "go generate ./..." as described here:
// https://github.com/google/go-github/blob/master/CONTRIBUTING.md#submitting-a-patch

package {{.Package}}
{{with .Imports}}
Expand Down Expand Up @@ -373,6 +383,8 @@ const test = `// Copyright {{.Year}} The go-github AUTHORS. All rights reserved.
// license that can be found in the LICENSE file.

// Code generated by gen-accessors; DO NOT EDIT.
// Instead, please run "go generate ./..." as described here:
// https://github.com/google/go-github/blob/master/CONTRIBUTING.md#submitting-a-patch

package {{.Package}}
{{with .Imports}}
Expand Down
16 changes: 15 additions & 1 deletion github/gen-stringify-test.go
Expand Up @@ -352,7 +352,19 @@ func (t *templateData) dump() error {
}

logf("Writing %v...", t.filename)
return ioutil.WriteFile(t.filename, clean, 0644)
if err := os.Chmod(t.filename, 0644); err != nil {
return fmt.Errorf("os.Chmod(%q, 0644): %v", t.filename, err)
}

if err := ioutil.WriteFile(t.filename, clean, 0444); err != nil {
return err
}

if err := os.Chmod(t.filename, 0444); err != nil {
return fmt.Errorf("os.Chmod(%q, 0444): %v", t.filename, err)
}

return nil
}

func newStructField(receiverType, fieldName, fieldType, zeroValue string, namedStruct bool) *structField {
Expand All @@ -379,6 +391,8 @@ const source = `// Copyright {{.Year}} The go-github AUTHORS. All rights reserve
// license that can be found in the LICENSE file.

// Code generated by gen-stringify-tests; DO NOT EDIT.
// Instead, please run "go generate ./..." as described here:
// https://github.com/google/go-github/blob/master/CONTRIBUTING.md#submitting-a-patch

package {{ $package := .Package}}{{$package}}
{{with .Imports}}
Expand Down
2 changes: 2 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions github/github-stringify_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.