Skip to content

feat: initial Turso Elixir client library #11

feat: initial Turso Elixir client library

feat: initial Turso Elixir client library #11

Workflow file for this run

name: Release
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., 1.0.0)'
required: true
type: string
env:
MIX_ENV: prod
jobs:
# Create GitHub release
release:
name: Create Release
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch'
permissions:
contents: write
outputs:
version: ${{ steps.version.outputs.version }}
tag_version: ${{ steps.version.outputs.tag_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full history for changelog generation
- name: Extract version
id: version
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ github.event.inputs.version }}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag_version=v$VERSION" >> $GITHUB_OUTPUT
else
TAG_VERSION="${GITHUB_REF#refs/tags/}"
VERSION="${TAG_VERSION#v}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag_version=$TAG_VERSION" >> $GITHUB_OUTPUT
fi
- name: Install mise and tools
uses: jdx/mise-action@v3
with:
install: true
cache: true
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
deps/
_build/
key: ${{ runner.os }}-mix-prod-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}-${{ hashFiles('mise.toml') }}
restore-keys: |
${{ runner.os }}-mix-prod-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}-
${{ runner.os }}-mix-prod-
- name: Install dependencies
run: mix deps.get
- name: Generate changelog
id: changelog
run: |
VERSION="${{ steps.version.outputs.version }}"
# Find previous tag or use initial commit for first release
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || git rev-list --max-parents=0 HEAD)
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo "## What's Changed in v$VERSION" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
# Group commits by type
echo "### ✨ Features" >> $GITHUB_OUTPUT
git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD | grep -E "^- (feat|add)" || echo "- No new features" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "### 🐛 Bug Fixes" >> $GITHUB_OUTPUT
git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD | grep -E "^- (fix|bug)" || echo "- No bug fixes" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "### 📚 Documentation" >> $GITHUB_OUTPUT
git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD | grep -E "^- (docs|doc)" || echo "- No documentation changes" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "### 🔧 Other Changes" >> $GITHUB_OUTPUT
git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD | grep -vE "^- (feat|add|fix|bug|docs|doc)" || echo "- No other changes" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "### Installation" >> $GITHUB_OUTPUT
echo "\`\`\`elixir" >> $GITHUB_OUTPUT
echo "def deps do" >> $GITHUB_OUTPUT
echo " [{:turso, \"~> $VERSION\"}]" >> $GITHUB_OUTPUT
echo "end" >> $GITHUB_OUTPUT
echo "\`\`\`" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "**Full Changelog**: [$PREVIOUS_TAG...v$VERSION](https://github.com/${{ github.repository }}/compare/$PREVIOUS_TAG...v$VERSION)" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag_version }}
name: Turso Elixir Client v${{ steps.version.outputs.version }}
body: ${{ steps.changelog.outputs.CHANGELOG }}
draft: false
prerelease: ${{ contains(steps.version.outputs.version, '-') }}
make_latest: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Publish to Hex.pm
publish:
name: Publish to Hex
runs-on: ubuntu-latest
needs: release
if: (startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch') && !contains(needs.release.outputs.version, '-')
env:
MIX_ENV: dev # Override to dev so ex_doc is available
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install mise and tools
uses: jdx/mise-action@v3
with:
install: true
cache: true
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
deps/
_build/
key: ${{ runner.os }}-mix-prod-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}-${{ hashFiles('mise.toml') }}
restore-keys: |
${{ runner.os }}-mix-prod-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}-
${{ runner.os }}-mix-prod-
- name: Install dependencies
run: mix deps.get
- name: Compile application
run: mix compile --warnings-as-errors
- name: Verify package can be built
run: mix hex.build
- name: Publish to Hex
run: mix hex.publish --yes
env:
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
# Notification and cleanup
notify:
name: Release Notification
runs-on: ubuntu-latest
needs: [release, publish]
if: always() && (startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch')
steps:
- name: Notify release status
run: |
VERSION="${{ needs.release.outputs.version }}"
if [[ "${{ needs.release.result }}" == "success" && "${{ needs.publish.result }}" == "success" ]]; then
echo "✅ Turso Elixir Client v$VERSION successfully released!"
echo "📦 Hex package: https://hex.pm/packages/turso/$VERSION"
echo "📋 GitHub release: https://github.com/${{ github.repository }}/releases/tag/v$VERSION"
echo "📚 Documentation: https://hexdocs.pm/turso/$VERSION"
elif [[ "${{ needs.release.result }}" == "success" && "${{ needs.publish.result }}" == "skipped" ]]; then
echo "✅ Pre-release v$VERSION created on GitHub (Hex publishing skipped for pre-release)"
echo "📋 GitHub release: https://github.com/${{ github.repository }}/releases/tag/v$VERSION"
else
echo "❌ Release pipeline failed for v$VERSION"
echo "Release result: ${{ needs.release.result }}"
echo "Publish result: ${{ needs.publish.result }}"
exit 1
fi