|
| 1 | +# This flow publishes the Source-Declarative-Manifest (SDM) |
| 2 | +# connector to DockerHub as a Docker image. |
| 3 | + |
| 4 | +name: Publish SDM Connector |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + version: |
| 10 | + description: |
| 11 | + The version to publish, ie 1.0.0 or 1.0.0-dev1. |
| 12 | + If omitted, and if run from a release branch, the version will be |
| 13 | + inferred from the git tag. |
| 14 | + If omitted, and if run from a non-release branch, then only a SHA-based |
| 15 | + Docker tag will be created. |
| 16 | + required: false |
| 17 | + dry_run: |
| 18 | + description: If true, the workflow will not push to DockerHub. |
| 19 | + type: boolean |
| 20 | + required: false |
| 21 | + default: false |
| 22 | + |
| 23 | +jobs: |
| 24 | + build: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + |
| 28 | + - name: Detect Release Tag Version |
| 29 | + if: startsWith(github.ref, 'refs/tags/v') |
| 30 | + run: | |
| 31 | + DETECTED_VERSION=${{ github.ref_name }} |
| 32 | + echo "Version ref set to '${DETECTED_VERSION}'" |
| 33 | + # Remove the 'v' prefix if it exists |
| 34 | + DETECTED_VERSION="${DETECTED_VERSION#v}" |
| 35 | + echo "Setting version to '$DETECTED_VERSION'" |
| 36 | + echo "DETECTED_VERSION=${DETECTED_VERSION}" >> $GITHUB_ENV |
| 37 | +
|
| 38 | + - name: Validate and set VERSION from tag ('${{ github.ref_name }}') and input (${{ github.event.inputs.version || 'none' }}) |
| 39 | + id: set_version |
| 40 | + if: github.event_name == 'workflow_dispatch' |
| 41 | + run: | |
| 42 | + INPUT_VERSION=${{ github.event.inputs.version }} |
| 43 | + echo "Version input set to '${INPUT_VERSION}'" |
| 44 | + # Exit with success if both detected and input versions are empty |
| 45 | + if [ -z "${DETECTED_VERSION:-}" ] && [ -z "${INPUT_VERSION:-}" ]; then |
| 46 | + echo "No version detected or input. Will publish to SHA tag instead." |
| 47 | + echo 'VERSION=""' >> $GITHUB_ENV |
| 48 | + exit 0 |
| 49 | + fi |
| 50 | + # Remove the 'v' prefix if it exists |
| 51 | + INPUT_VERSION="${INPUT_VERSION#v}" |
| 52 | + # Fail if detected version is non-empty and different from the input version |
| 53 | + if [ -n "${DETECTED_VERSION:-}" ] && [ -n "${INPUT_VERSION:-}" ] && [ "${DETECTED_VERSION}" != "${INPUT_VERSION}" ]; then |
| 54 | + echo "Error: Version input '${INPUT_VERSION}' does not match detected version '${DETECTED_VERSION}'." |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | + # Set the version to the input version if non-empty, otherwise the detected version |
| 58 | + VERSION="${INPUT_VERSION:-$DETECTED_VERSION}" |
| 59 | + # Fail if the version is still empty |
| 60 | + if [ -z "$VERSION" ]; then |
| 61 | + echo "Error: VERSION is not set. Ensure the tag follows the format 'refs/tags/vX.Y.Z'." |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | + echo "Setting version to '$VERSION'" |
| 65 | + echo "VERSION=${VERSION}" >> $GITHUB_ENV |
| 66 | + echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT |
| 67 | + # Check if version is a prerelease version (will not tag 'latest') |
| 68 | + if [[ "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 69 | + echo "IS_PRERELEASE=false" >> $GITHUB_ENV |
| 70 | + echo "IS_PRERELEASE=false" >> $GITHUB_OUTPUT |
| 71 | + else |
| 72 | + echo "IS_PRERELEASE=true" >> $GITHUB_ENV |
| 73 | + echo "IS_PRERELEASE=true" >> $GITHUB_OUTPUT |
| 74 | + fi |
| 75 | +
|
| 76 | + - uses: actions/checkout@v4 |
| 77 | + with: |
| 78 | + fetch-depth: 0 |
| 79 | + |
| 80 | + - uses: hynek/build-and-inspect-python-package@v2 |
| 81 | + name: Build package with version ref '${{ env.VERSION }}' |
| 82 | + env: |
| 83 | + # Pass in the evaluated version from the previous step |
| 84 | + # More info: https://github.com/mtkennerly/poetry-dynamic-versioning#user-content-environment-variables |
| 85 | + POETRY_DYNAMIC_VERSIONING_BYPASS: ${{ env.VERSION }} |
| 86 | + |
| 87 | + - uses: actions/upload-artifact@v4 |
| 88 | + with: |
| 89 | + name: Packages-${{ github.run_id }} |
| 90 | + path: | |
| 91 | + /tmp/baipp/dist/*.whl |
| 92 | + /tmp/baipp/dist/*.tar.gz |
| 93 | + outputs: |
| 94 | + VERSION: ${{ steps.set_version.outputs.VERSION }} |
| 95 | + IS_PRERELEASE: ${{ steps.set_version.outputs.IS_PRERELEASE }} |
| 96 | + |
| 97 | + publish_sdm: |
| 98 | + name: Publish SDM to DockerHub |
| 99 | + if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch' |
| 100 | + runs-on: ubuntu-latest |
| 101 | + needs: [build] |
| 102 | + environment: |
| 103 | + name: DockerHub |
| 104 | + url: https://hub.docker.com/r/airbyte/source-declarative-manifest/tags |
| 105 | + env: |
| 106 | + VERSION: ${{ needs.build.outputs.VERSION }} |
| 107 | + IS_PRERELEASE: ${{ needs.build.outputs.IS_PRERELEASE }} |
| 108 | + |
| 109 | + steps: |
| 110 | + - uses: actions/checkout@v4 |
| 111 | + with: |
| 112 | + fetch-depth: 0 |
| 113 | + |
| 114 | + # We need to download the build artifact again because the previous job was on a different runner |
| 115 | + - name: Download Build Artifact |
| 116 | + uses: actions/download-artifact@v4 |
| 117 | + with: |
| 118 | + name: Packages-${{ github.run_id }} |
| 119 | + path: dist |
| 120 | + |
| 121 | + - name: Set up QEMU for multi-platform builds |
| 122 | + uses: docker/setup-qemu-action@v3 |
| 123 | + |
| 124 | + - name: Set up Docker Buildx |
| 125 | + uses: docker/setup-buildx-action@v3 |
| 126 | + |
| 127 | + - name: Login to Docker Hub |
| 128 | + uses: docker/login-action@v3 |
| 129 | + with: |
| 130 | + username: ${{ secrets.DOCKER_HUB_USERNAME }} |
| 131 | + password: ${{ secrets.DOCKER_HUB_PASSWORD }} |
| 132 | + |
| 133 | + - name: "Check for existing tag (version: ${{ env.VERSION || 'none' }} )" |
| 134 | + if: env.VERSION != '' |
| 135 | + run: | |
| 136 | + tag="airbyte/source-declarative-manifest:${{ env.VERSION }}" |
| 137 | + if [ -z "$tag" ]; then |
| 138 | + echo "Error: VERSION is not set. Ensure the tag follows the format 'refs/tags/vX.Y.Z'." |
| 139 | + exit 1 |
| 140 | + fi |
| 141 | + echo "Checking if tag '$tag' exists on DockerHub..." |
| 142 | + if DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect "$tag" > /dev/null 2>&1; then |
| 143 | + echo "The tag '$tag' already exists on DockerHub. Skipping publish to prevent overwrite." |
| 144 | + exit 1 |
| 145 | + fi |
| 146 | + echo "No existing tag '$tag' found. Proceeding with publish." |
| 147 | +
|
| 148 | + - name: Build and push (sha tag) |
| 149 | + # Only run if the version is not set |
| 150 | + if: env.VERSION == '' && github.event.inputs.dry_run == 'false' |
| 151 | + uses: docker/build-push-action@v5 |
| 152 | + with: |
| 153 | + context: . |
| 154 | + platforms: linux/amd64,linux/arm64 |
| 155 | + push: true |
| 156 | + tags: | |
| 157 | + airbyte/source-declarative-manifest:${{ github.sha }} |
| 158 | +
|
| 159 | + - name: "Build and push (version tag: ${{ env.VERSION || 'none'}})" |
| 160 | + # Only run if the version is set |
| 161 | + if: env.VERSION != '' && github.event.inputs.dry_run == 'false' |
| 162 | + uses: docker/build-push-action@v5 |
| 163 | + with: |
| 164 | + context: . |
| 165 | + platforms: linux/amd64,linux/arm64 |
| 166 | + push: true |
| 167 | + tags: | |
| 168 | + airbyte/source-declarative-manifest:${{ env.VERSION }} |
| 169 | +
|
| 170 | +
|
| 171 | + - name: Build and push ('latest' tag) |
| 172 | + # Only run if version is set and IS_PRERELEASE is false |
| 173 | + if: env.VERSION != '' && env.IS_PRERELEASE == 'false' && github.event.inputs.dry_run == 'false' |
| 174 | + uses: docker/build-push-action@v5 |
| 175 | + with: |
| 176 | + context: . |
| 177 | + platforms: linux/amd64,linux/arm64 |
| 178 | + push: true |
| 179 | + tags: | |
| 180 | + airbyte/source-declarative-manifest:latest |
0 commit comments