summaryrefslogtreecommitdiffstats
path: root/modules/charset
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-09-05 07:04:18 +0100
committerGitHub <noreply@github.com>2022-09-05 14:04:18 +0800
commit8080e23c9bc4e37102f63bec36603a540ff6ea9b (patch)
tree7baf3246a3f00480d396ef2821c8167f9ae195af /modules/charset
parent0232601734fffd13aab3930ebd2b6911eb913315 (diff)
downloadgitea-8080e23c9bc4e37102f63bec36603a540ff6ea9b.tar.gz
gitea-8080e23c9bc4e37102f63bec36603a540ff6ea9b.zip
Move go-licenses to generate and separate generate into a frontend and backend component (#21061)
The `go-licenses` make task introduced in #21034 is being run on make vendor and occasionally causes an empty go-licenses file if the vendors need to change. This should be moved to the generate task as it is a generated file. Now because of this change we also need to split generation into two separate steps: 1. `generate-backend` 2. `generate-frontend` In the future it would probably be useful to make `generate-swagger` part of `generate-frontend` but it's not tolerated with our .drone.yml Ref #21034 Signed-off-by: Andrew Thornton <art27@cantab.net> Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'modules/charset')
-rw-r--r--modules/charset/ambiguous/generate.go11
-rw-r--r--modules/charset/invisible/generate.go11
2 files changed, 22 insertions, 0 deletions
diff --git a/modules/charset/ambiguous/generate.go b/modules/charset/ambiguous/generate.go
index 43cdb217a7..7dd2821aae 100644
--- a/modules/charset/ambiguous/generate.go
+++ b/modules/charset/ambiguous/generate.go
@@ -110,6 +110,17 @@ func runTemplate(t *template.Template, filename string, data interface{}) error
verbosef("Bad source:\n%s", buf.String())
return fmt.Errorf("unable to format source: %w", err)
}
+
+ old, err := os.ReadFile(filename)
+ if err != nil && !os.IsNotExist(err) {
+ return fmt.Errorf("failed to read old file %s because %w", filename, err)
+ } else if err == nil {
+ if bytes.Equal(bs, old) {
+ // files are the same don't rewrite it.
+ return nil
+ }
+ }
+
file, err := os.Create(filename)
if err != nil {
return fmt.Errorf("failed to create file %s because %w", filename, err)
diff --git a/modules/charset/invisible/generate.go b/modules/charset/invisible/generate.go
index 230ff0b832..39eddd58dd 100644
--- a/modules/charset/invisible/generate.go
+++ b/modules/charset/invisible/generate.go
@@ -63,6 +63,17 @@ func runTemplate(t *template.Template, filename string, data interface{}) error
verbosef("Bad source:\n%s", buf.String())
return fmt.Errorf("unable to format source: %w", err)
}
+
+ old, err := os.ReadFile(filename)
+ if err != nil && !os.IsNotExist(err) {
+ return fmt.Errorf("failed to read old file %s because %w", filename, err)
+ } else if err == nil {
+ if bytes.Equal(bs, old) {
+ // files are the same don't rewrite it.
+ return nil
+ }
+ }
+
file, err := os.Create(filename)
if err != nil {
return fmt.Errorf("failed to create file %s because %w", filename, err)