Skip to content

Update API bindings

Update API bindings #4

name: Update API bindings
on:
workflow_dispatch:
inputs:
version:
description: "Binding version (leave blank to auto-increment the patch version)"
required: false
type: string
schedule:
# Daily at 06:00 UTC
- cron: "0 6 * * *"
permissions:
contents: write
pull-requests: write
jobs:
update-bindings:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Set up tools
uses: jdx/mise-action@e6a8b3978addb5a52f2b4cd9d91eafa7f0ab959d # v4.2.0
- name: Generate bindings
run: mise run build
- name: Detect changes
id: detect
env:
INPUT_VERSION: ${{ inputs.version }}
run: |
if [ -n "$INPUT_VERSION" ] || [ -n "$(git status --porcelain)" ]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "Bindings already match the current API; no PR needed."
fi
- name: Bump version and regenerate
if: steps.detect.outputs.changed == 'true'
id: versions
env:
INPUT_VERSION: ${{ inputs.version }}
run: |
api_version=$(curl -s --max-time 30 "https://api.cloudsmith.io/status/check/basic/" | jq -r '.version')
if [ -z "$api_version" ] || [ "$api_version" = "null" ]; then
echo "Could not fetch CloudSmith API version" >&2
exit 1
fi
current_version=$(grep -E '^package_version=' scripts/common.sh | cut -d'"' -f2)
if [ -n "$INPUT_VERSION" ]; then
new_version="$INPUT_VERSION"
else
IFS='.' read -r major minor patch <<< "$current_version"
new_version="${major}.${minor}.$((patch + 1))"
fi
sed -i -E "s/^package_version=.*/package_version=\"${new_version}\"/" scripts/common.sh
mise run build
echo "api_version=$api_version" >> "$GITHUB_OUTPUT"
echo "new_version=$new_version" >> "$GITHUB_OUTPUT"
- name: Close stale automated binding PRs
if: steps.detect.outputs.changed == 'true'
env:
GH_TOKEN: ${{ github.token }}
NEW_VERSION: ${{ steps.versions.outputs.new_version }}
run: |
keep="automated/update-bindings-v${NEW_VERSION}"
gh pr list --state open --json number,headRefName \
--jq '.[]
| select(.headRefName | startswith("automated/update-bindings-"))
| select(.headRefName != "'"$keep"'")
| .number' \
| while read -r number; do
[ -n "$number" ] || continue
gh pr close "$number" --delete-branch \
--comment "Superseded by automated bindings update v${NEW_VERSION}."
done
- name: Create pull request
if: steps.detect.outputs.changed == 'true'
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
with:
branch: automated/update-bindings-v${{ steps.versions.outputs.new_version }}
base: master
title: "feat: update bindings to v${{ steps.versions.outputs.new_version }} (API v${{ steps.versions.outputs.api_version }})"
commit-message: "feat: update bindings to v${{ steps.versions.outputs.new_version }} (API v${{ steps.versions.outputs.api_version }})"
body: |
Automated API bindings update.
- Binding version: `${{ steps.versions.outputs.new_version }}`
- CloudSmith API version: `${{ steps.versions.outputs.api_version }}`
Generated by the **Update API bindings** workflow.
labels: |
bindings
automated
delete-branch: true