Skip to content

Commit 2dcc3ae

Browse files
authored
CI: pin hub branch during functional tests (#3526)
1 parent ea1a1d7 commit 2dcc3ae

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

cmd/crowdsec-cli/clihub/hub.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ cscli hub upgrade`,
4646
DisableAutoGenTag: true,
4747
}
4848

49+
cmd.AddCommand(cli.newBranchCmd())
4950
cmd.AddCommand(cli.newListCmd())
5051
cmd.AddCommand(cli.newUpdateCmd())
5152
cmd.AddCommand(cli.newUpgradeCmd())
@@ -84,6 +85,28 @@ func (cli *cliHub) List(out io.Writer, hub *cwhub.Hub, all bool) error {
8485
return nil
8586
}
8687

88+
func (cli *cliHub) newBranchCmd() *cobra.Command {
89+
var all bool
90+
91+
cmd := &cobra.Command{
92+
Use: "branch",
93+
Short: "Show selected hub branch",
94+
Long: "Display the hub branch to be used, depending on configuration and crowdsec version",
95+
Args: args.NoArgs,
96+
DisableAutoGenTag: true,
97+
RunE: func(cmd *cobra.Command, _ []string) error {
98+
branch := require.HubBranch(cmd.Context(), cli.cfg())
99+
fmt.Println(branch)
100+
return nil
101+
},
102+
}
103+
104+
flags := cmd.Flags()
105+
flags.BoolVarP(&all, "all", "a", false, "List all available items, including those not installed")
106+
107+
return cmd
108+
}
109+
87110
func (cli *cliHub) newListCmd() *cobra.Command {
88111
var all bool
89112

test/lib/config/config-global

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ config_prepare() {
6161
.api.server.listen_socket="/run/crowdsec.sock" |
6262
.config_paths.config_dir |= sub("/$", "")
6363
' "${CONFIG_DIR}/config.yaml"
64+
65+
# pin the branch to avoid having to query the last version repeatedly.
66+
# this means the fixture could possibly go stale (i.e. use the wrong branch) if a new version is released,
67+
# but that shouldn't impact the tests anyway.
68+
69+
HUB_BRANCH=$("$CSCLI" hub branch 2>/dev/null)
70+
export HUB_BRANCH
71+
72+
echo "Setting up tests with hub branch $HUB_BRANCH"
73+
74+
# need a working config, so we do it as a separate step.
75+
76+
yq -i e '.cscli.hub_branch=strenv(HUB_BRANCH)' "${CONFIG_DIR}/config.yaml"
6477
}
6578

6679
make_init_data() {

test/lib/config/config-local

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ config_generate() {
9898
.api.server.console_path=strenv(CONFIG_DIR)+"/console.yaml" |
9999
del(.api.server.online_client)
100100
' ../config/config.yaml >"${CONFIG_DIR}/config.yaml"
101+
102+
# pin the branch to avoid having to query the last version repeatedly.
103+
# this means the fixture could possibly go stale (i.e. use the wrong branch) if a new version is released,
104+
# but that shouldn't impact the tests anyway.
105+
106+
HUB_BRANCH=$("$CSCLI" hub branch 2>/dev/null)
107+
export HUB_BRANCH
108+
109+
echo "Setting up tests with hub branch $HUB_BRANCH"
110+
111+
# need a working config, so we do it as a separate step.
112+
113+
yq -i e '.cscli.hub_branch=strenv(HUB_BRANCH)' "${CONFIG_DIR}/config.yaml"
101114
}
102115

103116
make_init_data() {

0 commit comments

Comments
 (0)