Init action

This commit is contained in:
stefanprodan 2020-05-28 09:24:03 +03:00
parent 2cfe06dc96
commit 16cfdebcde
3 changed files with 144 additions and 0 deletions

8
Dockerfile Normal file
View file

@ -0,0 +1,8 @@
FROM stefanprodan/alpine-base:latest
RUN apk --no-cache add git
COPY src/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

39
action.yml Normal file
View file

@ -0,0 +1,39 @@
name: 'helm-gh-pages'
description: 'A GitHub Action for publishing Helm charts with 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, defaults to `https://<USER>.github.io/<REPOSITORY>`"
required: false
owner:
description: "The GitHub user or org that owns this repository, defaults to GITHUB_REPOSITORY"
required: false
repository:
description: "The GitHub repository name, defaults to GITHUB_REPOSITORY"
required: false
branch:
description: "The branch to publish charts, defaults to `gh-pages`"
required: false
helm_version:
description: "The Helm CLI version"
required: false
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.token }}
- ${{ inputs.charts_dir }}
- ${{ inputs.charts_url }}
- ${{ inputs.user }}
- ${{ inputs.repository }}
- ${{ inputs.branch }}
- ${{ inputs.helm_version }}

97
src/entrypoint.sh Normal file
View file

@ -0,0 +1,97 @@
#!/usr/bin/env bash
set -o errexit
set -o pipefail
GITHUB_TOKEN=$1
CHARTS_DIR=$2
CHARTS_URL=$3
OWNER=$4
REPOSITORY=$5
BRANCH=$6
HELM_VERSION=$7
CHARTS_TMP_DIR=$(mktemp -d)
REPO_ROOT=$(git rev-parse --show-toplevel)
REPO_URL=""
main() {
if [[ -z "$HELM_VERSION" ]]; then
HELM_VERSION="3.2.1"
fi
if [[ -z "$CHARTS_DIR" ]]; then
CHARTS_DIR="charts"
fi
if [[ -z "$OWNER" ]]; then
OWNER=$(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://${OWNER}.github.io/${REPOSITORY}"
fi
if [[ -z "$REPO_URL" ]]; then
REPO_URL="https://x-access-token:${GITHUB_TOKEN}@github.com/${OWNER}/${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
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
charts=$(cd ${CHARTS_TMP_DIR} && ls *.tgz | xarg)
mv -f ${CHARTS_TMP_DIR}/*.tgz .
helm repo index . --url ${CHARTS_URL}
git add .
git commit -m "Publish $charts"
git push origin gh-pages
popd >& /dev/null
rm -rf $tmpDir
}
main