Skip to content

Commit

Permalink
Update CI to use matrix builds
Browse files Browse the repository at this point in the history
Also modify version subcommand to not require k8s access when the
`--cli` flag is set.

Signed-off-by: Andrew Seigner <[email protected]>
  • Loading branch information
siggy committed Feb 17, 2021
1 parent d4ef4b9 commit 7ef8a76
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 49 deletions.
137 changes: 91 additions & 46 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ on:
branches:
- main

defaults:
run:
shell: bash

jobs:

go_unit_tests:
Expand All @@ -18,7 +22,8 @@ jobs:
container:
image: golang:1.15.8
steps:
- uses: actions/checkout@v2
- name: Checkout Code
uses: actions/checkout@v2

- name: Test
run: go test -race -v ./...
Expand All @@ -29,35 +34,88 @@ jobs:
container:
image: golang:1.15.8
steps:
- uses: actions/checkout@v2
- name: Checkout Code
uses: actions/checkout@v2

- name: Lint
run: bin/lint

release:
if: startsWith(github.ref, 'refs/tags')
needs:
- go_unit_tests
- go_lint
name: Release
build_cli:
name: Build CLI
runs-on: ubuntu-20.04
strategy:
matrix:
include:
- platform: linux-amd64
goos: linux
goarch: amd64
- platform: linux-arm64
goos: linux
goarch: arm64
- platform: darwin
goos: darwin
goarch: ""
- platform: windows
goos: windows
goarch: ""
container:
image: golang:1.15.8
steps:
- name: Checkout Code
uses: actions/checkout@v2

- run: echo "tag=${GITHUB_REF##*/}" >> $GITHUB_ENV
- name: Parse GITHUB_REF
run: echo "tag=${GITHUB_REF##*/}" >> $GITHUB_ENV

- name: Build Project
run: |
GO_FLAGS="-mod=readonly -ldflags \"-s -w -X github.com/buoyantio/linkerd-buoyant/pkg/version.Version=${{ env.tag }}\""
- name: Build CLI
run: CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o linkerd-buoyant-${{ env.tag }}-${{ matrix.platform }} -mod=readonly -ldflags "-s -w -X github.com/buoyantio/linkerd-buoyant/pkg/version.Version=${{ env.tag }}"

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build "${GO_FLAGS}" -o linkerd-buoyant-${{ env.tag }}-linux-amd64
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build "${GO_FLAGS}" -o linkerd-buoyant-${{ env.tag }}-linux-arm64
CGO_ENABLED=0 GOOS=darwin go build "${GO_FLAGS}" -o linkerd-buoyant-${{ env.tag }}-darwin
CGO_ENABLED=0 GOOS=windows go build "${GO_FLAGS}" -o linkerd-buoyant-${{ env.tag }}-windows
- name: Upload CLI Executable
uses: actions/upload-artifact@v2
with:
name: linkerd-buoyant-${{ env.tag }}-${{ matrix.platform }}
path: linkerd-buoyant-${{ env.tag }}-${{ matrix.platform }}

smoke_test_cli:
name: Smoke Test CLI
needs:
- build_cli
strategy:
matrix:
include:
# no arm runner available, skip it
- platform: linux-amd64
os: ubuntu-20.04
- platform: darwin
os: macos-10.15
- platform: windows
os: windows-2019
runs-on: ${{ matrix.os }}
steps:
- name: Parse GITHUB_REF
run: echo "tag=${GITHUB_REF##*/}" >> $GITHUB_ENV

- name: Download CLI Executable
uses: actions/download-artifact@v2
with:
name: linkerd-buoyant-${{ env.tag }}-${{ matrix.platform }}

- name: Run CLI
run: |
ls -R
chmod +x linkerd-buoyant-${{ env.tag }}-${{ matrix.platform }}
./linkerd-buoyant-${{ env.tag }}-${{ matrix.platform }} version --cli
# everything below here for releases (tags)
create_release:
if: startsWith(github.ref, 'refs/tags')
name: Create Release
needs:
- go_unit_tests
- go_lint
- smoke_test_cli
runs-on: ubuntu-20.04
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1
Expand All @@ -69,39 +127,26 @@ jobs:
draft: false
prerelease: false

- name: Upload Release Asset (linux-amd64)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./linkerd-buoyant-${{ env.tag }}-linux-amd64
asset_name: linkerd-buoyant-${{ env.tag }}-linux-amd64
asset_content_type: application/octet-stream
- name: Upload Release Asset (linux-arm64)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./linkerd-buoyant-${{ env.tag }}-linux-arm64
asset_name: linkerd-buoyant-${{ env.tag }}-linux-arm64
asset_content_type: application/octet-stream
- name: Upload Release Asset (darwin)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./linkerd-buoyant-${{ env.tag }}-darwin
asset_name: linkerd-buoyant-${{ env.tag }}-darwin
asset_content_type: application/octet-stream
- name: Upload Release Asset (windows)
upload_release_assets:
if: startsWith(github.ref, 'refs/tags')
name: Upload Release Assets
needs:
- create_release
strategy:
matrix:
include:
- platform: linux-amd64
- platform: linux-arm64
- platform: darwin
- platform: windows
runs-on: ubuntu-20.04
steps:
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./linkerd-buoyant-${{ env.tag }}-windows
asset_name: linkerd-buoyant-${{ env.tag }}-windows
asset_path: ./linkerd-buoyant-${{ env.tag }}-${{ matrix.platform }}
asset_name: linkerd-buoyant-${{ env.tag }}-${{ matrix.platform }}
asset_content_type: application/octet-stream
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# linkerd-buoyant

![Actions](https://github.com/BuoyantIO/linkerd-buoyant/workflows/Actions/badge.svg?branch=main)

The Linkerd Buoyant extension is a CLI tool for managing the Buoyant Cloud
Agent.

Expand Down
7 changes: 6 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"os"
"path/filepath"

"github.com/fatih/color"
Expand Down Expand Up @@ -32,7 +33,11 @@ upgrade, and delete functionality`,

defaultKubeConfig := ""
if home := homedir.HomeDir(); home != "" {
defaultKubeConfig = filepath.Join(home, ".kube", "config")
kubeconfig := filepath.Join(home, ".kube", "config")
_, err := os.Stat(kubeconfig)
if !os.IsNotExist(err) {
defaultKubeConfig = kubeconfig
}
}

// global flags
Expand Down
7 changes: 5 additions & 2 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ func newCmdVersion(cfg *config) *cobra.Command {
Args: cobra.NoArgs,
Short: "Print the CLI and Agent version information",
RunE: func(cmd *cobra.Command, args []string) error {
if versionCfg.cli {
return versionCmd(cmd.Context(), versionCfg, nil)
}

client, err := k8s.New(cfg.kubeconfig, cfg.kubecontext, cfg.bcloudServer)
if err != nil {
return err
}

return versionCmd(cmd.Context(), versionCfg, client)
},
}
Expand All @@ -47,7 +50,7 @@ func versionCmd(
fmt.Fprintf(cfg.stdout, "CLI version: %s\n", version.Version)
}

if cfg.cli {
if cfg.cli || client == nil {
return nil
}

Expand Down

0 comments on commit 7ef8a76

Please sign in to comment.