-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support latest version with the latest tag
Signed-off-by: Christopher Larivière <[email protected]>
- Loading branch information
1 parent
eb6166c
commit e8c1626
Showing
9 changed files
with
112 additions
and
22 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
2 changes: 1 addition & 1 deletion
2
.github/workflows/manual.yaml → .github/workflows/release-manual.yaml
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
name: Build & publish images | ||
name: Manual - Build & publish images | ||
on: | ||
push: | ||
tags: | ||
|
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
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 |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
**/terraform.tfstate** | ||
**/*.tfstate | ||
**/*.bitwarden | ||
.actsecret | ||
.goenv | ||
## macos | ||
.DS_Store |
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 @@ | ||
package api | ||
|
||
type Interface interface { | ||
GetPublishedVersion(imageName string) (string, error) | ||
} |
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,67 @@ | ||
package github | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
type Github struct { | ||
Token string | ||
RepoOwner string | ||
} | ||
|
||
func (g *Github) GetPublishedVersion(imageName string) (string, error) { | ||
url := fmt.Sprintf("https://api.github.com/users/%s/packages/container/%s/versions", g.RepoOwner, imageName) | ||
|
||
req, err := http.NewRequest("GET", url, nil) | ||
if err != nil { | ||
fmt.Println("Error creating request:", err) | ||
return "", err | ||
} | ||
|
||
req.Header.Set("Accept", "application/vnd.github.v3+json") | ||
req.Header.Set("Authorization", "token "+g.Token) | ||
|
||
client := &http.Client{} | ||
resp, err := client.Do(req) | ||
if err != nil { | ||
fmt.Println("Error making request:", err) | ||
return "", err | ||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
fmt.Println("Received non-OK status code:", resp.StatusCode) | ||
return "", err | ||
} | ||
|
||
var data []map[string]interface{} | ||
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil { | ||
fmt.Println("Error decoding response body:", err) | ||
return "", err | ||
} | ||
|
||
for _, image := range data { | ||
if metadata, ok := image["metadata"].(map[string]interface{}); ok { | ||
if container, ok := metadata["container"].(map[string]interface{}); ok { | ||
if tags, ok := container["tags"].([]interface{}); ok { | ||
for i, tag := range tags { | ||
if tagStr, ok := tag.(string); ok && tagStr == "latest" { | ||
tags = append(tags[:i], tags[i+1:]...) | ||
longest := "" | ||
for _, t := range tags { | ||
if tStr, ok := t.(string); ok && len(tStr) > len(longest) { | ||
longest = tStr | ||
} | ||
} | ||
return longest, nil | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return "", fmt.Errorf("no data to go through") | ||
} |