Skip to content

feat: add development workflow contract #19

feat: add development workflow contract

feat: add development workflow contract #19

Workflow file for this run

name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
dry_run_version:
description: "Version to use for a dry-run build (no tag needed). Leave empty to skip."
required: false
default: ""
permissions:
contents: write
jobs:
build:
name: Build binaries
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
sha_darwin_arm64: ${{ steps.shas.outputs.darwin_arm64 }}
sha_darwin_x64: ${{ steps.shas.outputs.darwin_x64 }}
sha_linux_arm64: ${{ steps.shas.outputs.linux_arm64 }}
sha_linux_x64: ${{ steps.shas.outputs.linux_x64 }}
steps:
- uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Determine version
id: version
run: |
if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
VERSION="${GITHUB_REF_NAME#v}"
elif [ -n "${{ github.event.inputs.dry_run_version }}" ]; then
VERSION="${{ github.event.inputs.dry_run_version }}"
else
VERSION="0.0.0-dryrun.${GITHUB_RUN_NUMBER}"
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "VERSION=${VERSION}"
- name: Build all targets
env:
VERSION: ${{ steps.version.outputs.version }}
run: bash scripts/build-binaries.sh
- name: Extract per-target SHA256
id: shas
run: |
while IFS= read -r line; do
hash=$(awk '{print $1}' <<<"$line")
file=$(awk '{print $2}' <<<"$line" | sed 's#^\*##')
case "$file" in
braincode-darwin-arm64.tar.gz) echo "darwin_arm64=$hash" >> "$GITHUB_OUTPUT" ;;
braincode-darwin-x64.tar.gz) echo "darwin_x64=$hash" >> "$GITHUB_OUTPUT" ;;
braincode-linux-arm64.tar.gz) echo "linux_arm64=$hash" >> "$GITHUB_OUTPUT" ;;
braincode-linux-x64.tar.gz) echo "linux_x64=$hash" >> "$GITHUB_OUTPUT" ;;
esac
done < dist/SHA256SUMS
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: braincode-binaries
path: |
dist/braincode-*.tar.gz
dist/SHA256SUMS
if-no-files-found: error
retention-days: 7
release:
name: GitHub Release
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push' && github.ref_type == 'tag'
steps:
- uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: braincode-binaries
path: dist
- name: Create release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "${GITHUB_REF_NAME}" \
dist/braincode-*.tar.gz \
dist/SHA256SUMS \
--title "${GITHUB_REF_NAME}" \
--generate-notes
npm-publish:
name: Publish to npm
runs-on: ubuntu-latest
needs: [build, release]
if: github.event_name == 'push' && github.ref_type == 'tag'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
registry-url: "https://registry.npmjs.org"
- name: Inject version and publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
VERSION: ${{ needs.build.outputs.version }}
working-directory: apps/cli/npm
run: |
npm version "${VERSION}" --no-git-tag-version --allow-same-version
npm publish --access public
homebrew:
name: Update Homebrew tap
runs-on: ubuntu-latest
needs: [build, release]
if: github.event_name == 'push' && github.ref_type == 'tag'
steps:
- name: Checkout main repo
uses: actions/checkout@v4
with:
path: src
- name: Checkout homebrew-tap
uses: actions/checkout@v4
with:
repository: taotao7/homebrew-tap
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
path: tap
- name: Render formula
env:
VERSION: ${{ needs.build.outputs.version }}
SHA_DARWIN_ARM64: ${{ needs.build.outputs.sha_darwin_arm64 }}
SHA_DARWIN_X64: ${{ needs.build.outputs.sha_darwin_x64 }}
SHA_LINUX_ARM64: ${{ needs.build.outputs.sha_linux_arm64 }}
SHA_LINUX_X64: ${{ needs.build.outputs.sha_linux_x64 }}
run: |
mkdir -p tap/Formula
sed \
-e "s|{{VERSION}}|${VERSION}|g" \
-e "s|{{SHA_DARWIN_ARM64}}|${SHA_DARWIN_ARM64}|g" \
-e "s|{{SHA_DARWIN_X64}}|${SHA_DARWIN_X64}|g" \
-e "s|{{SHA_LINUX_ARM64}}|${SHA_LINUX_ARM64}|g" \
-e "s|{{SHA_LINUX_X64}}|${SHA_LINUX_X64}|g" \
src/scripts/templates/braincode.rb.template > tap/Formula/braincode.rb
cat tap/Formula/braincode.rb
- name: Commit and push
working-directory: tap
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add Formula/braincode.rb
if git diff --cached --quiet; then
echo "no formula changes"
exit 0
fi
git commit -m "braincode ${{ needs.build.outputs.version }}"
git push