|
13 | 13 | ecr_repository_name: durable-functions/aws-durable-execution-emulator |
14 | 14 |
|
15 | 15 | jobs: |
| 16 | + preflight: |
| 17 | + # Decide whether to publish before building anything. |
| 18 | + runs-on: ubuntu-latest |
| 19 | + permissions: |
| 20 | + contents: read |
| 21 | + id-token: write # ECR Public reads require an assumed role |
| 22 | + outputs: |
| 23 | + should_publish: ${{ steps.plan.outputs.should_publish }} |
| 24 | + version: ${{ steps.plan.outputs.version }} |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 27 | + with: |
| 28 | + ref: ${{ github.event.release.tag_name }} |
| 29 | + |
| 30 | + - name: Parse testing version from the release tag |
| 31 | + id: tag |
| 32 | + shell: bash |
| 33 | + env: |
| 34 | + RELEASE_TAG: ${{ github.event.release.tag_name }} |
| 35 | + run: | |
| 36 | + tag_version="$(python .github/scripts/parse_testing_version.py)" |
| 37 | + if [[ -z "$tag_version" ]]; then |
| 38 | + echo "Release tag does not name the testing package. Nothing to publish." |
| 39 | + else |
| 40 | + echo "tag names testing version: $tag_version" |
| 41 | + fi |
| 42 | +
|
| 43 | + - name: Verify the tag version matches the source |
| 44 | + id: verify |
| 45 | + if: steps.tag.outputs.tag_version != '' |
| 46 | + shell: bash |
| 47 | + env: |
| 48 | + TAG_VERSION: ${{ steps.tag.outputs.tag_version }} |
| 49 | + ABOUT_PATH: ${{ env.package_path }}/src/aws_durable_execution_sdk_python_testing/__about__.py |
| 50 | + run: | |
| 51 | + source_version="$(grep "^__version__" "$ABOUT_PATH" | cut -d'"' -f2)" |
| 52 | + echo "source version: $source_version" |
| 53 | + if [[ "$TAG_VERSION" != "$source_version" ]]; then |
| 54 | + echo "::error::Release tag names testing-v$TAG_VERSION but __about__.py is $source_version. Aborting before any publish." |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | + echo "version=$source_version" >> "$GITHUB_OUTPUT" |
| 58 | +
|
| 59 | + - name: Configure AWS Credentials |
| 60 | + if: steps.tag.outputs.tag_version != '' |
| 61 | + uses: aws-actions/configure-aws-credentials@cbe3b392738ccf3f987d68400dafcf4b0624a56c # v6.2.4 |
| 62 | + with: |
| 63 | + role-to-assume: ${{ secrets.ECR_UPLOAD_IAM_ROLE_ARN }} |
| 64 | + aws-region: ${{ env.aws_region }} |
| 65 | + |
| 66 | + - name: Check whether the image tag already exists |
| 67 | + id: exists |
| 68 | + if: steps.tag.outputs.tag_version != '' |
| 69 | + shell: bash |
| 70 | + env: |
| 71 | + VERSION: ${{ steps.verify.outputs.version }} |
| 72 | + ECR_REPOSITORY: ${{ env.ecr_repository_name }} |
| 73 | + run: | |
| 74 | + repo_name="${ECR_REPOSITORY##*/}" |
| 75 | + if aws ecr-public describe-images \ |
| 76 | + --region "${{ env.aws_region }}" \ |
| 77 | + --repository-name "$repo_name" \ |
| 78 | + --image-ids imageTag="v${VERSION}" >/dev/null 2>&1; then |
| 79 | + echo "exists=true" >> "$GITHUB_OUTPUT" |
| 80 | + else |
| 81 | + echo "exists=false" >> "$GITHUB_OUTPUT" |
| 82 | + fi |
| 83 | +
|
| 84 | + - name: Emit release plan |
| 85 | + id: plan |
| 86 | + shell: bash |
| 87 | + env: |
| 88 | + TAG_VERSION: ${{ steps.tag.outputs.tag_version }} |
| 89 | + VERSION: ${{ steps.verify.outputs.version }} |
| 90 | + EXISTS: ${{ steps.exists.outputs.exists }} |
| 91 | + run: | |
| 92 | + echo "## Emulator image release plan" >> "$GITHUB_STEP_SUMMARY" |
| 93 | +
|
| 94 | + if [[ -z "$TAG_VERSION" ]]; then |
| 95 | + echo "- decision: **skip** (release does not name the testing package)" >> "$GITHUB_STEP_SUMMARY" |
| 96 | + echo "should_publish=false" >> "$GITHUB_OUTPUT" |
| 97 | + echo "version=" >> "$GITHUB_OUTPUT" |
| 98 | + exit 0 |
| 99 | + fi |
| 100 | +
|
| 101 | + echo "- testing version: $VERSION" >> "$GITHUB_STEP_SUMMARY" |
| 102 | + if [[ "$EXISTS" == "true" ]]; then |
| 103 | + echo "- image tag v$VERSION: already present in public ECR" >> "$GITHUB_STEP_SUMMARY" |
| 104 | + echo "- decision: **skip** (version already published)" >> "$GITHUB_STEP_SUMMARY" |
| 105 | + echo "should_publish=false" >> "$GITHUB_OUTPUT" |
| 106 | + else |
| 107 | + echo "- image tag v$VERSION: not present in public ECR" >> "$GITHUB_STEP_SUMMARY" |
| 108 | + echo "- decision: **publish**" >> "$GITHUB_STEP_SUMMARY" |
| 109 | + echo "should_publish=true" >> "$GITHUB_OUTPUT" |
| 110 | + fi |
| 111 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 112 | +
|
16 | 113 | build-and-upload-image-to-ecr: |
17 | | - # Only publish when the release includes a new testing package version. |
18 | | - if: contains(github.event.release.tag_name, 'testing-v') |
| 114 | + needs: preflight |
| 115 | + if: needs.preflight.outputs.should_publish == 'true' |
19 | 116 | runs-on: ubuntu-latest |
20 | 117 | permissions: |
21 | 118 | contents: read |
|
24 | 121 | full_image_arm64: ${{ steps.build-publish.outputs.full_image_arm64 }} |
25 | 122 | full_image_x86_64: ${{ steps.build-publish.outputs.full_image_x86_64 }} |
26 | 123 | ecr_registry_repository: ${{ steps.build-publish.outputs.ecr_registry_repository }} |
27 | | - version: ${{ steps.version.outputs.VERSION }} |
| 124 | + version: ${{ needs.preflight.outputs.version }} |
28 | 125 | strategy: |
29 | 126 | matrix: |
30 | 127 | include: |
@@ -56,13 +153,6 @@ jobs: |
56 | 153 | working-directory: ${{ env.package_path }} |
57 | 154 | run: hatch build |
58 | 155 |
|
59 | | - - name: Get version from __about__.py |
60 | | - id: version |
61 | | - run: | |
62 | | - VERSION=$(grep "^__version__" "${{ env.package_path }}/src/aws_durable_execution_sdk_python_testing/__about__.py" | cut -d'"' -f2) |
63 | | - echo "VERSION=$VERSION" |
64 | | - echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT" |
65 | | -
|
66 | 156 | - name: Configure AWS Credentials |
67 | 157 | uses: aws-actions/configure-aws-credentials@cbe3b392738ccf3f987d68400dafcf4b0624a56c # v6.2.4 |
68 | 158 | with: |
|
81 | 171 | env: |
82 | 172 | ECR_REGISTRY: ${{ steps.login-ecr-public.outputs.registry }} |
83 | 173 | ECR_REPOSITORY: ${{ env.ecr_repository_name }} |
84 | | - PER_ARCH_IMAGE_TAG: v${{ steps.version.outputs.VERSION }}-${{ matrix.arch }} |
| 174 | + PER_ARCH_IMAGE_TAG: v${{ needs.preflight.outputs.version }}-${{ matrix.arch }} |
85 | 175 | run: | |
86 | 176 | docker build --platform "${{ matrix.platform }}" --provenance false "${{ env.package_path }}" -f "${{ env.package_path }}/Dockerfile" -t "$ECR_REGISTRY/$ECR_REPOSITORY:$PER_ARCH_IMAGE_TAG" |
87 | 177 | docker push "$ECR_REGISTRY/$ECR_REPOSITORY:$PER_ARCH_IMAGE_TAG" |
@@ -134,3 +224,53 @@ jobs: |
134 | 224 | --arch amd64 \ |
135 | 225 | --os linux |
136 | 226 | docker manifest push "${{ needs.build-and-upload-image-to-ecr.outputs.ecr_registry_repository }}" |
| 227 | +
|
| 228 | + verify-publish: |
| 229 | + needs: [preflight, create-ecr-manifest-per-arch] |
| 230 | + runs-on: ubuntu-latest |
| 231 | + permissions: |
| 232 | + id-token: write |
| 233 | + steps: |
| 234 | + - name: Configure AWS Credentials |
| 235 | + uses: aws-actions/configure-aws-credentials@cbe3b392738ccf3f987d68400dafcf4b0624a56c # v6.2.4 |
| 236 | + with: |
| 237 | + role-to-assume: ${{ secrets.ECR_UPLOAD_IAM_ROLE_ARN }} |
| 238 | + aws-region: ${{ env.aws_region }} |
| 239 | + |
| 240 | + - name: Verify the version and latest tags on public ECR |
| 241 | + shell: bash |
| 242 | + env: |
| 243 | + VERSION: ${{ needs.preflight.outputs.version }} |
| 244 | + ECR_REPOSITORY: ${{ env.ecr_repository_name }} |
| 245 | + run: | |
| 246 | + repo_name="${ECR_REPOSITORY##*/}" |
| 247 | + version_digest="" |
| 248 | + for attempt in $(seq 1 10); do |
| 249 | + version_digest="$(aws ecr-public describe-images \ |
| 250 | + --region "${{ env.aws_region }}" \ |
| 251 | + --repository-name "$repo_name" \ |
| 252 | + --image-ids imageTag="v${VERSION}" \ |
| 253 | + --query 'imageDetails[0].imageDigest' --output text 2>/dev/null || true)" |
| 254 | + if [[ -n "$version_digest" && "$version_digest" != "None" ]]; then |
| 255 | + echo "v$VERSION is visible in public ECR ($version_digest)." |
| 256 | + break |
| 257 | + fi |
| 258 | + echo "attempt $attempt: v$VERSION not visible in public ECR yet, retrying." |
| 259 | + version_digest="" |
| 260 | + sleep 15 |
| 261 | + done |
| 262 | + if [[ -z "$version_digest" ]]; then |
| 263 | + echo "::error::v$VERSION did not become visible in public ECR after publishing." |
| 264 | + exit 1 |
| 265 | + fi |
| 266 | +
|
| 267 | + latest_digest="$(aws ecr-public describe-images \ |
| 268 | + --region "${{ env.aws_region }}" \ |
| 269 | + --repository-name "$repo_name" \ |
| 270 | + --image-ids imageTag="latest" \ |
| 271 | + --query 'imageDetails[0].imageDigest' --output text 2>/dev/null || true)" |
| 272 | + if [[ "$latest_digest" != "$version_digest" ]]; then |
| 273 | + echo "::error::latest on public ECR points at $latest_digest but v$VERSION is $version_digest." |
| 274 | + exit 1 |
| 275 | + fi |
| 276 | + echo "latest on public ECR points at v$VERSION." |
0 commit comments