diff --git a/.github/workflows/publish-chart.yml b/.github/workflows/publish-chart.yml new file mode 100644 index 0000000000000..a0f6ab940ae41 --- /dev/null +++ b/.github/workflows/publish-chart.yml @@ -0,0 +1,59 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +--- + +name: Publish Chart +on: + push: + branches: ['helm-chart/v[0-9]+-[0-9]+-[0-9]'] +jobs: + publish-chart: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + persist-credentials: false + + - name: Install Helm + uses: azure/setup-helm@v1 + with: + version: v3.5.3 + + - name: "Build Chart" + run: ./scripts/ci/astronomer-airflow-chart-release.sh + id: build-chart + + - name: Publish Chart + uses: ncipollo/release-action@v1 + with: + allowUpdates: true + prerelease: true + artifacts: "chart-rel/index.yaml,chart-rel/*.tgz" + body: | + Add the repo as follows: + ```shell + helm repo add apache-airflow-oss ${{steps.build-chart.outputs.chart_repo}} + ``` + + Install the chart: + ```shell + helm install airflow apache-airflow-oss/airflow --version ${{steps.build-chart.outputs.chart_version}} + ``` + tag: ${{steps.build-chart.outputs.chart_gh_release_tag}} + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/scripts/ci/astronomer-airflow-chart-release.sh b/scripts/ci/astronomer-airflow-chart-release.sh new file mode 100755 index 0000000000000..65271ccedc88d --- /dev/null +++ b/scripts/ci/astronomer-airflow-chart-release.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +# This file is Not licensed to ASF +# SKIP LICENSE INSERTION + +ROOT_DIRECTORY=$(pwd) +CHART_DIRECTORY=${ROOT_DIRECTORY}/chart +CHART_RELEASE_DIRECTORY=${ROOT_DIRECTORY}/chart-rel +export ROOT_DIRECTORY CHART_DIRECTORY CHART_RELEASE_DIRECTORY + +if [[ ! -d "$CHART_DIRECTORY" ]]; then + echo "chart directory does not exists ..." + echo + echo "Current Working Directory: " + echo + ls -ltr +fi + +CHART_VERSION="$(awk '$1 ~ /^version/ {printf $2;exit;}' "$CHART_DIRECTORY"/Chart.yaml)" +export CHART_VERSION +export CHART_GH_RELEASE_TAG="oss-helm-chart/$CHART_VERSION" +export CHART_PUBLISH_REPO="https://github.com/astronomer/airflow/releases/download/${CHART_GH_RELEASE_TAG}" + +# shellcheck disable=SC2153 +export TAG=${GITHUB_REF/refs\/tags\//} +if [[ "$GITHUB_REF" != *"tags"* ]]; then + export TAG="" +fi +echo "TAG: $TAG" +# shellcheck disable=SC2153 +export BRANCH=${GITHUB_REF#refs/*/} +echo "BRANCH: $BRANCH" + + +function package_chart() { + echo "Packaging chart ..." + helm package "$CHART_DIRECTORY" --destination "$CHART_RELEASE_DIRECTORY" +} + +function merge_index_yaml() { + echo "Merging index.yaml ..." + curl https://airflow.apache.org/index.yaml --output index.yaml --silent + helm repo index --merge ./index.yaml "${CHART_RELEASE_DIRECTORY}" --url "${CHART_PUBLISH_REPO}" +} + +# If the build is not a tag/release, build a dev version +if [[ -z ${TAG:=} ]]; then + echo + echo "Current Chart Version is: ${CHART_VERSION}" + echo + package_chart && merge_index_yaml +elif [[ ${TAG:=} == "${BRANCH:=}" ]]; then + echo + # TODO: Release the chart +fi + +echo "::set-output name=chart_version::${CHART_VERSION}" +echo "::set-output name=chart_gh_release_tag::${CHART_GH_RELEASE_TAG}" +echo "::set-output name=chart_repo::${CHART_PUBLISH_REPO}" + + +ls -altr "${CHART_RELEASE_DIRECTORY}/"