From 3cb6988b8ba162c2acf87d8d2bc431c9f60f1d64 Mon Sep 17 00:00:00 2001 From: Hidetake Iwata Date: Sun, 28 Nov 2021 15:10:23 +0900 Subject: [PATCH] Refactor workflows (#668) * Refactor workflows * Fix runs-on * Fix Dockerfile --- .github/workflows/go.yaml | 102 +++------------------------------ .github/workflows/release.yaml | 70 ++++++++++++++++++++++ Dockerfile | 3 +- Makefile | 49 ---------------- 4 files changed, 79 insertions(+), 145 deletions(-) create mode 100644 .github/workflows/release.yaml delete mode 100644 Makefile diff --git a/.github/workflows/go.yaml b/.github/workflows/go.yaml index 29b3fff..c335141 100644 --- a/.github/workflows/go.yaml +++ b/.github/workflows/go.yaml @@ -8,7 +8,6 @@ on: - .github/workflows/go.yaml - pkg/** - go.* - - Makefile tags: - v* pull_request: @@ -18,114 +17,29 @@ on: - .github/workflows/go.yaml - pkg/** - go.* - - Makefile jobs: lint: runs-on: ubuntu-latest + timeout-minutes: 10 steps: - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 + - uses: int128/go-actions/setup@v1 with: go-version: 1.16 - uses: golangci/golangci-lint-action@v2 with: version: v1.38.0 + skip-go-installation: true + skip-pkg-cache: true + skip-build-cache: true test: runs-on: ubuntu-latest + timeout-minutes: 10 steps: - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 + - uses: int128/go-actions/setup@v1 with: go-version: 1.16 - - uses: actions/cache@v2 - with: - path: ~/go/pkg/mod - key: go-linux-amd64-${{ hashFiles('**/go.sum') }} - restore-keys: | - go-linux-amd64- - - run: go test -v -race -cover -coverprofile=coverage.out ./... - - uses: codecov/codecov-action@v2 - - test-platform-dependent: - strategy: - matrix: - platform: - - os: windows-latest - GOOS: windows - GOARCH: amd64 - - os: macos-latest - GOOS: darwin - GOARCH: amd64 - runs-on: ${{ matrix.platform.os }} - env: - GOOS: ${{ matrix.platform.GOOS }} - GOARCH: ${{ matrix.platform.GOARCH }} - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 - with: - go-version: 1.16 - - uses: actions/cache@v2 - with: - path: ~/go/pkg/mod - key: go-${{ matrix.platform.GOOS }}-${{ matrix.platform.GOARCH }}-${{ hashFiles('**/go.sum') }} - restore-keys: | - go-${{ matrix.platform.GOOS }}-${{ matrix.platform.GOARCH }}- - - run: go test -race ./... - - release: - strategy: - matrix: - platform: - - os: ubuntu-latest - GOOS: linux - GOARCH: amd64 - CGO_ENABLED: 0 # https://github.com/int128/kubelogin/issues/567 - - os: ubuntu-latest - GOOS: linux - GOARCH: arm64 - - os: ubuntu-latest - GOOS: linux - GOARCH: arm - - os: macos-latest - GOOS: darwin - GOARCH: amd64 - CGO_ENABLED: 1 # https://github.com/int128/kubelogin/issues/249 - - os: macos-latest - GOOS: darwin - GOARCH: arm64 - - os: windows-latest - GOOS: windows - GOARCH: amd64 - runs-on: ${{ matrix.platform.os }} - env: - GOOS: ${{ matrix.platform.GOOS }} - GOARCH: ${{ matrix.platform.GOARCH }} - CGO_ENABLED: ${{ matrix.platform.CGO_ENABLED }} - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 - with: - go-version: 1.16 - - uses: actions/cache@v2 - with: - path: ~/go/pkg/mod - key: go-${{ matrix.platform.GOOS }}-${{ matrix.platform.GOARCH }}-${{ hashFiles('**/go.sum') }} - restore-keys: | - go-${{ matrix.platform.GOOS }}-${{ matrix.platform.GOARCH }}- - - run: make dist - - run: make dist-release - if: startswith(github.ref, 'refs/tags/') - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - publish: - if: startswith(github.ref, 'refs/tags/') - needs: - - release - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: rajatjindal/krew-release-bot@v0.0.40 + - run: go test -v -race ./... diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..0317c6c --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,70 @@ +name: release + +on: + push: + branches: + - master + paths: + - .github/workflows/release.yaml + - pkg/** + - go.* + tags: + - v* + pull_request: + branches: + - master + paths: + - .github/workflows/release.yaml + - pkg/** + - go.* + +jobs: + build: + strategy: + matrix: + platform: + - runs-on: ubuntu-latest + GOOS: linux + GOARCH: amd64 + CGO_ENABLED: 0 # https://github.com/int128/kubelogin/issues/567 + - runs-on: ubuntu-latest + GOOS: linux + GOARCH: arm64 + - runs-on: ubuntu-latest + GOOS: linux + GOARCH: arm + - runs-on: macos-latest + GOOS: darwin + GOARCH: amd64 + CGO_ENABLED: 1 # https://github.com/int128/kubelogin/issues/249 + - runs-on: macos-latest + GOOS: darwin + GOARCH: arm64 + - runs-on: windows-latest + GOOS: windows + GOARCH: amd64 + runs-on: ${{ matrix.platform.runs-on }} + env: + GOOS: ${{ matrix.platform.GOOS }} + GOARCH: ${{ matrix.platform.GOARCH }} + CGO_ENABLED: ${{ matrix.platform.CGO_ENABLED }} + timeout-minutes: 10 + steps: + - uses: actions/checkout@v2 + - uses: int128/go-actions/setup@v1 + with: + go-version: 1.16 + - run: go build -ldflags "-X main.version=${GITHUB_REF##*/}" + - uses: int128/go-actions/release@v1 + with: + binary: kubelogin + + publish: + if: startswith(github.ref, 'refs/tags/') + needs: + - build + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v2 + - uses: rajatjindal/krew-release-bot@v0.0.40 diff --git a/Dockerfile b/Dockerfile index 32544c0..c5c8fcf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,10 +3,9 @@ FROM golang:1.17 as builder WORKDIR /builder COPY go.* . RUN go mod download -COPY Makefile . COPY main.go . COPY pkg pkg -RUN make +RUN go build FROM gcr.io/distroless/base-debian10 COPY --from=builder /builder/kubelogin / diff --git a/Makefile b/Makefile deleted file mode 100644 index 847c22e..0000000 --- a/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -PRODUCT := kubelogin -TARGET_ARCHIVE := $(PRODUCT)_$(GOOS)_$(GOARCH).zip -TARGET_DIGEST := $(PRODUCT)_$(GOOS)_$(GOARCH).zip.sha256 - -ifeq ($(GOOS), windows) - TARGET := $(PRODUCT).exe -else - TARGET := $(PRODUCT) -endif - -# determine the version from ref -ifeq ($(GITHUB_REF), refs/heads/master) - VERSION := latest -else - VERSION ?= $(notdir $(GITHUB_REF)) -endif - -LDFLAGS := -X main.version=$(VERSION) - -all: $(TARGET) - -$(TARGET): - go build -o $@ -ldflags "$(LDFLAGS)" - -.PHONY: dist -dist: $(TARGET_ARCHIVE) $(TARGET_DIGEST) -$(TARGET_ARCHIVE): $(TARGET) -ifeq ($(GOOS), windows) - powershell Compress-Archive -Path $(TARGET),LICENSE,README.md -DestinationPath $@ -else - zip $@ $(TARGET) LICENSE README.md -endif - -$(TARGET_DIGEST): $(TARGET_ARCHIVE) -ifeq ($(GOOS), darwin) - shasum -a 256 -b $(TARGET_ARCHIVE) > $@ -else - sha256sum -b $(TARGET_ARCHIVE) > $@ -endif - -.PHONY: dist-release -dist-release: dist - gh release upload $(VERSION) $(TARGET_ARCHIVE) $(TARGET_DIGEST) --clobber - -.PHONY: clean -clean: - -rm $(TARGET) - -rm -r dist/output/ - -rm coverage.out gotest.log