diff --git a/.github/actions/helm-gh-pages/Dockerfile b/.github/actions/helm-gh-pages/Dockerfile new file mode 100644 index 0000000..a1157a3 --- /dev/null +++ b/.github/actions/helm-gh-pages/Dockerfile @@ -0,0 +1,8 @@ +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 new file mode 100644 index 0000000..fde5172 --- /dev/null +++ b/.github/actions/helm-gh-pages/action.yml @@ -0,0 +1,35 @@ +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 }} \ No newline at end of file diff --git a/.github/actions/helm-gh-pages/entrypoint.sh b/.github/actions/helm-gh-pages/entrypoint.sh new file mode 100644 index 0000000..492f8d8 --- /dev/null +++ b/.github/actions/helm-gh-pages/entrypoint.sh @@ -0,0 +1,87 @@ +#!/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 \ No newline at end of file diff --git a/.github/actions/helm/entrypoint.sh b/.github/actions/helm/entrypoint.sh index 22de5ba..8b218a8 100644 --- a/.github/actions/helm/entrypoint.sh +++ b/.github/actions/helm/entrypoint.sh @@ -1,14 +1,15 @@ #!/usr/bin/env bash set -o errexit -set -o nounset set -o pipefail HELM_VERSION=3.2.1 -BIN_DIR=/home/runner/bin +BIN_DIR="$GITHUB_WORKSPACE/bin" main() { mkdir -p ${BIN_DIR} + cp /helm-publish.sh ${BIN_DIR}/helm-publish + tmpDir=$(mktemp -d) pushd $tmpDir >& /dev/null @@ -20,4 +21,6 @@ main() { rm -rf $tmpDir } -main \ No newline at end of file +main +echo "::add-path::$BIN_DIR" +echo "::add-path::$RUNNER_WORKSPACE/$(basename $GITHUB_REPOSITORY)/bin" diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index b7a46be..7786bfc 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -12,6 +12,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 + - name: Publish Helm charts + uses: ./.github/actions/helm-gh-pages + with: + token: ${{ secrets.GITHUB_TOKEN }} - name: Restore Go cache uses: actions/cache@v1 with: @@ -27,7 +31,12 @@ jobs: uses: ./.github/actions/helm - name: Setup Kubernetes uses: engineerd/setup-kind@v0.4.0 - - name: Test + - name: Debug + run: | + which kubectl + ls -la $HOME + ls -la $GITHUB_WORKSPACE + - name: Run unit tests run: make test - name: Check if working tree is dirty run: | @@ -35,7 +44,7 @@ jobs: echo 'run make test and commit changes' exit 1 fi - - name: Build + - name: Build container image run: | GIT_COMMIT=$(git rev-list -1 HEAD) && \ docker build -t test/podinfo:latest --build-arg "REVISION=${GIT_COMMIT}" . @@ -46,10 +55,10 @@ jobs: --set image.repository=test/podinfo \ --set image.tag=latest \ --namespace=default - - name: Integration test + - name: Run integration tests run: | kubectl rollout status deployment/podinfo --timeout=1m - helm test podinfo --logs + helm test podinfo - name: Debug failure if: failure() run: |