Skip to content

Commit

Permalink
update install
Browse files Browse the repository at this point in the history
  • Loading branch information
henderiw committed May 17, 2024
1 parent 1c8f398 commit b0694d1
Show file tree
Hide file tree
Showing 8 changed files with 480 additions and 4 deletions.
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2024 Nokia
# Licensed under the Apache License 2.0
# SPDX-License-Identifier: Apache-2.0
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# Copyright 2024 Nokia
# Licensed under the Apache License 2.0
# SPDX-License-Identifier: Apache-2.0
---
name: goreleaser ci
on:
push:
# branches:
# - main
tags:
- v*
pull_request:
workflow_dispatch:
jobs:
build:
permissions: write-all
Expand All @@ -20,7 +27,7 @@ jobs:
with:
go-version-file: go.mod
- name: run go releaser
uses: goreleaser/goreleaser-action@v5.0.0
uses: goreleaser/goreleaser-action@v5.1.0
with:
version: latest
args: release --clean
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2024 Nokia
# Licensed under the Apache License 2.0
# SPDX-License-Identifier: Apache-2.0
---
name: Test
on:
workflow_dispatch:
pull_request:
push:
branches:
- "main"
- "!releases/**"
env:
GOVER: 1.22.2

jobs:
test:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GOVER }}
- run: go test -cover ./...
env:
CGO_ENABLED: 0
#- name: golangci-lint
# uses: golangci/golangci-lint-action@v6
# with:
# version: v1.38
# run staticcheck
14 changes: 12 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ builds:
main: cmd/kform/main.go
env:
- CGO_ENABLED=0
ldflags:
- -s -w -X github.com/kform-dev/kform/cmd.kform.commands.version={{.Version}} -X github.com/kform-dev/kform/cmd.kform.commands.commit={{.ShortCommit}} -X github.com/kform-dev/kform/cmd.kform.commands.date={{.Date}}
goos:
- darwin
#- freebsd
- linux
#- freebsd
#- openbsd
#- windows
goarch:
Expand All @@ -37,7 +39,15 @@ checksum:
archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}'
name_template: >-
{{ .ProjectName }}_
{{- replace .Version "v" "" }}_
{{- .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else if eq .Arch "arm" }}armv7
{{- else if eq .Arch "arm64" }}aarch64
{{- else }}{{ .Arch }}{{ end }}
files:
- none*
# use zip for windows archives
Expand Down
1 change: 1 addition & 0 deletions cmd/kform/commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func GetMain(ctx context.Context) *cobra.Command {
//updateHelp(names, subCmd)
cmd.AddCommand(subCmd)
}
cmd.AddCommand(GetVersionCommand(ctx))
return cmd
}

Expand Down
108 changes: 107 additions & 1 deletion cmd/kform/commands/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,109 @@
/*
Copyright 2024 Nokia.
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,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package commands

var version = "unknown"
import (
"context"
"fmt"
"io"
"net/http"
"os"
"os/exec"

"github.com/spf13/cobra"
)

var (
version = "0.0.0"
commit = "none"
date = "unknown"
)

const (
repoUrl = "https://github.com/kform-dev/kform"
downloadURL = "https://github.com/kform-dev/kform/raw/main/install.sh"
)

func GetVersionCommand(ctx context.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: "show kform version",
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Printf(" version: %s\n", version)
fmt.Printf(" commit: %s\n", commit)
fmt.Printf(" date: %s\n", date)
fmt.Printf(" source: %s\n", repoUrl)
fmt.Printf(" rel. notes: https://docs.kform.dev/rn/%s\n", version)

return nil
},
}

cmd.AddCommand(GetVersionUpgradeCommand(ctx))
return cmd
}

func GetVersionUpgradeCommand(ctx context.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "upgrade",
Short: "upgrade kform to latest available version",
//PreRunE: sudoCheck,
RunE: func(cmd *cobra.Command, args []string) error {
f, err := os.CreateTemp("", "kform")
defer os.Remove(f.Name())
if err != nil {
return fmt.Errorf("failed to create temp file: %w", err)
}
_ = downloadFile(downloadURL, f)

c := exec.Command("bash", f.Name())
// pass the environment variables to the upgrade script
// so that GITHUB_TOKEN is available
c.Env = os.Environ()

c.Stdout = os.Stdout
c.Stderr = os.Stderr
err = c.Run()
if err != nil {
return fmt.Errorf("upgrade failed: %w", err)
}

return nil
},
}

cmd.AddCommand()
return cmd
}

// downloadFile will download a file from a URL and write its content to a file.
func downloadFile(url string, file *os.File) error {
// Get the data
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()

// Write the body to file
_, err = io.Copy(file, resp.Body)
if err != nil {
return err
}

return nil
}
Loading

0 comments on commit b0694d1

Please sign in to comment.