fix: Windows compatibility and workflow error handling #5
Workflow file for this run
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 | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| permissions: | |
| contents: write | |
| packages: write | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| create-release: | |
| name: Create Release | |
| runs-on: ubuntu-latest | |
| outputs: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| version: ${{ steps.get_version.outputs.version }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Get version from tag | |
| id: get_version | |
| run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT | |
| - name: Generate Changelog | |
| id: changelog | |
| uses: mikepenz/release-changelog-builder-action@v4 | |
| with: | |
| configuration: ".github/changelog-config.json" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create Release | |
| id: create_release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| TAG_NAME="${GITHUB_REF#refs/tags/}" | |
| gh release create "${TAG_NAME}" \ | |
| --title "Release ${TAG_NAME}" \ | |
| --notes "## Installation | |
| ### Install via npm | |
| \`\`\`bash | |
| npm install -g @v-lawyer/kanuni | |
| \`\`\` | |
| ### Install via Cargo | |
| \`\`\`bash | |
| cargo install kanuni | |
| \`\`\` | |
| ### Download binaries | |
| See Assets below for platform-specific binaries. | |
| ## What's New | |
| See [CHANGELOG.md](https://github.com/v-lawyer/kanuni-cli/blob/main/CHANGELOG.md) for details." | |
| build-release: | |
| name: Build Release | |
| needs: create-release | |
| strategy: | |
| matrix: | |
| include: | |
| # macOS builds | |
| - target: x86_64-apple-darwin | |
| os: macos-latest | |
| name: kanuni-darwin-x64 | |
| - target: aarch64-apple-darwin | |
| os: macos-latest | |
| name: kanuni-darwin-arm64 | |
| # Linux builds | |
| - target: x86_64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| name: kanuni-linux-x64 | |
| - target: aarch64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| name: kanuni-linux-arm64 | |
| # Windows builds | |
| - target: x86_64-pc-windows-msvc | |
| os: windows-latest | |
| name: kanuni-windows-x64.exe | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install cross-compilation tools | |
| if: matrix.target == 'aarch64-unknown-linux-gnu' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y gcc-aarch64-linux-gnu | |
| - name: Build release binary | |
| run: | | |
| cargo build --release --target ${{ matrix.target }} | |
| env: | |
| CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc | |
| - name: Prepare binary | |
| shell: bash | |
| run: | | |
| if [[ "${{ matrix.os }}" == "windows-latest" ]]; then | |
| cp target/${{ matrix.target }}/release/kanuni.exe ${{ matrix.name }} | |
| else | |
| cp target/${{ matrix.target }}/release/kanuni ${{ matrix.name }} | |
| fi | |
| # Create tarball for non-Windows | |
| if [[ "${{ matrix.os }}" != "windows-latest" ]]; then | |
| tar czf ${{ matrix.name }}.tar.gz ${{ matrix.name }} | |
| else | |
| # Create zip for Windows | |
| 7z a ${{ matrix.name }}.zip ${{ matrix.name }} | |
| fi | |
| - name: Generate SHA256 | |
| shell: bash | |
| run: | | |
| if [[ "${{ matrix.os }}" == "windows-latest" ]]; then | |
| certutil -hashfile ${{ matrix.name }}.zip SHA256 > ${{ matrix.name }}.zip.sha256 | |
| else | |
| shasum -a 256 ${{ matrix.name }}.tar.gz > ${{ matrix.name }}.tar.gz.sha256 | |
| fi | |
| - name: Upload Release Assets | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| TAG_NAME="${GITHUB_REF#refs/tags/}" | |
| if [[ "${{ matrix.os }}" == "windows-latest" ]]; then | |
| gh release upload "${TAG_NAME}" "${{ matrix.name }}.zip" "${{ matrix.name }}.zip.sha256" | |
| else | |
| gh release upload "${TAG_NAME}" "${{ matrix.name }}.tar.gz" "${{ matrix.name }}.tar.gz.sha256" | |
| fi | |
| publish-crate: | |
| name: Publish to crates.io | |
| needs: create-release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Publish to crates.io | |
| run: cargo publish --token ${{ secrets.CRATES_IO_TOKEN }} | |
| publish-npm: | |
| name: Publish to npm | |
| needs: [create-release, build-release] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Update package version | |
| working-directory: ./kanuni-npm | |
| run: | | |
| npm version ${{ needs.create-release.outputs.version }} --no-git-tag-version | |
| - name: Publish to npm | |
| working-directory: ./kanuni-npm | |
| run: npm publish | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| continue-on-error: true | |
| publish-docker: | |
| name: Publish Docker Image | |
| needs: [create-release] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| with: | |
| platforms: linux/amd64,linux/arm64 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: vlawyer/kanuni | |
| tags: | | |
| type=semver,pattern={{version}},value=${{ needs.create-release.outputs.version }} | |
| type=semver,pattern={{major}}.{{minor}},value=${{ needs.create-release.outputs.version }} | |
| type=semver,pattern={{major}},value=${{ needs.create-release.outputs.version }} | |
| type=raw,value=latest | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| update-homebrew: | |
| name: Update Homebrew Formula | |
| needs: [create-release, build-release] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout tap repository | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: v-lawyer/homebrew-tap | |
| token: ${{ secrets.HOMEBREW_TAP_TOKEN }} | |
| - name: Update Formula | |
| run: | | |
| # This would update the formula with new URLs and SHA256 | |
| echo "Updating Homebrew formula for version ${{ needs.create-release.outputs.version }}" | |
| # Script to update formula would go here | |
| continue-on-error: true |