未验证 提交 d307489e 编写于 作者: LinuxSuRen's avatar LinuxSuRen 提交者: GitHub

Ignore load config file with cmd completion (#353)

* Ignore load config file with cmd completion

* Upload the artifacts before doing test

* Add debug info when writing generate config file

* Fix the empty config file path when first save generated config file

* Not ignore center start cmd for loading config

* Download the jenkins.war into a unif dir

* Add jenkins.war formula support

* Fix the wrong formula URL

* Fix the formula issues

* Upload artifacts of pr and clean it when pr was closed

* Fix the artifacts file path

* Fix the wrong artifact path
上级 c50dbb81
name: Pull Request Clean
on:
pull_request:
types: [closed]
jobs:
build:
name: Build
runs-on: ubuntu-18.04
steps:
- name: Build
run: |
pr=$(echo $GITHUB_REF | sed 's/refs\/pull\///g' | sed 's/\/merge//g')
curl -ulinuxsuren:${{ secrets.BINTRAY_TOKEN }} -X DELETE https://api.bintray.com/packages/jenkins-zh/generic/jenkins-cli/versions/pr-$pr
......@@ -29,12 +29,7 @@ jobs:
- name: Build
run: |
export PATH=$PATH:${PWD}/bin:$GOPATH/bin:/home/runner/go/bin
make clean go-bindata-download-linux tools init build-all
- name: Test
run: |
export PATH=$PATH:${PWD}/bin:$GOPATH/bin:/home/runner/go/bin
make test
make clean go-bindata-download-linux tools init release
# - name: SonarCloud Scan
# uses: LinuxSuRen/sonarcloud-github-action@master
......@@ -42,6 +37,22 @@ jobs:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Upload PR to Bintray
run: |
pr=$(echo $GITHUB_REF | sed 's/refs\/pull\///g' | sed 's/\/merge//g')
echo "start to upload generic packages for pr-$pr"
curl -ulinuxsuren:${{ secrets.BINTRAY_TOKEN }} -X DELETE https://api.bintray.com/packages/jenkins-zh/generic/jenkins-cli/versions/pr-$pr
curl -T release/jcli-darwin-amd64.tar.gz -ulinuxsuren:${{ secrets.BINTRAY_TOKEN }} \
-H "X-Bintray-Package:jenkins-cli" -H "X-Bintray-Version:pr-$pr" \
https://api.bintray.com/content/jenkins-zh/generic/jenkins-cli/pr-$pr/jcli-darwin-amd64.tar.gz
curl -T release/jcli-linux-amd64.tar.gz -ulinuxsuren:${{ secrets.BINTRAY_TOKEN }} \
-H "X-Bintray-Package:jenkins-cli" -H "X-Bintray-Version:pr-$pr" \
https://api.bintray.com/content/jenkins-zh/generic/jenkins-cli/pr-$pr/jcli-linux-amd64.tar.gz
curl -T release/jcli-windows-386.tar.gz -ulinuxsuren:${{ secrets.BINTRAY_TOKEN }} \
-H "X-Bintray-Package:jenkins-cli" -H "X-Bintray-Version:pr-$pr" \
https://api.bintray.com/content/jenkins-zh/generic/jenkins-cli/pr-$pr/jcli-windows-386.tar.gz
curl -ulinuxsuren:${{ secrets.BINTRAY_TOKEN }} -X POST https://api.bintray.com/content/jenkins-zh/generic/jenkins-cli/pr-$pr/publish
- name: Upload darwin artifact
uses: actions/upload-artifact@v1.0.0
with:
......@@ -59,3 +70,8 @@ jobs:
with:
name: windows
path: bin/windows/jcli.exe
- name: Test
run: |
export PATH=$PATH:${PWD}/bin:$GOPATH/bin:/home/runner/go/bin
make test
......@@ -23,13 +23,22 @@ Useful links:
* [Jenkins Remote Access API](https://wiki.jenkins.io/display/JENKINS/Remote+access+API)
* [Jenkins REST API overview](https://www.youtube.com/watch?v=D93t1jElt4Q) by [Cliffano Subagio](https://github.com/cliffano)
*
## Testing
We use a BDD Testing Framework to test our project. Please make sure you're familiar
with [ginkgo](https://github.com/onsi/ginkgo) before you get start to contribute.
### Test By Manual
Unit testing can help us a lot, but doing the manual test is still necessary. I highly suggest that you test it under
a totally fresh environment. Here is list of free resources that you can use:
| Provider | Link |
|---|---|
| Aliyun | [https://api.aliyun.com/#/cli](https://api.aliyun.com/#/cli) |
| Google Could | [https://ssh.cloud.google.com/cloudshell/environment/view](https://ssh.cloud.google.com/cloudshell/environment/view) |
## Pull Requests
Before you get started, please fork this project into your GitHub account. Then
......
......@@ -2,6 +2,7 @@ package cmd
import (
"fmt"
"github.com/mitchellh/go-homedir"
"go.uber.org/zap"
"net/http"
"os"
......@@ -22,6 +23,8 @@ type CenterDownloadOption struct {
Output string
ShowProgress bool
Formula string
RoundTripper http.RoundTripper
}
......@@ -37,7 +40,7 @@ func init() {
i18n.T("The mirror site of Jenkins"))
centerDownloadCmd.Flags().BoolVarP(&centerDownloadOption.ShowProgress, "progress", "p", true,
i18n.T("If you want to show the download progress"))
centerDownloadCmd.Flags().StringVarP(&centerDownloadOption.Output, "output", "o", "jenkins.war",
centerDownloadCmd.Flags().StringVarP(&centerDownloadOption.Output, "output", "o", "",
i18n.T("The file of output"))
}
......@@ -48,6 +51,19 @@ var centerDownloadCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, _ []string) error {
return centerDownloadOption.DownloadJenkins()
},
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
if centerDownloadOption.Output != "" {
return
}
var userHome string
if userHome, err = homedir.Dir(); err != nil {
return
}
centerDownloadOption.Output = fmt.Sprintf("%s/.jenkins-cli/cache/%s/jenkins.war", userHome, centerDownloadOption.Version)
return
},
}
// DownloadJenkins download the Jenkins
......@@ -68,6 +84,7 @@ func (c *CenterDownloadOption) DownloadJenkins() (err error) {
JenkinsCore: client.JenkinsCore{
RoundTripper: c.RoundTripper,
},
Formula: c.Formula,
LTS: c.LTS,
Version: c.Version,
Output: c.Output,
......
......@@ -37,6 +37,7 @@ type CenterStartOption struct {
Download bool
Version string
LTS bool
Formula string
DryRun bool
}
......@@ -64,6 +65,8 @@ func init() {
i18n.T("The of version of jenkins.war"))
centerStartCmd.Flags().BoolVarP(&centerStartOption.LTS, "lts", "", true,
i18n.T("If you want to download Jenkins as LTS"))
centerStartCmd.Flags().StringVarP(&centerStartOption.Formula, "formula", "", "",
i18n.T("The formula of jenkins.war, only support zh currently"))
centerStartCmd.Flags().BoolVarP(&centerStartOption.HTTPSEnable, "https-enable", "", false,
i18n.T("If you want to enable https"))
......@@ -99,6 +102,7 @@ var centerStartCmd = &cobra.Command{
if _, fileErr := os.Stat(jenkinsWar); fileErr != nil {
download := &CenterDownloadOption{
Mirror: "default",
Formula: centerStartOption.Formula,
LTS: centerStartOption.LTS,
Output: jenkinsWar,
ShowProgress: true,
......
......@@ -158,10 +158,8 @@ func findSuiteByName(name string) (suite *PluginSuite) {
}
func loadDefaultConfig() (err error) {
var userHome string
userHome, err = homedir.Dir()
if err == nil {
configPath := fmt.Sprintf("%s/.jenkins-cli.yaml", userHome)
var configPath string
if configPath, err = getDefaultConfigPath(); err == nil {
if _, err = os.Stat(configPath); err == nil {
err = loadConfig(configPath)
}
......@@ -169,6 +167,15 @@ func loadDefaultConfig() (err error) {
return
}
func getDefaultConfigPath() (configPath string, err error) {
var userHome string
userHome, err = homedir.Dir()
if err == nil {
configPath = fmt.Sprintf("%s/.jenkins-cli.yaml", userHome)
}
return
}
func loadConfig(path string) (err error) {
configOptions.ConfigFileLocation = path
......
......@@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"github.com/mitchellh/go-homedir"
"go.uber.org/zap"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
......@@ -59,13 +60,21 @@ var configGenerateCmd = &cobra.Command{
// InteractiveWithConfig be friendly for a newer
func (o *ConfigGenerateOption) InteractiveWithConfig(cmd *cobra.Command, data []byte) (err error) {
configPath := configOptions.ConfigFileLocation
_, err = os.Stat(configPath)
if configPath == "" {
configPath, err = getDefaultConfigPath()
}
if err == nil {
_, err = os.Stat(configPath)
}
if err != nil && os.IsNotExist(err) {
confirm := o.Confirm("Cannot found your config file, do you want to edit it?")
if confirm {
var content string
content, err = o.Editor(string(data), "Edit your config file")
if err == nil {
logger.Debug("write generated config file", zap.String("path", configPath))
err = ioutil.WriteFile(configPath, []byte(content), 0644)
}
}
......
......@@ -46,10 +46,10 @@ var healthCheckRegister = &health.CheckRegister{
var rootCmd = &cobra.Command{
Use: "jcli",
Short: i18n.T("jcli is a tool which could help you with your multiple Jenkins"),
Long: `jcli is Jenkins CLI which could help with your multiple Jenkins,
Manage your Jenkins and your pipelines
More information could found at https://jenkins-zh.cn`,
Short: i18n.T("Jenkins CLI written by golang which could help you with your multiple Jenkins"),
Long: `Jenkins CLI written by golang which could help you with your multiple Jenkins,
We'd love to hear your feedback at https://github.com/jenkins-zh/jenkins-cli/issues`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
if logger, err = util.InitLogger(rootOptions.LoggerLevel); err == nil {
client.SetLogger(logger)
......@@ -91,9 +91,10 @@ More information could found at https://jenkins-zh.cn`,
func needReadConfig(cmd *cobra.Command) bool {
ignoreConfigLoad := []string{
"config.generate",
"center.start",
//"center.start", // relay on the config when find a mirror
"cwp",
"version",
"completion",
}
configPath := getCmdPath(cmd)
......
......@@ -18,6 +18,8 @@ type UpdateCenterManager struct {
Version string
Output string
Formula string
ShowProgress bool
}
......@@ -132,7 +134,9 @@ func (u *UpdateCenterManager) GetJenkinsWarURL() (warURL string) {
version = "latest"
}
if u.LTS {
if u.Formula == "zh" {
warURL = fmt.Sprintf("https://dl.bintray.com/jenkins-zh/generic/jenkins/%s/jenkins-zh.war", version)
} else if u.LTS {
warURL = fmt.Sprintf("%s/war-stable/%s/jenkins.war", strings.TrimRight(u.MirrorSite, "/"), version)
} else {
warURL = fmt.Sprintf("%s/war/%s/jenkins.war", strings.TrimRight(u.MirrorSite, "/"), version)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册