Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: account for dynamic CDK version #72

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 51 additions & 8 deletions .github/workflows/cdk-publish.yml
Original file line number Diff line number Diff line change
@@ -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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the version in pyproject is static and doesn't reflect the actual dynamic CDK version, we default to pushing a new image on any changes to the CDK (except test files)

- 'Dockerfile'
workflow_dispatch:

Expand Down Expand Up @@ -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'
Expand All @@ -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:
Expand All @@ -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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably can either delete this line or the ENV variable on line 61


- 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
Expand All @@ -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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Revert the tags before merging to main

airbyte/source-declarative-manifest:test-${{ env.CDK_VERSION }}
airbyte/source-declarative-manifest:test-${{ env.CDK_VERSION }}-${{ github.run_number }}
Loading