Skip to content

Commit

Permalink
Merge pull request #50 from gabeduke/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
gabeduke authored Aug 3, 2020
2 parents bb5597d + 9ff7be2 commit 689ab1e
Show file tree
Hide file tree
Showing 12 changed files with 194 additions and 77 deletions.
2 changes: 0 additions & 2 deletions .github/actions/golang/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
FROM golang:1.13

RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.17.1

RUN apt-get update && \
apt-get install -y jq

Expand Down
23 changes: 0 additions & 23 deletions .github/actions/golang/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,6 @@ $(format_code "${DIFF}" diff)
exit $SUCCESS
}

go_lint () {
echo "Running go lint"
go get ./...

set +e
golangci-lint run --out-format tab > lint-results.txt
SUCCESS=$?
set -e

if [ $SUCCESS != 0 ]; then
FAILED=$(cat lint-results.txt)
FAILED=$(format_code "${FAILED}" less)
echo "${FAILED}"
post "Go Lint" "${FAILED}"
exit $SUCCESS
fi

exit $SUCCESS
}

go_test() {
echo "Running go test"

Expand Down Expand Up @@ -142,9 +122,6 @@ case "$1" in
'fmt')
go_fmt
;;
'lint')
go_lint
;;
'test')
go_test
;;
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/bumpver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- master
- main
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -11,7 +12,8 @@ jobs:
with:
fetch-depth: '0'
- name: Bump version and push tag
uses: anothrNick/github-tag-action@1.13.0
uses: anothrNick/github-tag-action@1.22.0
env:
GITHUB_TOKEN: ${{ secrets.USER_GITHUB_TOKEN }}
WITH_V: false
WITH_V: true
RELEASE_BRANCHES: "master,main"
17 changes: 0 additions & 17 deletions .github/workflows/fmt.yml

This file was deleted.

40 changes: 22 additions & 18 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@ on:
tags: ["*"]
name: Release
jobs:
release:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set output
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- name: generate-release-changelog
uses: docker://ferrarimarco/github-changelog-generator:1.15.0.pre.beta
env:
CHANGELOG_GITHUB_TOKEN: ${{ secrets.CHANGELOG_GITHUB_TOKEN }}
SRC_PATH: /github/workspace
with:
args: -u gabeduke -p kubectl-iexec --release-branch develop --future-release ${{ steps.vars.outputs.tag }}
- name: goreleaser
uses: docker://goreleaser/goreleaser
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update new version in krew-index
uses: rajatjindal/krew-release-bot@v0.0.36
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.14
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
name: Update new version in krew-index
uses: rajatjindal/krew-release-bot@v0.0.36
50 changes: 37 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,46 @@
name: Test

on:
push:
branches: [ develop ]
pull_request:
branches:
- master
- develop
push:
branches:
- master
- main

name: Test
jobs:
test:

build:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: test
uses: ./.github/actions/golang
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}} #required
with:
args: test

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Build
run: go build -v .

- name: Fmt
run: |
./hack/fmt.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Test
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}} #required
run: |
./hack/test.sh
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ archives:
windows: Windows
386: i386
amd64: x86_64
name_template: "{{ .ProjectName }}_{{ .Tag }}_{{ .Os }}_{{ .Arch }}"
checksum:
name_template: 'checksums.txt'
snapshot:
Expand Down
2 changes: 1 addition & 1 deletion .krew.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Plugin
metadata:
name: iexec
spec:
version: v{{ .TagName }}
version: {{ .TagName }}
homepage: https://github.com/gabeduke/kubectl-iexec
platforms:
- selector:
Expand Down
6 changes: 6 additions & 0 deletions hack/fmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

. $(dirname "$0")/fn.sh

go_fmt

116 changes: 116 additions & 0 deletions hack/fn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/usr/bin/env bash

set -ef pipefail
set -x

go_fmt () {
echo "Running go fmt"

# Use an eval to avoid glob expansion
FIND_EXEC="find . -type f -iname '*.go'"

# Get a list of files that we are interested in
CHECK_FILES=$(eval "${FIND_EXEC}")

set +e
test -z "$(gofmt -l -d -e "${CHECK_FILES}")"
SUCCESS=$?
set -e

# Exit if `go fmt` passes.
if [ $SUCCESS -eq 0 ]; then
exit 0
fi


# Get list of unformatted files.
set +e
ISSUE_FILES=$(gofmt -l "${CHECK_FILES}")
echo "${ISSUE_FILES}"
set -e

# Iterate through each unformatted file.
OUTPUT=""
for FILE in $ISSUE_FILES; do
DIFF=$(gofmt -d -e "${FILE}")
OUTPUT="$OUTPUT
\`${FILE}\`
$(format_code "${DIFF}" diff)
"
done

echo "${OUTPUT}"
post "go fmt" "${OUTPUT}"

exit $SUCCESS
}

go_test() {
echo "Running go test"

# short mode for printing results to PR
set +e
go test ./... -v -short -race | grep FAIL > test-results.txt
SUCCESS=${PIPESTATUS[0]}
set -e

if [ "$SUCCESS" != 0 ]; then
FAILED=$(cat test-results.txt)
FAILED=$(format_code "${FAILED}" less)
post "Go Test" "${FAILED}"
exit "$SUCCESS"
fi

# verbose for upload to codecov
set +e
go test ./... -race -coverprofile=coverage.txt -covermode=atomic
SUCCESS=$?
set -e

if [ $SUCCESS != 0 ]; then
exit $SUCCESS
fi

set +x
if [ -z "$CODECOV_TOKEN" ]
then
echo "No Codecov token provided. Skipping.."
exit $SUCCESS
else
curl -s https://codecov.io/bash | bash -s -- -t "$CODECOV_TOKEN" -f ./coverage.txt
exit $SUCCESS
fi
set -x

}

format_code() {
local CODE="${1}"
local SYNTAX="${2}"
CODE="
\`\`\`${SYNTAX}
${CODE}
\`\`\`
"
echo "${CODE}"
}

post() {

STEP="${1}"
FAILED="${2}"

# Post results back as comment.
COMMENT="#### \`${STEP}\`
${FAILED}
"
PAYLOAD=$(echo '{}' | jq --arg body "$COMMENT" '.body = $body')
COMMENTS_URL=$(cat < /github/workflow/event.json | jq -r .pull_request.comments_url)

if [ "COMMENTS_URL" != null ]; then
set +e
curl -s -S -H "Authorization: token $GITHUB_TOKEN" --header "Content-Type: application/json" --data "$PAYLOAD" "$COMMENTS_URL" > /dev/null
set -e
fi
}

6 changes: 6 additions & 0 deletions hack/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

. $(dirname "$0")/fn.sh

go_test

2 changes: 1 addition & 1 deletion pkg/iexec/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// get all pods from kubernetes API
func getAllPods(client kubernetes.Interface, namespace string) (*corev1.PodList, error) {
pods, err := client.CoreV1().Pods(namespace).List(context.TODO(), metav1.ListOptions{})
pods, err := client.CoreV1().Pods(namespace).List(context.TODO(), metav1.ListOptions{FieldSelector: "status.phase=Running"})
if err != nil {
return pods, err
}
Expand Down

0 comments on commit 689ab1e

Please sign in to comment.