Skip to content

Release v0.18.1 (#301) #46

Release v0.18.1 (#301)

Release v0.18.1 (#301) #46

name: Publish Release
on:
push:
branches: [master]
paths:
- '.github/releases/v*/manifest.yml'
- '.github/releases/v*/RELEASE_NOTES.md'
jobs:
detect-version:
if: github.repository == 'polkadot-developers/polkadot-cookbook'
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
skip: ${{ steps.version.outputs.skip }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
fetch-tags: true
- name: Detect release version
id: version
run: |
# Get files changed in this commit
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD)
# Find release version from changed manifest
VERSION=$(echo "$CHANGED_FILES" | grep -oP '\.github/releases/\K(v[0-9]+\.[0-9]+\.[0-9]+)' | head -1)
if [ -z "$VERSION" ]; then
echo "No release version detected"
echo "skip=true" >> $GITHUB_OUTPUT
exit 0
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Detected release version: $VERSION"
# Check if tag already exists
if git rev-parse "$VERSION" >/dev/null 2>&1; then
echo "Tag $VERSION already exists, skipping release creation"
echo "skip=true" >> $GITHUB_OUTPUT
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
build-cli-binaries:
needs: detect-version
if: github.repository == 'polkadot-developers/polkadot-cookbook' && needs.detect-version.outputs.skip == 'false' && needs.detect-version.outputs.version != ''
name: Build CLI Binary (${{ matrix.target }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact_name: dot
asset_name: dot-linux-amd64
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
artifact_name: dot
asset_name: dot-linux-arm64
cross: true
- os: macos-latest
target: x86_64-apple-darwin
artifact_name: dot
asset_name: dot-macos-intel
- os: macos-latest
target: aarch64-apple-darwin
artifact_name: dot
asset_name: dot-macos-apple-silicon
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact_name: dot.exe
asset_name: dot-windows-amd64.exe
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: ${{ matrix.target }}
- name: Install cross (for cross-compilation)
if: matrix.cross
run: |
cargo install cross@0.2.4 --locked
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Build CLI binary
shell: bash
run: |
cd dot/cli
if [ "${{ matrix.cross }}" = "true" ]; then
cross build --release --locked --target ${{ matrix.target }}
else
cargo build --release --locked --target ${{ matrix.target }}
fi
- name: Prepare binary
shell: bash
run: |
# In a Cargo workspace, binaries are in target/<target>/release, not cli/target
BINARY_PATH=$(find target -type f -name "${{ matrix.artifact_name }}" | grep -E "/${{ matrix.target }}/release/${{ matrix.artifact_name }}$" | head -1)
if [ -z "$BINARY_PATH" ]; then
echo "ERROR: Binary not found!"
find target -type f -name "${{ matrix.artifact_name }}" || echo "No binaries found at all"
exit 1
fi
echo "Found binary at: $BINARY_PATH"
BINARY_DIR=$(dirname "$BINARY_PATH")
cd "$BINARY_DIR"
# Strip binary (except on Windows and macOS arm64)
if [[ "${{ matrix.os }}" != "windows-latest" && "${{ matrix.target }}" != "aarch64-apple-darwin" ]]; then
strip ${{ matrix.artifact_name }} || true
fi
# Create archive in dot/cli directory
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
7z a "$GITHUB_WORKSPACE/dot/cli/${{ matrix.asset_name }}.zip" ${{ matrix.artifact_name }}
else
tar czf "$GITHUB_WORKSPACE/dot/cli/${{ matrix.asset_name }}.tar.gz" ${{ matrix.artifact_name }}
fi
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset_name }}
path: |
dot/cli/${{ matrix.asset_name }}.tar.gz
dot/cli/${{ matrix.asset_name }}.zip
if-no-files-found: error
publish-release:
needs: [detect-version, build-cli-binaries]
if: github.repository == 'polkadot-developers/polkadot-cookbook' && needs.detect-version.outputs.skip == 'false' && needs.detect-version.outputs.version != ''
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Download all CLI binaries
uses: actions/download-artifact@v4
with:
path: cli-artifacts
- name: Create Git tag
env:
VERSION: ${{ needs.detect-version.outputs.version }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Determine release type from commit message
COMMIT_MSG=$(git log -1 --pretty=%B)
if echo "$COMMIT_MSG" | grep -qi "breaking change"; then
TAG_MSG="Release $VERSION (breaking change)"
else
TAG_MSG="Release $VERSION"
fi
git tag -a $VERSION -m "$TAG_MSG"
git push origin $VERSION
echo "✅ Created and pushed tag $VERSION"
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.detect-version.outputs.version }}
run: |
# Determine release title from commit message
COMMIT_MSG=$(git log -1 --pretty=%B)
if echo "$COMMIT_MSG" | grep -qi "breaking change"; then
TITLE="Release $VERSION (Breaking Change)"
else
TITLE="Release $VERSION"
fi
# Collect all CLI binary archives
CLI_ASSETS=""
for file in cli-artifacts/**/*.tar.gz cli-artifacts/**/*.zip; do
if [ -f "$file" ]; then
CLI_ASSETS="$CLI_ASSETS $file"
fi
done
# Collect optional cover art
COVER_ART=""
if [ -f ".github/releases/$VERSION/cover.svg" ]; then
COVER_ART=".github/releases/$VERSION/cover.svg"
fi
# Create release with manifest, cover art, and CLI binaries
gh release create $VERSION \
--title "$TITLE" \
--notes-file ".github/releases/$VERSION/RELEASE_NOTES.md" \
".github/releases/$VERSION/manifest.yml" \
$COVER_ART \
$CLI_ASSETS
echo "✅ Created GitHub Release $VERSION with CLI binaries"