From 1020102bf2fa59408e1af4f29c9e8e3af9fda1d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Nussbaumer?= Date: Tue, 23 Nov 2021 14:33:31 +0100 Subject: [PATCH] build: improve GH actions and move cmd/ folder --- .github/workflows/build.yaml | 3 +- .github/workflows/publish.yaml | 66 +++++++++++++++++-- .../main.go | 0 3 files changed, 64 insertions(+), 5 deletions(-) rename cmd/{approverd => kubelet-csr-approver}/main.go (100%) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index e710c95..5bdedd0 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -14,7 +14,8 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-go@v2 with: - go-version: 1.17.x + go-version: 1.17 + stable: true - run: | go build ./... diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index b93032a..3fdbc8c 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -1,17 +1,74 @@ -name: ko publish +name: Test and publish on: push: branches: ['main'] jobs: - publish: + test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-go@v2 with: - go-version: 1.17.x + go-version: 1.17 + stable: true + + - run: | + go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest + mkdir -p local/envtest-bin/ + setup-envtest use -p env 1.21.x --bin-dir local/envtest-bin > local/envtest-bin/env + - name: Run Unit tests + run: | + source local/envtest-bin/env + export KUBEBUILDER_ASSETS=$(pwd)/$KUBEBUILDER_ASSETS + go test -race -covermode atomic -coverprofile=profile.cov ./... + + - name: Send coverage + env: + COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + go install github.com/mattn/goveralls + goveralls -coverprofile=profile.cov -service=github + + + release-tagged: + if: "startsWith(github.ref, 'refs/tags/v')" + needs: + # - lint + - test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: 1.17 + stable: true + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: postfinance + password: ${{ secrets.DOCKER_TOKEN }} + - uses: imjasonh/setup-ko@v0.4 + env: + KO_DOCKER_REPO: docker.io/postfinance + - run: | + tag=$(echo ${{ github.ref }} | cut -d "/" -f 3 - ) + ko publish cmd/kubelet-csr-approver/main.go --base-import-paths --tags $tag + + release-untagged: + if: "!startsWith(github.ref, 'refs/tags/v')" + needs: + # - lint + - test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: 1.17 + stable: true - name: Login to DockerHub uses: docker/login-action@v1 @@ -21,4 +78,5 @@ jobs: - uses: imjasonh/setup-ko@v0.4 env: KO_DOCKER_REPO: docker.io/postfinance - - run: ko publish cmd/approverd/main.go \ No newline at end of file + - run: | + ko publish cmd/kubelet-csr-approver/main.go --base-import-paths \ No newline at end of file diff --git a/cmd/approverd/main.go b/cmd/kubelet-csr-approver/main.go similarity index 100% rename from cmd/approverd/main.go rename to cmd/kubelet-csr-approver/main.go