← Files Dataiku HeadlessARCHIVED FILE

.github/workflows/bump.yml

5.93 KB · Nov 27, 2026 · 19:32 UTC

↓ Download file

See the change to this file →

name: Release

# Publish automatically after main CI, with manual dispatch for recovery.
on:
  workflow_run:
    workflows: [CI]
    types: [completed]
    branches: [main]
  workflow_dispatch:
    inputs:
      release_pr:
        description: Merged release PR number (required for publish)
        type: string
        required: true

concurrency:
  group: bump
  cancel-in-progress: false

permissions:
  contents: read

jobs:
  publish:
    if: >-
      (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main') ||
      (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' &&
       github.event.workflow_run.event == 'push' && github.event.workflow_run.head_branch == 'main' &&
       github.event.workflow_run.head_repository.full_name == github.repository)
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: read
      actions: read
    steps:
      - name: Resolve merged release PR and check CI
        id: target
        env:
          GH_TOKEN: ${{ github.token }}
          GH_REPO: ${{ github.repository }}
          PR_NUMBER: ${{ inputs.release_pr }}
          EVENT_NAME: ${{ github.event_name }}
          CI_SHA: ${{ github.event.workflow_run.head_sha }}
        run: |
          set -euo pipefail
          if [[ "$EVENT_NAME" == workflow_run ]]; then
            # Query trusted API metadata; never consume artifacts or PR code.
            gh api --paginate --slurp "repos/$GH_REPO/commits/$CI_SHA/pulls?per_page=100" > "$RUNNER_TEMP/pulls.json"
            jq --arg repo "$GH_REPO" --arg sha "$CI_SHA" '[.[][] | select(.merged_at != null and .base.ref == "main" and .head.repo.full_name == $repo and .merge_commit_sha == $sha and (.head.ref | test("^release/[0-9]+\\.[0-9]+\\.[0-9]+$")))]' "$RUNNER_TEMP/pulls.json" > "$RUNNER_TEMP/candidates.json"
            count=$(jq length "$RUNNER_TEMP/candidates.json")
            if [[ "$count" == 0 ]]; then
              echo 'No merged release PR for this CI commit; nothing to publish.' >> "$GITHUB_STEP_SUMMARY"
              exit 0
            fi
            test "$count" = 1 || { echo 'Multiple release PRs match this commit.'; exit 1; }
            PR_NUMBER=$(jq -r '.[0].number' "$RUNNER_TEMP/candidates.json")
          fi
          [[ "$PR_NUMBER" =~ ^[1-9][0-9]*$ ]] || { echo 'Provide a release PR number.'; exit 1; }
          gh api "repos/$GH_REPO/pulls/$PR_NUMBER" > "$RUNNER_TEMP/pr.json"
          jq -e --arg repo "$GH_REPO" '.merged == true and .base.ref == "main" and .head.repo.full_name == $repo and (.head.ref | test("^release/[0-9]+\\.[0-9]+\\.[0-9]+$"))' "$RUNNER_TEMP/pr.json"
          sha=$(jq -r .merge_commit_sha "$RUNNER_TEMP/pr.json")
          if [[ "$EVENT_NAME" == workflow_run ]]; then
            test "$sha" = "$CI_SHA" || { echo 'Release merge does not match the CI commit.'; exit 1; }
          fi
          version=$(jq -r '.head.ref | ltrimstr("release/")' "$RUNNER_TEMP/pr.json")
          gh api "repos/$GH_REPO/actions/workflows/ci.yml/runs?head_sha=$sha&event=push&per_page=1" > "$RUNNER_TEMP/ci.json"
          jq -e --arg sha "$sha" --arg repo "$GH_REPO" '.workflow_runs[0] | .head_sha == $sha and .head_branch == "main" and .head_repository.full_name == $repo and .event == "push" and .status == "completed" and .conclusion == "success"' "$RUNNER_TEMP/ci.json"
          echo "head_sha=$(jq -r .head.sha "$RUNNER_TEMP/pr.json")" >> "$GITHUB_OUTPUT"
          echo "sha=$sha" >> "$GITHUB_OUTPUT"
          echo "version=$version" >> "$GITHUB_OUTPUT"
      - if: steps.target.outputs.sha != ''
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          ref: ${{ steps.target.outputs.sha }}
          fetch-depth: 0
      - if: steps.target.outputs.sha != ''
        uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
      - name: Verify merged release before publishing
        if: steps.target.outputs.sha != ''
        env:
          VERSION: ${{ steps.target.outputs.version }}
          RELEASE_HEAD: ${{ steps.target.outputs.head_sha }}
        run: |
          set -euo pipefail
          python3 scripts/check_release.py --merge-head "$RELEASE_HEAD"
          test "$(python3 scripts/check_release.py)" = "$VERSION"
          git merge-base --is-ancestor HEAD origin/main
          uv lock --check
          uv lock --script runtime/run_mcp.py --check
          python3 scripts/check_release.py --notes > "$RUNNER_TEMP/notes.md"
      - name: Push matching tags and publish release
        if: steps.target.outputs.sha != ''
        env:
          GH_TOKEN: ${{ github.token }}
          VERSION: ${{ steps.target.outputs.version }}
        run: |
          set -euo pipefail
          git config user.name 'github-actions[bot]'
          git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
          sha=$(git rev-parse HEAD)
          # Check BOTH existing tags before creating or pushing either one.
          for tag in "v$VERSION" "dataiku-headless--v$VERSION"; do
            if git show-ref --verify --quiet "refs/tags/$tag"; then
              test "$(git rev-parse "refs/tags/$tag^{commit}")" = "$sha" || { echo "Tag $tag points to another commit."; exit 1; }
            fi
          done
          for tag in "v$VERSION" "dataiku-headless--v$VERSION"; do
            git show-ref --verify --quiet "refs/tags/$tag" || git tag -a "$tag" -m "dataiku-headless $VERSION"
          done
          git push --atomic origin "refs/tags/v$VERSION" "refs/tags/dataiku-headless--v$VERSION"
          # A successful retry leaves an existing release unchanged.
          gh release list --limit 1000 --json tagName > "$RUNNER_TEMP/releases.json"
          if ! jq -e --arg tag "v$VERSION" 'any(.[]; .tagName == $tag)' "$RUNNER_TEMP/releases.json"; then
            gh release create "v$VERSION" --verify-tag --title "v$VERSION" --notes-file "$RUNNER_TEMP/notes.md"
          fi
          gh release view "v$VERSION" --json url --jq .url >> "$GITHUB_STEP_SUMMARY"

SHA-256: cf8cb14f19e5c6f4c32754b26060553d9f77d10c1c15a49d24250e89c65337dd