6 Commits

Author SHA1 Message Date
Sankalp Kotewar
235994ccc5 Update bug_report.md (#30)
Some checks failed
ci-workflow / build (macos-latest) (push) Has been cancelled
ci-workflow / build (ubuntu-latest) (push) Has been cancelled
ci-workflow / build (windows-latest) (push) Has been cancelled
release / release (push) Has been cancelled
* Update bug_report.md

* Added extension version list command
2022-08-17 12:39:16 +05:30
Deepak Dahiya
ccd695dfaa Fixed e2e workflow issue (#29)
* Fixed e2e workflow issue

* Updating cli version

* minor
2022-08-16 15:05:44 +05:30
Deepak Dahiya
b8890ddb4c Used go-gh table printer for listing caches (#25)
* Used go-gh table printer for listing caches

* lint

* lint

* minor

* cleanup

* cleanup

* cleanup

* cleanup

* cleanup

* cleanup

* cleanup

* cleanup

* cleanup

* cleanup

* cleanup

* cleanup

* cleanup
2022-08-11 14:15:02 +05:30
Aparna Ravindra
c196049591 Create E2E test on main branch (#24)
* Create e2e_test.yml
2022-08-04 14:17:21 +05:30
Aparna Ravindra
1aec73ad5e Update canary.yaml to fix typo (#22)
Update secret name
2022-08-03 17:17:12 +05:30
Aparna Ravindra
ebd16ae99c Workflow: Canary Test (#18)
* Create canary.yaml
2022-08-03 15:38:35 +05:30
9 changed files with 193 additions and 79 deletions

View File

@@ -9,7 +9,7 @@ assignees: ''
### Describe the bug
A clear and concise description of what the bug is. Include CLI version by typing `gh actions-cache --version` and extension version by typing `gh actions-cache --version`. <!--TODO: Implement version printing for the cache -->
A clear and concise description of what the bug is. Include CLI version by typing `gh --version` and the extension version `gh extensions list | grep actions-cache`.
### Steps to reproduce the behavior

67
.github/workflows/canary.yaml vendored Normal file
View File

@@ -0,0 +1,67 @@
name: Canary Test
on:
release:
types: [released]
schedule:
- cron: "30 18 * * *"
workflow_dispatch:
jobs:
upload:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
name: cache upload (${{ matrix.os }})
steps:
- name: Create file to cache
run: |
mkdir test-cache
echo "foo" > test-cache/test.txt
- uses: actions/cache@v3
with:
path: test-cache
key: ${{ matrix.os }}-runner-${{ github.run_number }}-${{ github.run_attempt }}
canary:
needs: upload
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
env:
CacheKey: ${{ matrix.os }}-runner-${{ github.run_number }}-${{ github.run_attempt }}
steps:
- name: checkout repo
uses: actions/checkout@v2
- name: Install extension
env:
GITHUB_TOKEN: ${{ secrets.REPO_WRITE_TOKEN }}
run: gh extensions install actions/gh-actions-cache
- name: List Command
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.REPO_WRITE_TOKEN }}
run: |
cache_found=$(gh actions-cache list --key $CacheKey --limit 100 --branch $GITHUB_REF --order desc --sort created-at | grep $CacheKey)
echo $cache_found
[[ -z "$cache_found" ]] && exit 1 || echo "Cache List Successful"
- name: Delete Command
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.REPO_WRITE_TOKEN }}
run: |
cache_delete=$(gh actions-cache delete $CacheKey --branch $GITHUB_REF --confirm | grep "Deleted 1 cache entry with key")
echo $cache_delete
[[ -z "$cache_delete" ]] && exit 1 || echo "Cache Delete Successful"
- name: Slack Notification on failure
if: failure()
uses: 8398a7/action-slack@a74b761b4089b5d730d813fbedcd2ec5d394f3af
with:
text: actions/gh-actions-cache canary failure
status: ${{ job.status }}
fields: repo,workflow,message,author,action,ref
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

81
.github/workflows/e2e_test.yml vendored Normal file
View File

@@ -0,0 +1,81 @@
name: E2E Test
on:
push:
branches:
- main
workflow_dispatch:
jobs:
upload:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
name: cache upload (${{ matrix.os }})
steps:
- name: Create file to cache
run: |
mkdir test-cache
echo "foo" > test-cache/test.txt
- uses: actions/cache@v3
with:
path: test-cache
key: ${{ matrix.os }}-runner-${{ github.run_number }}-${{ github.run_attempt }}
canary:
needs: upload
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
env:
CacheKey: ${{ matrix.os }}-runner-${{ github.run_number }}-${{ github.run_attempt }}
steps:
- name: checkout repo
uses: actions/checkout@v2
- name: Restore Go modules cache
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: go-${{ runner.os }}-${{ hashFiles('go.mod') }}
restore-keys: |
go-${{ runner.os }}-
- name: Build the project
run: go build
- name: Install extension
env:
GITHUB_TOKEN: ${{ secrets.REPO_WRITE_TOKEN }}
run: gh extensions install .
- name: Print help
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.REPO_WRITE_TOKEN }}
run: |
gh actions-cache --help
- name: List Command
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.REPO_WRITE_TOKEN }}
run: |
cache_found=$(gh actions-cache list --key $CacheKey --limit 100 --branch $GITHUB_REF --order desc --sort created-at | grep $CacheKey)
echo $cache_found
[[ -z "$cache_found" ]] && exit 1 || echo "Cache List Successful"
- name: Delete Command
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.REPO_WRITE_TOKEN }}
run: |
cache_delete=$(gh actions-cache delete $CacheKey --branch $GITHUB_REF --confirm | grep "Deleted 1 cache entry with key")
echo $cache_delete
[[ -z "$cache_delete" ]] && exit 1 || echo "Cache Delete Successful"
- name: Slack Notification on failure
if: failure()
uses: 8398a7/action-slack@a74b761b4089b5d730d813fbedcd2ec5d394f3af
with:
text: actions/gh-actions-cache E2E test failure
status: ${{ job.status }}
fields: repo,workflow,message,author,action,ref
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

