sdk-updated #106
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: Release CLI | |
| on: | |
| repository_dispatch: | |
| types: [sdk-updated] | |
| workflow_dispatch: | |
| concurrency: | |
| group: cli-release | |
| cancel-in-progress: false | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.RELEASE_PAT }} | |
| - name: Pull latest to avoid race conditions | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git fetch --tags | |
| git pull --rebase origin main | |
| - name: Fetch latest SDK version from tag | |
| id: sdk | |
| run: | | |
| SDK_VER=$(curl -sL -H "Authorization: token ${{ secrets.RELEASE_PAT }}" \ | |
| "https://api.github.com/repos/buildio/sdk-crystal-lang/tags" \ | |
| | jq -r '[.[] | select(.name | test("^v[0-9]+\\.[0-9]+\\.[0-9]+$"))][0].name' \ | |
| | sed 's/^v//') | |
| echo "version=$SDK_VER" >> $GITHUB_OUTPUT | |
| echo "SDK version: $SDK_VER" | |
| - name: Determine next version | |
| id: version | |
| run: | | |
| LATEST=$(git tag -l 'v*' | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -1) | |
| LATEST="${LATEST:-v0.0.0}" | |
| MAJOR=$(echo "$LATEST" | sed 's/v//' | cut -d. -f1) | |
| MINOR=$(echo "$LATEST" | sed 's/v//' | cut -d. -f2) | |
| PATCH=$(echo "$LATEST" | sed 's/v//' | cut -d. -f3) | |
| NEXT_TAG="v${MAJOR}.${MINOR}.$((PATCH + 1))" | |
| NEXT_VER="${MAJOR}.${MINOR}.$((PATCH + 1))" | |
| echo "tag=${NEXT_TAG}" >> $GITHUB_OUTPUT | |
| echo "bare=${NEXT_VER}" >> $GITHUB_OUTPUT | |
| echo "Next version: $NEXT_TAG" | |
| - name: Update shard.yml | |
| env: | |
| SDK_VER: ${{ steps.sdk.outputs.version }} | |
| CLI_VER: ${{ steps.version.outputs.bare }} | |
| run: | | |
| sed -i "s/^version: .*/version: ${CLI_VER}/" shard.yml | |
| sed -i "/build-client/{n;n;s/version: .*/version: ${SDK_VER}/;}" shard.yml | |
| echo "Updated shard.yml:" | |
| head -15 shard.yml | |
| - name: Install Crystal and update lockfile | |
| uses: crystal-lang/install-crystal@v1 | |
| - run: shards update | |
| - name: Commit, tag, and push | |
| env: | |
| NEXT_TAG: ${{ steps.version.outputs.tag }} | |
| SDK_VER: ${{ steps.sdk.outputs.version }} | |
| run: | | |
| git add shard.yml shard.lock | |
| if ! git diff --cached --quiet; then | |
| git commit -m "Release ${NEXT_TAG}, SDK ${SDK_VER}" | |
| fi | |
| git tag "${NEXT_TAG}" | |
| git push origin main --tags | |
| # Export for downstream steps | |
| echo "RELEASE_TAG=${NEXT_TAG}" >> $GITHUB_ENV | |
| - name: Dispatch to Homebrew | |
| uses: peter-evans/repository-dispatch@v3 | |
| with: | |
| token: ${{ secrets.RELEASE_PAT }} | |
| repository: buildio/homebrew-cli | |
| event-type: cli-released | |
| client-payload: '{"tag": "${{ env.RELEASE_TAG }}"}' |