|
| 1 | +name: Update API bindings |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: "Binding version (leave blank to auto-increment the patch version)" |
| 8 | + required: false |
| 9 | + type: string |
| 10 | + schedule: |
| 11 | + # Daily at 06:00 UTC |
| 12 | + - cron: "0 6 * * *" |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: write |
| 16 | + pull-requests: write |
| 17 | + |
| 18 | +jobs: |
| 19 | + update-bindings: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 24 | + with: |
| 25 | + persist-credentials: false |
| 26 | + |
| 27 | + - name: Set up tools |
| 28 | + uses: jdx/mise-action@e6a8b3978addb5a52f2b4cd9d91eafa7f0ab959d # v4.2.0 |
| 29 | + |
| 30 | + - name: Generate bindings |
| 31 | + run: mise run build |
| 32 | + |
| 33 | + - name: Detect changes |
| 34 | + id: detect |
| 35 | + env: |
| 36 | + INPUT_VERSION: ${{ inputs.version }} |
| 37 | + run: | |
| 38 | + if [ -n "$INPUT_VERSION" ] || [ -n "$(git status --porcelain)" ]; then |
| 39 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 40 | + else |
| 41 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 42 | + echo "Bindings already match the current API; no PR needed." |
| 43 | + fi |
| 44 | +
|
| 45 | + - name: Bump version and regenerate |
| 46 | + if: steps.detect.outputs.changed == 'true' |
| 47 | + id: versions |
| 48 | + env: |
| 49 | + INPUT_VERSION: ${{ inputs.version }} |
| 50 | + run: | |
| 51 | + api_version=$(curl -s --max-time 30 "https://api.cloudsmith.io/status/check/basic/" | jq -r '.version') |
| 52 | + if [ -z "$api_version" ] || [ "$api_version" = "null" ]; then |
| 53 | + echo "Could not fetch CloudSmith API version" >&2 |
| 54 | + exit 1 |
| 55 | + fi |
| 56 | +
|
| 57 | + current_version=$(grep -E '^package_version=' scripts/common.sh | cut -d'"' -f2) |
| 58 | + if [ -n "$INPUT_VERSION" ]; then |
| 59 | + new_version="$INPUT_VERSION" |
| 60 | + else |
| 61 | + IFS='.' read -r major minor patch <<< "$current_version" |
| 62 | + new_version="${major}.${minor}.$((patch + 1))" |
| 63 | + fi |
| 64 | +
|
| 65 | + sed -i -E "s/^package_version=.*/package_version=\"${new_version}\"/" scripts/common.sh |
| 66 | + mise run build |
| 67 | +
|
| 68 | + echo "api_version=$api_version" >> "$GITHUB_OUTPUT" |
| 69 | + echo "new_version=$new_version" >> "$GITHUB_OUTPUT" |
| 70 | +
|
| 71 | + - name: Close stale automated binding PRs |
| 72 | + if: steps.detect.outputs.changed == 'true' |
| 73 | + env: |
| 74 | + GH_TOKEN: ${{ github.token }} |
| 75 | + NEW_VERSION: ${{ steps.versions.outputs.new_version }} |
| 76 | + run: | |
| 77 | + keep="automated/update-bindings-v${NEW_VERSION}" |
| 78 | + gh pr list --state open --json number,headRefName \ |
| 79 | + --jq '.[] |
| 80 | + | select(.headRefName | startswith("automated/update-bindings-")) |
| 81 | + | select(.headRefName != "'"$keep"'") |
| 82 | + | .number' \ |
| 83 | + | while read -r number; do |
| 84 | + [ -n "$number" ] || continue |
| 85 | + gh pr close "$number" --delete-branch \ |
| 86 | + --comment "Superseded by automated bindings update v${NEW_VERSION}." |
| 87 | + done |
| 88 | +
|
| 89 | + - name: Create pull request |
| 90 | + if: steps.detect.outputs.changed == 'true' |
| 91 | + uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1 |
| 92 | + with: |
| 93 | + branch: automated/update-bindings-v${{ steps.versions.outputs.new_version }} |
| 94 | + base: master |
| 95 | + title: "feat: update bindings to v${{ steps.versions.outputs.new_version }} (API v${{ steps.versions.outputs.api_version }})" |
| 96 | + commit-message: "feat: update bindings to v${{ steps.versions.outputs.new_version }} (API v${{ steps.versions.outputs.api_version }})" |
| 97 | + body: | |
| 98 | + Automated API bindings update. |
| 99 | +
|
| 100 | + - Binding version: `${{ steps.versions.outputs.new_version }}` |
| 101 | + - CloudSmith API version: `${{ steps.versions.outputs.api_version }}` |
| 102 | +
|
| 103 | + Generated by the **Update API bindings** workflow. |
| 104 | + labels: | |
| 105 | + bindings |
| 106 | + automated |
| 107 | + delete-branch: true |
0 commit comments