Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47113d1159 | ||
|
|
9adb9e80c2 | ||
|
|
18233abdce | ||
|
|
d3293b69e1 | ||
|
|
2b273da8da |
2
.github/workflows/canary.yaml
vendored
2
.github/workflows/canary.yaml
vendored
@@ -35,7 +35,7 @@ jobs:
|
||||
CacheKey: ${{ matrix.os }}-runner-${{ github.run_number }}-${{ github.run_attempt }}
|
||||
steps:
|
||||
- name: checkout repo
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: Install extension
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.REPO_WRITE_TOKEN }}
|
||||
|
||||
2
.github/workflows/e2e_test.yml
vendored
2
.github/workflows/e2e_test.yml
vendored
@@ -34,7 +34,7 @@ jobs:
|
||||
CacheKey: ${{ matrix.os }}-runner-${{ github.run_number }}-${{ github.run_attempt }}
|
||||
steps:
|
||||
- name: checkout repo
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: Restore Go modules cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
|
||||
@@ -8,6 +8,8 @@ It also allows deleting a corrupt, incomplete or dangling cache. A cache can be
|
||||
|
||||
This extension builds on top of [cache management](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#managing-caches) capabilities exposed by GitHub [APIs](https://docs.github.com/en/rest/actions/cache).
|
||||
|
||||
**Note:** This extension currently supports github.com only, GitHub Enterprise Server is not supported currently.
|
||||
|
||||
## Installation
|
||||
|
||||
1. Install the `gh` CLI - see the [installation](https://github.com/cli/cli#installation)
|
||||
@@ -97,4 +99,4 @@ EXAMPLES:
|
||||
|
||||
|
||||
## Contributing
|
||||
If anything feels off, or if you feel that some functionality is missing, please check out the [contributing page](CONTRIBUTING.md). There you will find instructions for sharing your feedback, building the tool locally, and submitting pull requests to the project.
|
||||
If anything feels off, or if you feel that some functionality is missing, please check out the [contributing page](CONTRIBUTING.md). There you will find instructions for sharing your feedback, building the tool locally, and submitting pull requests to the project.
|
||||
|
||||
15
cmd/list.go
15
cmd/list.go
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/actions/gh-actions-cache/service"
|
||||
"github.com/actions/gh-actions-cache/types"
|
||||
"github.com/spf13/cobra"
|
||||
ghTerm "github.com/cli/go-gh/pkg/term"
|
||||
)
|
||||
|
||||
func NewCmdList() *cobra.Command {
|
||||
@@ -41,9 +42,13 @@ func NewCmdList() *cobra.Command {
|
||||
return types.HandledError{Message: err.Error(), InnerError: err}
|
||||
}
|
||||
|
||||
// This will be used to determine the if output is terminal
|
||||
terminal := ghTerm.FromEnv()
|
||||
isTerminalOutput := terminal.IsTerminalOutput()
|
||||
|
||||
if f.Branch == "" && f.Key == "" {
|
||||
totalCacheSize, err := artifactCache.GetCacheUsage()
|
||||
if err == nil && totalCacheSize > 0 {
|
||||
if err == nil && totalCacheSize > 0 && isTerminalOutput {
|
||||
fmt.Printf("Total caches size %s\n\n", internal.FormatCacheSize(totalCacheSize))
|
||||
}
|
||||
}
|
||||
@@ -58,9 +63,11 @@ func NewCmdList() *cobra.Command {
|
||||
totalCaches := listCacheResponse.TotalCount
|
||||
caches := listCacheResponse.ActionsCaches
|
||||
if len(caches) > 0 {
|
||||
fmt.Printf("Showing %d of %d cache entries in %s/%s\n\n", displayedEntriesCount(len(caches), f.Limit), totalCaches, repo.Owner(), repo.Name())
|
||||
if isTerminalOutput {
|
||||
fmt.Printf("Showing %d of %d cache entries in %s/%s\n\n", displayedEntriesCount(len(caches), f.Limit), totalCaches, repo.Owner(), repo.Name())
|
||||
}
|
||||
internal.PrettyPrintCacheList(caches)
|
||||
} else {
|
||||
} else if isTerminalOutput {
|
||||
fmt.Printf("There are no Actions caches currently present in this repo or for the provided filters\n")
|
||||
}
|
||||
return nil
|
||||
@@ -69,7 +76,7 @@ func NewCmdList() *cobra.Command {
|
||||
|
||||
listCmd.Flags().StringVarP(&f.Repo, "repo", "R", "", "Select another repository for finding actions cache.")
|
||||
listCmd.Flags().StringVarP(&f.Branch, "branch", "B", "", "Filter by branch")
|
||||
listCmd.Flags().IntVarP(&f.Limit, "limit", "", 30, "Number of items to fetch between 1 and 100")
|
||||
listCmd.Flags().IntVarP(&f.Limit, "limit", "L", 30, "Number of items to fetch between 1 and 100")
|
||||
listCmd.Flags().StringVarP(&f.Key, "key", "", "", "Filter by key")
|
||||
listCmd.Flags().StringVarP(&f.Order, "order", "", "", "Order of caches returned (asc/desc)")
|
||||
listCmd.Flags().StringVarP(&f.Sort, "sort", "", "", "Sort fetched caches (last-used/size/created-at)")
|
||||
|
||||
@@ -62,6 +62,18 @@ func TestListWithIncorrectLimit(t *testing.T) {
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
func TestListLimitShorthandUsingIncorrectLimit(t *testing.T) {
|
||||
t.Cleanup(gock.Off)
|
||||
|
||||
cmd := NewCmdList()
|
||||
cmd.SetArgs([]string{"-L", "102", "--repo", "testOrg/testRepo"})
|
||||
err := cmd.Execute()
|
||||
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, err, fmt.Errorf("102 is not a valid integer value for limit flag. Allowed values: 1-100"))
|
||||
assert.True(t, gock.IsDone(), internal.PrintPendingMocks(gock.Pending()))
|
||||
}
|
||||
|
||||
func TestListWithIncorrectOrder(t *testing.T) {
|
||||
t.Cleanup(gock.Off)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user