|
| 1 | +name: update openapi |
| 2 | + |
| 3 | +# Detects a new STABLE ethersphere/bee release tag, pulls its OpenAPI specs into |
| 4 | +# openapi/, bumps the Bee version strings in the install docs, and opens (or updates) |
| 5 | +# a PR. Prereleases (-rc*, -beta, v2.7.1a, v2.5.0-v8, ...) are ignored. |
| 6 | +# |
| 7 | +# Requires the BOT_PAT secret (a classic PAT with public_repo scope, or a fine-grained PAT |
| 8 | +# with contents + pull-requests write). It is used so the auto-PR triggers build.yaml CI — |
| 9 | +# PRs opened with the default GITHUB_TOKEN do NOT trigger other workflows. The job fails |
| 10 | +# loudly if BOT_PAT is missing/expired rather than silently skipping CI. |
| 11 | + |
| 12 | +on: |
| 13 | + schedule: |
| 14 | + - cron: "0 6 * * *" # daily 06:00 UTC |
| 15 | + workflow_dispatch: |
| 16 | + inputs: |
| 17 | + tag: |
| 18 | + description: "Force a specific Bee tag (e.g. v2.9.0); blank = latest stable" |
| 19 | + required: false |
| 20 | + |
| 21 | +concurrency: |
| 22 | + group: update-openapi |
| 23 | + cancel-in-progress: true |
| 24 | + |
| 25 | +permissions: |
| 26 | + contents: write |
| 27 | + pull-requests: write |
| 28 | + |
| 29 | +jobs: |
| 30 | + update-openapi: |
| 31 | + runs-on: ubuntu-22.04 |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + fetch-depth: 0 |
| 36 | + |
| 37 | + - name: Resolve latest stable Bee tag |
| 38 | + id: resolve |
| 39 | + run: | |
| 40 | + set -euo pipefail |
| 41 | + if [ -n "${{ github.event.inputs.tag }}" ]; then |
| 42 | + NEW_TAG="${{ github.event.inputs.tag }}" |
| 43 | + else |
| 44 | + NEW_TAG="$(git ls-remote --tags --refs https://github.com/ethersphere/bee.git \ |
| 45 | + | awk '{print $2}' | sed 's#refs/tags/##' \ |
| 46 | + | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \ |
| 47 | + | sort -V | tail -1)" |
| 48 | + fi |
| 49 | + if [ -z "$NEW_TAG" ]; then |
| 50 | + echo "Could not resolve a stable Bee tag" >&2 |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | + NEW_VER="${NEW_TAG#v}" |
| 54 | + echo "new_tag=$NEW_TAG" >> "$GITHUB_OUTPUT" |
| 55 | + echo "new_ver=$NEW_VER" >> "$GITHUB_OUTPUT" |
| 56 | + echo "Latest stable Bee tag: $NEW_TAG (version $NEW_VER)" |
| 57 | +
|
| 58 | + - name: Determine current docs version |
| 59 | + id: current |
| 60 | + run: | |
| 61 | + set -euo pipefail |
| 62 | + OLD_VER="$(grep -oE 'TAG=v[0-9]+\.[0-9]+\.[0-9]+' docs/bee/installation/quick-start.md \ |
| 63 | + | head -1 | sed 's/^TAG=v//')" |
| 64 | + if [ -z "$OLD_VER" ]; then |
| 65 | + echo "Could not determine current docs version anchor" >&2 |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | + echo "old_ver=$OLD_VER" >> "$GITHUB_OUTPUT" |
| 69 | + echo "Current docs version: $OLD_VER" |
| 70 | +
|
| 71 | + - name: Fetch OpenAPI specs from the tag |
| 72 | + env: |
| 73 | + NEW_TAG: ${{ steps.resolve.outputs.new_tag }} |
| 74 | + run: | |
| 75 | + set -euo pipefail |
| 76 | + for f in Swarm.yaml SwarmCommon.yaml; do |
| 77 | + curl -fsSL \ |
| 78 | + "https://raw.githubusercontent.com/ethersphere/bee/${NEW_TAG}/openapi/$f" \ |
| 79 | + -o "openapi/$f" |
| 80 | + done |
| 81 | +
|
| 82 | + - name: Bump Bee version strings in docs |
| 83 | + if: ${{ steps.current.outputs.old_ver != steps.resolve.outputs.new_ver }} |
| 84 | + env: |
| 85 | + OLD_VER: ${{ steps.current.outputs.old_ver }} |
| 86 | + NEW_VER: ${{ steps.resolve.outputs.new_ver }} |
| 87 | + run: | |
| 88 | + set -euo pipefail |
| 89 | + FILES=( |
| 90 | + docs/bee/installation/build-from-source.md |
| 91 | + docs/bee/installation/docker.md |
| 92 | + docs/bee/installation/quick-start.md |
| 93 | + docs/bee/installation/shell-script.md |
| 94 | + docs/bee/working-with-bee/bee-api.md |
| 95 | + docs/bee/working-with-bee/configuration.md |
| 96 | + docs/bee/working-with-bee/staking.md |
| 97 | + ) |
| 98 | + # Literal substring swap of the semver. This deliberately also rewrites the |
| 99 | + # vX.Y.Z, bee:X.Y.Z and X.Y.Z-<hash> forms (the version is a substring of each), |
| 100 | + # and is safe because the old version never appears inside an unrelated number |
| 101 | + # in these files. ESC_OLD escapes the dots so they match literally. |
| 102 | + ESC_OLD="${OLD_VER//./\\.}" |
| 103 | + sed -i "s/${ESC_OLD}/${NEW_VER}/g" "${FILES[@]}" |
| 104 | +
|
| 105 | + - name: Detect changes |
| 106 | + id: changes |
| 107 | + run: | |
| 108 | + set -euo pipefail |
| 109 | + if git diff --quiet; then |
| 110 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 111 | + echo "No changes — already up to date with the latest stable Bee release." |
| 112 | + else |
| 113 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 114 | + fi |
| 115 | +
|
| 116 | + - name: Create or update PR |
| 117 | + if: ${{ steps.changes.outputs.changed == 'true' }} |
| 118 | + uses: peter-evans/create-pull-request@v6 |
| 119 | + with: |
| 120 | + token: ${{ secrets.BOT_PAT }} |
| 121 | + branch: bot/update-openapi-${{ steps.resolve.outputs.new_tag }} |
| 122 | + commit-message: "chore: update OpenAPI specs and version refs to Bee ${{ steps.resolve.outputs.new_tag }}" |
| 123 | + title: "Update OpenAPI specs to Bee ${{ steps.resolve.outputs.new_tag }}" |
| 124 | + labels: openapi-auto-update |
| 125 | + delete-branch: true |
| 126 | + body: | |
| 127 | + Automated update to Bee **${{ steps.resolve.outputs.new_tag }}**. |
| 128 | +
|
| 129 | + Source: https://github.com/ethersphere/bee/tree/${{ steps.resolve.outputs.new_tag }}/openapi |
| 130 | +
|
| 131 | + ## What changed |
| 132 | + - `openapi/Swarm.yaml` and `openapi/SwarmCommon.yaml` pulled from the tagged commit. |
| 133 | + - Bee version strings bumped `${{ steps.current.outputs.old_ver }}` → `${{ steps.resolve.outputs.new_ver }}` in the install docs. |
| 134 | +
|
| 135 | + ## ⚠️ Please review before merging |
| 136 | + The version-string replacement is **best-effort** (literal semver swap in a fixed set |
| 137 | + of doc files) and can miss or over-match. Skim the doc diff. Merging this PR triggers |
| 138 | + the `tag-on-openapi-merge` workflow, which tags the merge commit `${{ steps.resolve.outputs.new_tag }}` |
| 139 | + and (with a PAT configured) kicks off the gh-pages deploy. |
0 commit comments