From b8bb0c8a7b85f5d237748fe797dc9851aeadf304 Mon Sep 17 00:00:00 2001 From: ChristoGrab Date: Tue, 19 Nov 2024 09:05:11 -0800 Subject: [PATCH] fix: account for dynamic CDK version --- .github/workflows/cdk-publish.yml | 59 ++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/.github/workflows/cdk-publish.yml b/.github/workflows/cdk-publish.yml index 2e5ab8e2..450605f6 100644 --- a/.github/workflows/cdk-publish.yml +++ b/.github/workflows/cdk-publish.yml @@ -1,8 +1,11 @@ name: Publish CDK and Source Declarative Manifest on: push: + branches: + - main paths: - - 'airbyte_cdk/pyproject.toml' # To only publish on CDK version change + - 'airbyte_cdk/**' # Check for any changes in the CDK directory + - '!airbyte_cdk/test/**' # Ignore changes in test CDK test directory - 'Dockerfile' workflow_dispatch: @@ -38,7 +41,7 @@ jobs: continue-on-error: true # Prevent security scan from failing the build with: image-ref: airbyte/source-declarative-manifest:build-test - format: 'table,sarif' + format: 'sarif' output: 'trivy-results.sarif' exit-code: 1 severity: 'CRITICAL,HIGH' @@ -52,6 +55,10 @@ jobs: permissions: id-token: write # Required for trusted publishing contents: write # Required for artifact uploads + env: + POETRY_NO_INTERACTION: 1 + POETRY_VIRTUALENVS_CREATE: false + POETRY_VIRTUALENVS_IN_PROJECT: false steps: - uses: actions/checkout@v4 with: @@ -69,14 +76,50 @@ jobs: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_PASSWORD }} + - name: Set up Python environment + run: | + python -m venv .venv + source .venv/bin/activate + pip install --upgrade pip + pip install poetry==1.6.1 + poetry config virtualenvs.create false + - name: Get CDK version run: | + export PATH="/home/runner/.local/bin:$PATH" + source .venv/bin/activate + poetry self add "poetry-dynamic-versioning[plugin]" # Get the current CDK version + poetry dynamic-versioning cdk_version="$(poetry version --short | tr -d '[:space:]')" - echo "CDK_VERSION=$cdk_version" >> $GITHUB_ENV - - name: Check if tag already exists + if [ -z "$cdk_version" ]; then + echo "Failed to get CDK version" + exit 1 + fi + if [ "$cdk_version" = "0.0.0" ]; then + echo "Error: Failed to resolve dynamic CDK version" + exit 1 + fi + + # Extract the valid SemVer part + valid_cdk_version=$(echo "$cdk_version" | grep -Eo '^[0-9]+\.[0-9]+\.[0-9]+') + + if [ -z "$valid_cdk_version" ]; then + echo "Failed to extract valid SemVer from $cdk_version" + exit 1 + fi + + echo "Valid CDK version extracted: $valid_cdk_version" + + # Sanitize the version string for Docker tags + sanitized_cdk_version="${valid_cdk_version}" + + echo "Using CDK version: $sanitized_cdk_version" + echo "CDK_VERSION=$sanitized_cdk_version" >> $GITHUB_ENV # Pass the semVer CDK version to the next steps + + - name: Check for existing tag run: | - tag="airbyte/source-declarative-manifest:${{ env.CDK_VERSION}}-${{ github.run_number }}" + tag="airbyte/source-declarative-manifest:${{ env.CDK_VERSION }}-${{ github.run_number }}" if DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect "$tag" > /dev/null 2>&1; then echo "The tag $tag already exists on Dockerhub. Skipping publish to prevent overwrite." exit 1 @@ -88,6 +131,6 @@ jobs: platforms: linux/amd64,linux/arm64 push: true tags: | - airbyte/source-declarative-manifest:latest - airbyte/source-declarative-manifest:${{ env.CDK_VERSION }} - airbyte/source-declarative-manifest:${{ env.CDK_VERSION }}-${{ github.run_number }} + airbyte/source-declarative-manifest:test + airbyte/source-declarative-manifest:test-${{ env.CDK_VERSION }} + airbyte/source-declarative-manifest:test-${{ env.CDK_VERSION }}-${{ github.run_number }}