From 369014455cb7fc20ea0c0b0b0d7a1a214e9c5531 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Thu, 28 May 2020 10:13:45 +0300 Subject: [PATCH 1/2] Use helm-gh-pages action --- .github/actions/helm-gh-pages/Dockerfile | 8 -- .github/actions/helm-gh-pages/action.yml | 35 --------- .github/actions/helm-gh-pages/entrypoint.sh | 87 --------------------- .github/actions/helm/action.yml | 2 +- .github/workflows/release.yml | 2 +- 5 files changed, 2 insertions(+), 132 deletions(-) delete mode 100644 .github/actions/helm-gh-pages/Dockerfile delete mode 100644 .github/actions/helm-gh-pages/action.yml delete mode 100644 .github/actions/helm-gh-pages/entrypoint.sh diff --git a/.github/actions/helm-gh-pages/Dockerfile b/.github/actions/helm-gh-pages/Dockerfile deleted file mode 100644 index a1157a3..0000000 --- a/.github/actions/helm-gh-pages/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM stefanprodan/alpine-base:latest - -COPY entrypoint.sh /entrypoint.sh -RUN chmod +x /entrypoint.sh - -RUN apk --no-cache add git - -ENTRYPOINT ["/entrypoint.sh"] diff --git a/.github/actions/helm-gh-pages/action.yml b/.github/actions/helm-gh-pages/action.yml deleted file mode 100644 index 38718a1..0000000 --- a/.github/actions/helm-gh-pages/action.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: 'helm-gh-pages' -description: 'A GitHub Action to publish helm charts to Github Pages' -author: 'Stefan Prodan' -branding: - icon: 'command' - color: 'blue' -inputs: - token: - description: "GitHub token" - required: true - charts_dir: - description: "The charts directory, defaults to `charts`" - required: false - charts_url: - description: "The GitHub Pages URL, default to `https://.github.io/`" - required: false - user: - description: "The GitHub user that owns this repository" - required: false - repository: - description: "The GitHub repository name" - required: false - branch: - description: "The branch to publish charts, default to `gh-pages`" - required: false -runs: - using: 'docker' - image: 'Dockerfile' - args: - - ${{ inputs.token }} - - ${{ inputs.charts_dir }} - - ${{ inputs.charts_url }} - - ${{ inputs.user }} - - ${{ inputs.repository }} - - ${{ inputs.branch }} diff --git a/.github/actions/helm-gh-pages/entrypoint.sh b/.github/actions/helm-gh-pages/entrypoint.sh deleted file mode 100644 index 34c701e..0000000 --- a/.github/actions/helm-gh-pages/entrypoint.sh +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -set -o pipefail - -GITHUB_TOKEN=$1 -CHARTS_DIR=$2 -CHARTS_URL=$3 -USER=$4 -REPOSITORY=$5 -BRANCH=$6 - -HELM_VERSION=3.2.1 -CHARTS_TMP_DIR=$(mktemp -d) -REPO_ROOT=$(git rev-parse --show-toplevel) - -main() { - if [[ -z "$CHARTS_DIR" ]]; then - CHARTS_DIR="charts" - fi - - if [[ -z "$USER" ]]; then - USER=$(cut -d '/' -f 1 <<< "$GITHUB_REPOSITORY") - fi - - if [[ -z "$REPOSITORY" ]]; then - REPOSITORY=$(cut -d '/' -f 2 <<< "$GITHUB_REPOSITORY") - fi - - if [[ -z "$BRANCH" ]]; then - BRANCH="gh-pages" - fi - - if [[ -z "$CHARTS_URL" ]]; then - CHARTS_URL="https://${USER}.github.io/${REPOSITORY}" - fi - - download - lint - package - upload -} - -download() { - tmpDir=$(mktemp -d) - - pushd $tmpDir >& /dev/null - - curl -sSL https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz | tar xz - cp linux-amd64/helm /usr/local/bin/helm - - popd >& /dev/null - rm -rf $tmpDir -} - -lint() { - helm lint ${REPO_ROOT}/${CHARTS_DIR}/* -} - -package() { - helm package ${REPO_ROOT}/${CHARTS_DIR}/* --destination ${CHARTS_TMP_DIR} -} - -upload() { - tmpDir=$(mktemp -d) - pushd $tmpDir >& /dev/null - - repo_url="https://x-access-token:${GITHUB_TOKEN}@github.com/${USER}/${REPOSITORY}" - git clone ${repo_url} - cd ${REPOSITORY} - git config user.name "$GITHUB_ACTOR" - git config user.email "$GITHUB_ACTOR@users.noreply.github.com" - git remote set-url origin ${repo_url} - git checkout gh-pages - - mv -f ${CHARTS_TMP_DIR}/*.tgz . - helm repo index . --url ${CHARTS_URL} - - git add . - git commit -m "Publish Helm charts" - git push origin gh-pages - - popd >& /dev/null - rm -rf $tmpDir -} - -main diff --git a/.github/actions/helm/action.yml b/.github/actions/helm/action.yml index d500727..feccd4d 100644 --- a/.github/actions/helm/action.yml +++ b/.github/actions/helm/action.yml @@ -12,4 +12,4 @@ runs: using: 'docker' image: 'Dockerfile' args: - - ${{ inputs.helm-version }} \ No newline at end of file + - ${{ inputs.helm-version }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a75e0c8..c2172d8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,7 +29,7 @@ jobs: repository: stefanprodan/podinfo-base tags: latest - name: Publish helm chart - uses: ./.github/actions/helm-gh-pages + uses: stefanprodan/helm-gh-pages@master with: token: ${{ secrets.GITHUB_TOKEN }} - uses: ./.github/actions/release-notes From d2798e1a24af0d13864e2f000a893352a3eb9d39 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Thu, 28 May 2020 10:21:50 +0300 Subject: [PATCH 2/2] Consolidate tests --- .github/workflows/e2e.yml | 21 +------------------ .github/workflows/lint.yml | 28 ------------------------- .github/workflows/test.yml | 43 ++++++++++++++++++++++++++++++++++++++ README.md | 1 + 4 files changed, 45 insertions(+), 48 deletions(-) delete mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 9a7782d..a3cbe6a 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -7,7 +7,7 @@ on: - 'master' jobs: - kind: + kind-helm: strategy: matrix: helm-version: @@ -17,27 +17,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - - name: Restore Go cache - uses: actions/cache@v1 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - name: Setup Go - uses: actions/setup-go@v2 - with: - go-version: 1.14.x - name: Setup Kubernetes uses: engineerd/setup-kind@v0.4.0 - - name: Run unit tests - run: make test - - name: Check if working tree is dirty - run: | - if [[ $(git diff --stat) != '' ]]; then - echo 'run make test and commit changes' - exit 1 - fi - name: Build container image run: | GIT_COMMIT=$(git rev-list -1 HEAD) && \ diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 670ac6e..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: lint - -on: - pull_request: - push: - branches: - - 'master' - -jobs: - validate: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: helm - uses: stefanprodan/kube-tools@v1 - with: - command: | - helmv3 template ./charts/podinfo | kubeval --strict - - name: kubeval - uses: stefanprodan/kube-tools@v1 - with: - command: | - kustomize build ./kustomize | kubeval --strict - - name: conftest - uses: stefanprodan/kube-tools@v1 - with: - command: | - kustomize build ./kustomize | conftest test -p .github/policy - diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..d6c090c --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,43 @@ +name: test + +on: + pull_request: + push: + branches: + - 'master' + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Restore Go cache + uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go- + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: 1.14.x + - name: Run unit tests + run: make test + - name: Check if working tree is dirty + run: | + if [[ $(git diff --stat) != '' ]]; then + echo 'run make test and commit changes' + exit 1 + fi + - name: Validate Helm chart + uses: stefanprodan/kube-tools@v1 + with: + command: | + helmv3 template ./charts/podinfo | kubeval --strict + - name: Validate kustomization + uses: stefanprodan/kube-tools@v1 + with: + command: | + kustomize build ./kustomize | kubeval --strict + kustomize build ./kustomize | conftest test -p .github/policy - diff --git a/README.md b/README.md index f2a5be1..0129145 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # podinfo [![e2e](https://github.com/stefanprodan/podinfo/workflows/e2e/badge.svg)](https://github.com/stefanprodan/podinfo/blob/master/.github/workflows/e2e.yml) +[![test](https://github.com/stefanprodan/podinfo/workflows/test/badge.svg)](https://github.com/stefanprodan/podinfo/blob/master/.github/workflows/test.yml) [![release](https://github.com/stefanprodan/podinfo/workflows/release/badge.svg)](https://github.com/stefanprodan/podinfo/blob/master/.github/workflows/release.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/stefanprodan/podinfo)](https://goreportcard.com/report/github.com/stefanprodan/podinfo) [![Docker Pulls](https://img.shields.io/docker/pulls/stefanprodan/podinfo)](https://hub.docker.com/r/stefanprodan/podinfo)