Skip to content

Commit

Permalink
ci: introduce pre-release and release flows
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Chila <[email protected]>
  • Loading branch information
pchila committed Jan 21, 2022
1 parent bbf7a59 commit 9063430
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ jobs:
id: docker_build
uses: keptn/gh-automation/.github/actions/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAGS: |
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE }}:${{ env.VERSION }}
BUILD_ARGS: |
Expand Down
68 changes: 68 additions & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]

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/[email protected]

- 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/[email protected]
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/[email protected]

- 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
69 changes: 69 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]

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/[email protected]

- 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/[email protected]
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/[email protected]

- 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
53 changes: 53 additions & 0 deletions gh-actions-scripts/build_helm_chart.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 9063430

Please sign in to comment.