Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish public ingester images | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: "Public release tag to publish images for. Must start with v." | |
| required: true | |
| type: string | |
| concurrency: | |
| group: publish-public-ingester-images | |
| cancel-in-progress: false | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| PUBLIC_IMAGE_CRATES: chainlink-ingester pyth-ingester redstone-ingester stork-ingester | |
| PUBLIC_REGISTRY_OWNER: relayprotocol | |
| PUBLIC_REPOSITORY_URL: https://github.com/relayprotocol/relay-settlement | |
| jobs: | |
| publish: | |
| name: Build and publish ingester images | |
| if: >- | |
| ${{ | |
| github.repository == 'relayprotocol/relay-settlement' && | |
| ( | |
| (github.event_name == 'release' && startsWith(github.event.release.tag_name, 'v')) || | |
| (github.event_name == 'workflow_dispatch' && startsWith(inputs.tag, 'v')) | |
| ) | |
| }} | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 60 | |
| steps: | |
| - name: Resolve public release tag | |
| id: meta | |
| env: | |
| EVENT_NAME: ${{ github.event_name }} | |
| RELEASE_TAG: ${{ github.event.release.tag_name }} | |
| INPUT_TAG: ${{ inputs.tag }} | |
| run: | | |
| set -euo pipefail | |
| if [ "$EVENT_NAME" = "release" ]; then | |
| public_version="$RELEASE_TAG" | |
| else | |
| public_version="$INPUT_TAG" | |
| fi | |
| if ! [[ "$public_version" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([.-][A-Za-z0-9._-]+)?$ ]]; then | |
| echo "::error::Public image tags must look like v1.2.3" | |
| exit 1 | |
| fi | |
| echo "public_version=$public_version" >> "$GITHUB_OUTPUT" | |
| - name: Checkout public release tag | |
| uses: actions/checkout@v6.0.2 | |
| with: | |
| ref: ${{ steps.meta.outputs.public_version }} | |
| - name: Setup Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to public GHCR | |
| uses: docker/login-action@v4.1.0 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ github.token }} | |
| - name: Build public ingester images | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| PUBLIC_VERSION: ${{ steps.meta.outputs.public_version }} | |
| run: | | |
| set -euo pipefail | |
| ghcr_tags() { | |
| local crate="$1" | |
| local error_file="$RUNNER_TEMP/ghcr-${crate}.err" | |
| if gh api \ | |
| "orgs/${PUBLIC_REGISTRY_OWNER}/packages/container/${crate}/versions" \ | |
| --paginate \ | |
| --jq '.[].metadata.container.tags[]?' \ | |
| 2>"$error_file"; then | |
| return 0 | |
| fi | |
| if grep -q "Package not found" "$error_file"; then | |
| return 1 | |
| fi | |
| cat "$error_file" >&2 | |
| return 2 | |
| } | |
| for crate in $PUBLIC_IMAGE_CRATES; do | |
| image="ghcr.io/${PUBLIC_REGISTRY_OWNER}/${crate}" | |
| existing_tags="" | |
| if existing_tags="$(ghcr_tags "$crate")"; then | |
| if printf '%s\n' "$existing_tags" | grep -Fxq "$PUBLIC_VERSION"; then | |
| echo "Skipping ${image}:${PUBLIC_VERSION}; tag already exists." | |
| continue | |
| fi | |
| else | |
| tag_check_status=$? | |
| if [ "$tag_check_status" -ne 1 ]; then | |
| exit "$tag_check_status" | |
| fi | |
| fi | |
| newest="$( | |
| printf '%s\n%s\n' "$existing_tags" "$PUBLIC_VERSION" \ | |
| | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \ | |
| | sort -V \ | |
| | tail -n1 || true | |
| )" | |
| build_tags=(--tag "${image}:${PUBLIC_VERSION}") | |
| if [ "$newest" = "$PUBLIC_VERSION" ]; then | |
| build_tags+=(--tag "${image}:latest") | |
| else | |
| echo "Not tagging ${image}:latest; ${PUBLIC_VERSION} is not the newest stable vX.Y.Z tag (${newest:-<none>})." | |
| fi | |
| docker buildx build \ | |
| --file "crates/${crate}/Dockerfile" \ | |
| --label "org.opencontainers.image.source=${PUBLIC_REPOSITORY_URL}" \ | |
| "${build_tags[@]}" \ | |
| --push \ | |
| crates | |
| done |