name: Release # Triggered when a version tag is pushed, e.g. `git tag v0.1.0 && git push --tags`. # Publishes the crate to crates.io and creates a GitHub Release with prebuilt binaries. on: push: tags: - "v*" permissions: contents: write jobs: # --- publish to crates.io ------------------------------------------------- crates-io: runs-on: ubuntu-latest # Requires a CARGO_REGISTRY_TOKEN repo secret (Settings → Secrets → Actions). env: CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 # Skip when this version is already on crates.io — a version can never be # re-uploaded, so publishing one that exists (released by hand, or a re-run # of this job) is a guaranteed failure rather than a real problem. - name: Publish to crates.io if: ${{ env.CARGO_REGISTRY_TOKEN != '' }} run: | name=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].name') version=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version') if curl -sf -H 'User-Agent: cortiq-gateway-release' \ "https://crates.io/api/v1/crates/$name/$version" >/dev/null; then echo "$name $version is already published — skipping" else cargo publish fi # --- prebuilt binaries + GitHub Release ----------------------------------- release: runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: include: - os: ubuntu-latest target: x86_64-unknown-linux-gnu - os: macos-14 target: aarch64-apple-darwin - os: windows-latest target: x86_64-pc-windows-msvc steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: targets: ${{ matrix.target }} - uses: Swatinem/rust-cache@v2 - name: Build run: cargo build --release --target ${{ matrix.target }} - name: Package shell: bash run: | bin=cortiq-gateway [ "${{ runner.os }}" = "Windows" ] && bin=cortiq-gateway.exe staging="cortiq-gateway-${{ github.ref_name }}-${{ matrix.target }}" mkdir "$staging" cp "target/${{ matrix.target }}/release/$bin" "$staging"/ cp README.md LICENSE config/gateway.example.toml "$staging"/ if [ "${{ runner.os }}" = "Windows" ]; then 7z a "$staging.zip" "$staging" >/dev/null echo "ASSET=$staging.zip" >> "$GITHUB_ENV" else tar czf "$staging.tar.gz" "$staging" echo "ASSET=$staging.tar.gz" >> "$GITHUB_ENV" fi - name: Release uses: softprops/action-gh-release@v2 with: files: ${{ env.ASSET }} generate_release_notes: true