View File

@@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.16
go-version: 1.18
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3

View File

@@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra"
)
const VERSION = "1.0.0"
const VERSION = "1.0.1"
var rootCmd = &cobra.Command{
Use: "gh-actions-cache",

19
go.mod
View File

@@ -5,16 +5,23 @@ go 1.18
require (
github.com/AlecAivazis/survey/v2 v2.3.5
github.com/TwiN/go-color v1.1.0
github.com/cli/go-gh v0.0.4-0.20220623035622-91ca4ef447d4
github.com/cli/go-gh v0.1.0
github.com/nleeper/goment v1.4.4
github.com/spf13/cobra v1.4.0
github.com/spf13/cobra v1.5.0
github.com/stretchr/testify v1.8.0
)
require github.com/pmezard/go-difflib v1.0.0 // indirect
require (
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e // indirect
)
require (
github.com/cli/safeexec v1.0.0
github.com/cli/safeexec v1.0.0 // indirect
github.com/cli/shurcooL-graphql v0.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
@@ -22,13 +29,13 @@ require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.8
github.com/mattn/go-isatty v0.0.8 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tkuchiki/go-timezone v0.2.0 // indirect
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
golang.org/x/term v0.0.0-20210503060354-a79de5458b56
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 // indirect
golang.org/x/text v0.3.6 // indirect
gopkg.in/h2non/gock.v1 v1.1.2
gopkg.in/yaml.v3 v3.0.1 // indirect

26
go.sum
View File

@@ -6,13 +6,14 @@ github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63n
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
github.com/TwiN/go-color v1.1.0 h1:yhLAHgjp2iAxmNjDiVb6Z073NE65yoaPlcki1Q22yyQ=
github.com/TwiN/go-color v1.1.0/go.mod h1:aKVf4e1mD4ai2FtPifkDPP5iyoCwiK08YGzGwerjKo0=
github.com/cli/go-gh v0.0.4-0.20220623035622-91ca4ef447d4 h1:6WrekNBE2Y+Xl9OCl7vsg49SSN68hwaVryfEawQevaQ=
github.com/cli/go-gh v0.0.4-0.20220623035622-91ca4ef447d4/go.mod h1:Y/QFb/VxnXQH0W4VlP+507HVxMzQ430x8kdjUuVcono=
github.com/cli/go-gh v0.1.0 h1:kMqFmC3ECBrV2UKzlOHjNOTTchExVc5tjNHtCqk/zYk=
github.com/cli/go-gh v0.1.0/go.mod h1:eTGWl99EMZ+3Iau5C6dHyGAJRRia65MtdBtuhWc+84o=
github.com/cli/safeexec v1.0.0 h1:0VngyaIyqACHdcMNWfo6+KdUYnqEr2Sg+bSP1pdF+dI=
github.com/cli/safeexec v1.0.0/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
github.com/cli/shurcooL-graphql v0.0.1 h1:/9J3t9O6p1B8zdBBtQighq5g7DQRItBwuwGh3SocsKM=
github.com/cli/shurcooL-graphql v0.0.1/go.mod h1:U7gCSuMZP/Qy7kbqkk5PrqXEeDgtfG5K+W+u8weorps=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -29,14 +30,14 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
@@ -45,18 +46,21 @@ github.com/nleeper/goment v1.4.4 h1:GlMTpxvhueljArSunzYjN9Ri4SOmpn0Vh2hg2z/IIl8=
github.com/nleeper/goment v1.4.4/go.mod h1:zDl5bAyDhqxwQKAvkSXMRLOdCowrdZz53ofRJc4VhTo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e h1:BuzhfgfWQbX0dWzYzT1zsORLnHRv3bcRcsaUk0VmXA8=
github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e/go.mod h1:/Tnicc6m/lsJE0irFMA0LfIwTBo4QP7A8IfyIv4zZKI=
github.com/tkuchiki/go-timezone v0.2.0 h1:yyZVHtQRVZ+wvlte5HXvSpBkR0dPYnPEIgq9qqAqltk=
github.com/tkuchiki/go-timezone v0.2.0/go.mod h1:b1Ean9v2UXtxSq4TZF0i/TU9NuoWa9hOzOKoGCV2zqY=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
@@ -64,6 +68,7 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16CMAGuqwO2lX1mTyyRRc=
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
@@ -75,7 +80,6 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY=
gopkg.in/h2non/gock.v1 v1.1.2/go.mod h1:n7UGz/ckNChHiK05rDoiC4MYSunEC/lyaUm2WWaDva0=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

View File

@@ -3,11 +3,6 @@ package internal
import (
"errors"
"fmt"
"math"
"os"
"os/exec"
"strconv"
"strings"
"unicode/utf8"
"github.com/TwiN/go-color"
@@ -15,16 +10,13 @@ import (
gh "github.com/cli/go-gh"
"github.com/cli/go-gh/pkg/api"
ghRepo "github.com/cli/go-gh/pkg/repository"
"github.com/cli/safeexec"
"github.com/mattn/go-isatty"
ghTableprinter "github.com/cli/go-gh/pkg/tableprinter"
ghTerm "github.com/cli/go-gh/pkg/term"
"github.com/nleeper/goment"
"golang.org/x/term"
)
const MB_IN_BYTES = 1024 * 1024
const GB_IN_BYTES = 1024 * 1024 * 1024
const SIZE_COLUMN_WIDTH = 15
const LAST_ACCESSED_AT_COLUMN_WIDTH = 20
func GetRepo(r string) (ghRepo.Repository, error) {
if r != "" {
@@ -51,17 +43,19 @@ func FormatCacheSize(size_in_bytes float64) string {
}
func PrettyPrintCacheList(caches []types.ActionsCache) {
width, _, _ := getTerminalWidth(os.Stdout)
width = int(math.Max(float64(width), 100))
sizeWidth := SIZE_COLUMN_WIDTH // hard-coded size as the content is scoped
timeWidth := LAST_ACCESSED_AT_COLUMN_WIDTH // hard-coded size as the content is scoped
keyWidth := int(math.Floor(0.65 * float64(width-SIZE_COLUMN_WIDTH-LAST_ACCESSED_AT_COLUMN_WIDTH)))
refWidth := int(math.Floor(0.20 * float64(width-SIZE_COLUMN_WIDTH-LAST_ACCESSED_AT_COLUMN_WIDTH)))
terminal := ghTerm.FromEnv()
w, _, _ := terminal.Size()
tp := ghTableprinter.New(terminal.Out(), terminal.IsTerminalOutput(), w)
for _, cache := range caches {
var formattedRow string = getFormattedCacheInfo(cache, keyWidth, sizeWidth, refWidth, timeWidth)
fmt.Println(formattedRow)
tp.AddField(cache.Key)
tp.AddField(FormatCacheSize(cache.SizeInBytes))
tp.AddField(cache.Ref)
tp.AddField(lastAccessedTime(cache.LastAccessedAt))
tp.EndRow()
}
_ = tp.Render()
}
func PrettyPrintTrimmedCacheList(caches []types.ActionsCache) {
@@ -78,24 +72,7 @@ func PrettyPrintTrimmedCacheList(caches []types.ActionsCache) {
func lastAccessedTime(lastAccessedAt string) string {
lastAccessed, _ := goment.New(lastAccessedAt)
return fmt.Sprintf(" %s", lastAccessed.FromNow())
}
func trimOrPad(value string, maxSize int) string {
if len(value) > maxSize {
value = value[:maxSize-3] + "..."
} else {
value = value + strings.Repeat(" ", maxSize-len(value))
}
return value
}
func getFormattedCacheInfo(cache types.ActionsCache, keyWidth int, sizeWidth int, refWidth int, timeWidth int) string {
key := trimOrPad(cache.Key, keyWidth)
size := trimOrPad(fmt.Sprintf("[%s]", FormatCacheSize(cache.SizeInBytes)), sizeWidth)
ref := trimOrPad(cache.Ref, refWidth)
time := trimOrPad(lastAccessedTime(cache.LastAccessedAt), timeWidth)
return fmt.Sprintf("%s %s %s %s", key, size, ref, time)
return lastAccessed.FromNow()
}
func RedTick() string {
@@ -112,24 +89,6 @@ func PrintSingularOrPlural(count int, singularStr string, pluralStr string) stri
return fmt.Sprintf("%d %s", count, pluralStr)
}
func getTerminalWidth(f *os.File) (int, int, error) {
if !isatty.IsCygwinTerminal(f.Fd()) {
return term.GetSize(int(f.Fd()))
}
tputExe, err := safeexec.LookPath("tput")
if err != nil {
return 100, 100, nil
}
tputCmd := exec.Command(tputExe, "cols")
tputCmd.Stdin = os.Stdin
if out, err := tputCmd.Output(); err == nil {
if w, err := strconv.Atoi(strings.TrimSpace(string(out))); err == nil {
return w, 100, nil
}
}
return 100, 100, nil
}
func HttpErrorHandler(err error, errMsg404 string) types.HandledError {
var httpError api.HTTPError
if errors.As(err, &httpError) && httpError.StatusCode == 404 {

View File

@@ -1,9 +1,5 @@
package types
import (
"fmt"
)
type HandledError struct {
Message string
InnerError error
@@ -11,5 +7,5 @@ type HandledError struct {
// Allow HandledError to satisfy error interface.
func (err HandledError) Error() string {
return fmt.Sprintf(err.Message)
return err.Message
}