diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index acc74dc..ea753f6 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -131,6 +131,7 @@ jobs: id: docker_build uses: keptn/gh-automation/.github/actions/docker-build@v1.3.0 with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} TAGS: | ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE }}:${{ env.VERSION }} BUILD_ARGS: | diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml new file mode 100644 index 0000000..799f061 --- /dev/null +++ b/.github/workflows/pre-release.yml @@ -0,0 +1,68 @@ +name: Create Pre-Release +on: + workflow_dispatch: +jobs: + test: + runs-on: ubuntu-20.04 + steps: + - name: Check out repository + uses: actions/checkout@v2 + - name: Unit tests + uses: ./.github/actions/unit-tests + + pre-release: + needs: test + name: Pre-Release + uses: keptn/gh-automation/.github/workflows/pre-release-integration.yml@v1.4.0 + + docker_build: + needs: [pre-release] + name: Docker Build + runs-on: ubuntu-20.04 + env: + VERSION: ${{ needs.pre-release.outputs.RELEASE_TAG }} + steps: + - name: Checkout Code + uses: actions/checkout@v2.4.0 + + - name: Load CI Environment from .ci_env + id: load_ci_env + uses: c-py/action-dotenv-to-setenv@v3 + with: + env-file: .ci_env + + - name: Docker Build + uses: keptn/gh-automation/.github/actions/docker-build@v1.4.0 + with: + TAGS: | + ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE }}:${{ env.VERSION }} + BUILD_ARGS: | + version=${{ env.VERSION }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + helm_chart_build: + needs: [pre-release, docker_build] + name: Build Helm Charts + runs-on: ubuntu-20.04 + env: + VERSION: ${{ needs.pre-release.outputs.RELEASE_TAG }} + steps: + - name: Checkout Code + uses: actions/checkout@v2.4.0 + + - name: Load CI Environment from .ci_env + id: load_ci_env + uses: c-py/action-dotenv-to-setenv@v3 + with: + env-file: .ci_env + + - name: Build Helm Charts + id: build_helm_charts + run: ./gh-actions-scripts/build_helm_chart.sh "${VERSION}" "${VERSION}" "${IMAGE}" + + - name: Upload Helm Chart as release asset + env: + RELEASE_TAG: ${{ needs.pre-release.outputs.RELEASE_TAG }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release upload "$RELEASE_TAG" installer/*.tgz diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e383b14 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,69 @@ +name: Create Release +on: + workflow_dispatch: +jobs: + test: + runs-on: ubuntu-20.04 + steps: + - name: Check out repository + uses: actions/checkout@v2 + - name: Unit tests + uses: ./.github/actions/unit-tests + + release: + needs: test + name: Release + uses: keptn/gh-automation/.github/workflows/release-integration.yml@v1.4.0 + + docker_build: + needs: [release] + name: Docker Build + runs-on: ubuntu-20.04 + env: + VERSION: ${{ needs.release.outputs.RELEASE_TAG }} + steps: + - name: Checkout Code + uses: actions/checkout@v2.4.0 + + - name: Load CI Environment from .ci_env + id: load_ci_env + uses: c-py/action-dotenv-to-setenv@v3 + with: + env-file: .ci_env + + - name: Docker Build + uses: keptn/gh-automation/.github/actions/docker-build@v1.4.0 + with: + TAGS: | + ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE }}:${{ env.VERSION }} + BUILD_ARGS: | + version=${{ env.VERSION }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + helm_chart_build: + needs: [release, docker_build] + + name: Build Helm Charts + runs-on: ubuntu-20.04 + env: + VERSION: ${{ needs.release.outputs.RELEASE_TAG }} + steps: + - name: Checkout Code + uses: actions/checkout@v2.4.0 + + - name: Load CI Environment from .ci_env + id: load_ci_env + uses: c-py/action-dotenv-to-setenv@v3 + with: + env-file: .ci_env + + - name: Build Helm Charts + id: build_helm_charts + run: ./gh-actions-scripts/build_helm_chart.sh "${VERSION}" "${VERSION}" "${IMAGE}" + + - name: Upload Helm Chart as release asset + env: + RELEASE_TAG: ${{ needs.release.outputs.RELEASE_TAG }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release upload "$RELEASE_TAG" installer/*.tgz diff --git a/gh-actions-scripts/build_helm_chart.sh b/gh-actions-scripts/build_helm_chart.sh new file mode 100755 index 0000000..438cf4e --- /dev/null +++ b/gh-actions-scripts/build_helm_chart.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# shellcheck disable=SC2181 + +VERSION=$1 # e.g., 0.7.2-next.0 +APP_VERSION=$2 # e.g., 0.7.2-next.0+1234 +IMAGE=$3 # e.g., prometheus-service + +if [ $# -ne 3 ]; then + echo "Usage: $0 VERSION APP_VERSION IMAGE" + exit +fi + +if [ -z "$VERSION" ]; then + echo "No Version set, exiting..." + exit 1 +fi + +if [ -z "$APP_VERSION" ]; then + echo "No Image Tag set, defaulting to version" + APP_VERSION=$VERSION +fi + + +# replace "appVersion: latest" with "appVersion: $VERSION" in all Chart.yaml files +# find . -name Chart.yaml -exec sed -i -- "s/appVersion: latest/appVersion: ${APP_VERSION}/g" {} \; +# find . -name Chart.yaml -exec sed -i -- "s/version: latest/version: ${VERSION}/g" {} \; + +mkdir installer/ + +# #################### +# HELM CHART +# #################### +BASE_PATH=. +CHARTS_PATH=chart + +helm package ${BASE_PATH}/${CHARTS_PATH} --app-version "$APP_VERSION" --version "$VERSION" +if [ $? -ne 0 ]; then + echo "Error packaging installer, exiting..." + exit 1 +fi + +mv "${IMAGE}-${VERSION}.tgz" "installer/${IMAGE}-${VERSION}.tgz" + +#verify the chart +helm template "installer/${IMAGE}-${VERSION}.tgz" --dry-run > /dev/null + +if [ $? -ne 0 ]; then + echo "::error Helm Chart for ${IMAGE} has templating errors -exiting" + exit 1 +fi + +echo "Generated files:" +echo " - installer/${IMAGE}-${VERSION}.tgz"