diff --git a/.github/workflows/promote.yaml b/.github/workflows/promote.yaml new file mode 100644 index 0000000000..c3bbd594d7 --- /dev/null +++ b/.github/workflows/promote.yaml @@ -0,0 +1,80 @@ +# Copyright 2026 Canonical Ltd. +# See LICENSE file for licensing details. +name: Release to candidate promotion train + +on: + workflow_dispatch: + inputs: + single-kernel-version: + description: "A pip package version of single kernel (eg: 1.8.42)" + required: true + type: string + +jobs: + trigger-release-ci: + # only on beta promotion + name: Trigger release CI (Airflow) + runs-on: ubuntu-latest + steps: + - name: Validate input + id: validate-input + shell: python + env: + PIP_VERSION: ${{ inputs.single-kernel-version }} + run: | + import re + import os + + pip_package_version = os.environ["PIP_VERSION"] + VERSION_REGEX = re.compile(r"\d.\d.\d+") + + if not VERSION_REGEX.match(pip_package_version): + raise ValueError(f"Invalid version received: {pip_package_version}") + - name: Check version exists + id: check-version + env: + PIP_VERSION: ${{ inputs.single-kernel-version }} + run: | + set -euo pipefail + DEP_NAME="mongo-charms-single-kernel" + URL="https://pypi.org/pypi/${DEP_NAME}/${PIP_VERSION}/json" + for i in {1..30}; do + if curl -fsS "$URL" >/dev/null; then + echo "Found ${DEP_NAME}==${VERSION_NUMBER} on PyPI." + exit 0 + fi + echo "Maybe transient error (attempt $i/30). Sleeping..." + sleep 60 + done + + echo "Timed out waiting for ${DEP_NAME}==${PIP_VERSION} on PyPI." + echo "Is the revision available on PyPI ?" + exit 1 + + - name: Trigger Airflow DAG + env: + PIP_VERSION: ${{ inputs.single-kernel-version }} + run: | + #shellcheck disable=SC2016 + response=$(curl -s -w "\n%{http_code}" -X POST \ + 'https://airflow.data-platform.ps7.canonical.com/api/v2/dags/mongodb_8/dagRuns' \ + -H 'Content-Type: application/json' \ + -H 'Authorization: Bearer ${{ secrets.AIRFLOW_API_TOKEN }}' \ + -d "{ + \"dag_run_id\": \"promote-${{ github.run_id }}\", + \"logical_date\": \"$(date -u +%Y-%m-%dT%H:%M:%SZ)\", + \"conf\": { + \"pip_version\": \"${PIP_VERSION}\" + } + }") + http_code=$(echo "$response" | tail -n1) + body=$(echo "$response" | sed '$d') + echo "$body" + if echo "$body" | grep -q '"detail":"Token Expired"'; then + echo "::error::Airflow API token has expired" + exit 1 + fi + if [ "$http_code" -lt 200 ] || [ "$http_code" -ge 300 ]; then + echo "::error::Airflow API request failed with status $http_code" + exit 1 + fi