Skip to content

Commit

Permalink
Merge branch 'master' into update_test
Browse files Browse the repository at this point in the history
  • Loading branch information
nexustar authored Apr 21, 2022
2 parents f743356 + 762dd94 commit 0c6361c
Show file tree
Hide file tree
Showing 18 changed files with 497 additions and 220 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/release-tiup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
release:
runs-on: ubuntu-latest
timeout-minutes: 30
outputs:
REL_VER: ${{ steps.build_tiup.outputs.REL_VER }}
strategy:
fail-fast: true
matrix:
Expand Down Expand Up @@ -195,3 +197,40 @@ jobs:
omitNameDuringUpdate: true
prerelease: ${{ github.event.release.prerelease }}
token: ${{ secrets.GITHUB_TOKEN }}

brew-upgrade:
runs-on: ubuntu-latest
timeout-minutes: 5
needs: release
steps:
- name: Check out brew code
uses: actions/checkout@v3
continue-on-error: true
if: github.event_name == 'release'
with:
repository: pingcap/homebrew-brew
persist-credentials: false
ref: master
path: ${{ github.workspace }}/homebrew-brew
fetch-depth: 0

- name: Update and Check tiup version
id: update_version
working-directory: ${{ github.workspace }}/homebrew-brew
continue-on-error: true
if: github.event_name == 'release'
run: |
sed -i 's/version.*/version "${{ needs.release.outputs.REL_VER }}"/g' Formula/tiup.rb
sed -i 's/tag:.*/tag: "${{ needs.release.outputs.REL_VER }}"/g' Formula/tiup.rb
cat Formula/tiup.rb
- name: Push new homebrew
uses: actions-js/push@master
continue-on-error: true
if: github.event_name == 'release'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
directory: ${{ github.workspace }}/homebrew-brew
message: "tiup: ${{ needs.release.outputs.REL_VER }}"
branch: master
repository: pingcap/homebrew-brew
148 changes: 0 additions & 148 deletions cmd/help.go

This file was deleted.

107 changes: 107 additions & 0 deletions cmd/history.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Copyright 2022 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"encoding/json"
"fmt"
"strconv"

"github.com/pingcap/errors"
"github.com/pingcap/tiup/pkg/environment"
"github.com/pingcap/tiup/pkg/tui"
"github.com/spf13/cobra"
)

// newHistoryCmd history
func newHistoryCmd() *cobra.Command {
rows := 100
var displayMode string
var all bool
cmd := &cobra.Command{
Use: "history <rows>",
Short: "Display the historical execution record of TiUP, displays 100 lines by default",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
r, err := strconv.Atoi(args[0])
if err == nil {
rows = r
} else {
return fmt.Errorf("%s: numeric argument required", args[0])
}
}

env := environment.GlobalEnv()
rows, err := env.GetHistory(rows, all)
if err != nil {
return err
}

if displayMode == "json" {
for _, r := range rows {
rBytes, err := json.Marshal(r)
if err != nil {
continue
}
fmt.Println(string(rBytes))
}
return nil
}
var table [][]string
table = append(table, []string{"Date", "Command", "Code"})

for _, r := range rows {
table = append(table, []string{
r.Date.Format("2006-01-02T15:04:05"),
r.Command,
strconv.Itoa(r.Code),
})
}
tui.PrintTable(table, true)
fmt.Printf("history log save path: %s\n", env.LocalPath(environment.HistoryDir))
return nil
},
}
cmd.Flags().StringVar(&displayMode, "format", "default", "The format of output, available values are [default, json]")
cmd.Flags().BoolVar(&all, "all", false, "Display all execution history")
cmd.AddCommand(newHistoryCleanupCmd())
return cmd
}

func newHistoryCleanupCmd() *cobra.Command {
var retainDays int
var all bool
var skipConfirm bool
cmd := &cobra.Command{
Use: "cleanup",
Short: "delete all execution history",
RunE: func(cmd *cobra.Command, args []string) error {
if retainDays < 0 {
return errors.Errorf("retain-days cannot be less than 0")
}

if all {
retainDays = 0
}

env := environment.GlobalEnv()
return env.DeleteHistory(retainDays, skipConfirm)
},
}

cmd.Flags().IntVar(&retainDays, "retain-days", 60, "Number of days to keep history for deletion")
cmd.Flags().BoolVar(&all, "all", false, "Delete all history")
cmd.Flags().BoolVarP(&skipConfirm, "yes", "y", false, "Skip all confirmations and assumes 'yes'")
return cmd
}
12 changes: 12 additions & 0 deletions cmd/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,24 @@ func newTransferOwnerCmd() *cobra.Command {
// the `mirror rotate` sub command
func newMirrorRotateCmd() *cobra.Command {
addr := "0.0.0.0:8080"
keyDir := ""

cmd := &cobra.Command{
Use: "rotate",
Short: "Rotate root.json",
Long: "Rotate root.json make it possible to modify root.json",
RunE: func(cmd *cobra.Command, args []string) error {
teleCommand = cmd.CommandPath()

e, err := environment.InitEnv(repoOpts, repository.MirrorOptions{KeyDir: keyDir})
if err != nil {
if errors.Is(perrs.Cause(err), v1manifest.ErrLoadManifest) {
log.Warnf("Please check for root manifest file, you may download one from the repository mirror, or try `tiup mirror set` to force reset it.")
}
return err
}
environment.SetGlobalEnv(e)

root, err := editLatestRootManifest()
if err != nil {
return err
Expand All @@ -465,6 +476,7 @@ func newMirrorRotateCmd() *cobra.Command {
},
}
cmd.Flags().StringVarP(&addr, "addr", "", addr, "listen address:port when starting the temp server for rotating")
cmd.Flags().StringVarP(&keyDir, "key-dir", "", keyDir, "specify the directory where stores the private keys")

return cmd
}
Expand Down
Loading

0 comments on commit 0c6361c

Please sign in to comment.