Merge pull request #7 from CleanSlice/fix/ranch-start #101
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 Platform | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| concurrency: | |
| group: release-platform-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| release: | |
| name: Tag and release Ranch platform | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| actions: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Read root version | |
| id: ver | |
| run: | | |
| VERSION=$(node -p "require('./package.json').version") | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| echo "Root package.json version: $VERSION" | |
| - name: Verify tag matches root version | |
| if: startsWith(github.ref, 'refs/tags/v') && !startsWith(github.ref, 'refs/tags/cli-v') | |
| run: | | |
| TAG_VERSION="${GITHUB_REF_NAME#v}" | |
| if [ "$TAG_VERSION" != "${{ steps.ver.outputs.version }}" ]; then | |
| echo "::error::Tag $GITHUB_REF_NAME does not match root package.json version ${{ steps.ver.outputs.version }}" | |
| exit 1 | |
| fi | |
| - name: Create git tag (if missing) | |
| id: tag | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| TAG="v${{ steps.ver.outputs.version }}" | |
| if git rev-parse "$TAG" >/dev/null 2>&1; then | |
| echo "Tag $TAG already exists — skipping creation" | |
| echo "created=false" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git tag "$TAG" | |
| git push origin "$TAG" | |
| echo "created=true" >> "$GITHUB_OUTPUT" | |
| - name: Create GitHub Release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| REPO: ${{ github.repository }} | |
| run: | | |
| VERSION="${{ steps.ver.outputs.version }}" | |
| TAG="v$VERSION" | |
| if gh release view "$TAG" >/dev/null 2>&1; then | |
| echo "Release $TAG already exists — skipping" | |
| exit 0 | |
| fi | |
| git fetch --tags --quiet | |
| PREV_TAG=$(git tag --list 'v*' --sort=-v:refname \ | |
| | grep -v '^cli-' \ | |
| | grep -vx "$TAG" \ | |
| | head -n1 || true) | |
| { | |
| echo "## What's Changed" | |
| echo "" | |
| if [ -n "$PREV_TAG" ]; then | |
| # Exclude cli/ — it has its own release stream | |
| CHANGES=$(git log "${PREV_TAG}..${TAG}" \ | |
| --pretty='format:- %s (%h)' --no-merges -- . ':!cli' || true) | |
| if [ -z "$CHANGES" ]; then | |
| echo "_No platform changes since $PREV_TAG._" | |
| else | |
| echo "$CHANGES" | |
| fi | |
| echo "" | |
| echo "**Full diff:** https://github.com/$REPO/compare/$PREV_TAG...$TAG" | |
| else | |
| echo "Initial platform release." | |
| fi | |
| echo "" | |
| echo "## How to update an existing checkout" | |
| echo "" | |
| echo '```bash' | |
| echo "ranch dev # detects new version, prompts to git pull" | |
| echo '```' | |
| echo "" | |
| echo "Or manually:" | |
| echo '```bash' | |
| echo "cd /path/to/ranch && git pull && bun install" | |
| echo '```' | |
| } > /tmp/platform-notes.md | |
| gh release create "$TAG" \ | |
| --title "Ranch $TAG" \ | |
| --notes-file /tmp/platform-notes.md \ | |
| --target "${{ github.sha }}" \ | |
| --latest | |
| - name: Dispatch build-images for the new tag | |
| if: steps.tag.outputs.created == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # Tag pushes from GITHUB_TOKEN do not trigger other workflows | |
| # (anti-recursion). workflow_dispatch is the exception, so we kick | |
| # build-images explicitly at the freshly-pushed tag — it bakes the | |
| # real version (e.g. 0.2.0) into RANCH_VERSION instead of the | |
| # 0.0.0-<sha> fallback that the prior main-branch run used. | |
| gh workflow run "Build, push & deploy" \ | |
| --repo "${{ github.repository }}" \ | |
| --ref "v${{ steps.ver.outputs.version }}" \ | |
| -f target=all |