-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: output change detection in GitHub action mode
- Loading branch information
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
) | ||
|
||
//nolint:forbidigo | ||
func emitOutput() error { | ||
out := getenv("INPUT_OUT", "") | ||
if len(out) == 0 { | ||
return nil | ||
} | ||
|
||
ref := getenv("INPUT_REF", "") | ||
if len(ref) == 0 { | ||
return nil | ||
} | ||
|
||
ghOutput := getenv("GITHUB_OUTPUT", "") | ||
if len(ghOutput) == 0 { | ||
return nil | ||
} | ||
|
||
file, err := os.Create(filepath.Clean(ghOutput)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = fmt.Fprintf(file, "changed=%t\n", isChanged(ref, out)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return file.Close() | ||
} | ||
|
||
//nolint:forbidigo | ||
func isChanged(refURL string, localFile string) bool { | ||
client := &http.Client{Timeout: httpTimeout} | ||
|
||
req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, refURL, nil) | ||
if err != nil { | ||
return true | ||
} | ||
|
||
resp, err := client.Do(req) | ||
if err != nil { | ||
return true | ||
} | ||
|
||
defer resp.Body.Close() //nolint:errcheck | ||
|
||
refData, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return true | ||
} | ||
|
||
localData, err := os.ReadFile(filepath.Clean(localFile)) | ||
if err != nil { | ||
return true | ||
} | ||
|
||
return !bytes.Equal(refData, localData) | ||
} | ||
|
||
const httpTimeout = 10 * time.Second |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
k6registry `v0.1.6` is here 🎉! | ||
|
||
This is an internal maintenance release. | ||
|
||
The only change is that in GitHub action mode, the change can be indicated by comparing the output to a reference output. The reference output URL can be passed in the `ref` action parameter. The output variable `changed` will be `true` or `false` depending on whether the output has changed or not compared to the reference output. |