lightswitch 0.6.0

CPU profiler as a library for Linux suitable for on-demand and continuous profiling
name: release
on:
    push:
        tags:
            - "v*.*.*"
        # branches:
        #   - main
    # pull_request:

jobs:
    build:
        strategy:
            matrix:
                config:
                    [
                        { os: ubuntu-22.04, target: x86_64-unknown-linux-gnu },
                        {
                            os: ubuntu-22.04-arm,
                            target: aarch64-unknown-linux-gnu,
                        },
                    ]

        runs-on: ${{ matrix.config.os }}
        env:
            TARGET: "${{ matrix.config.target }}"
        permissions:
            id-token: write
            contents: read
            packages: write

        steps:
            - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
            - uses: DeterminateSystems/nix-installer-action@3138316df39ed29be04236d7ffc686fa525866aa # v23
            - uses: DeterminateSystems/flakehub-cache-action@83282a8aef353db1d659d3bacf4a28b6683de0b3 # v2
            - name: Show nix version
              run: nix --version
            - name: Set up nix dev env
              run: nix develop --command echo 0
            - name: Run `cargo test`
              run: nix develop --command cargo test --workspace
            - name: Run `cargo hack`
              run: nix develop --command just hack
            - name: Build container image
              run: nix build .#container
            - name: Upload container image to GitHub's container registry
              run: |
                  export CONTAINERS_REGISTRIES_CONF=/dev/null
                  nix develop --ignore-environment --keep-env-var CONTAINERS_REGISTRIES_CONF --command skopeo copy --dest-creds="${{ github.repository_owner }}:${{ github.token }}" docker-archive:./result docker://ghcr.io/javierhonduco/lightswitch:${{ github.ref_name }}
                  nix develop --ignore-environment --keep-env-var CONTAINERS_REGISTRIES_CONF --command skopeo copy --dest-creds="${{ github.repository_owner }}:${{ github.token }}" docker-archive:./result docker://ghcr.io/javierhonduco/lightswitch:latest
            - name: Upload container
              uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
              with:
                  name: lightswitch-container-${{ matrix.config.target }}
                  path: ./result
            - name: Build `lightswitch` statically linked with glibc
              run: nix develop --ignore-environment --keep TARGET --command bash -c 'RUSTFLAGS="-C target-feature=+crt-static" cargo build --release --target $TARGET'
            - name: Upload static binary
              uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
              with:
                  name: lightswitch-static-glibc-${{ matrix.config.target }}
                  path: ./target/${{ matrix.config.target }}/release/lightswitch

    release:
        runs-on: ubuntu-22.04
        needs: [build]
        permissions:
            contents: write
        steps:
            - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
            - name: Display artifacts structure
              run: tree -h
            - name: Rename artifacts
              run: |
                  mkdir renamed
                  cp lightswitch-container-x86_64-unknown-linux-gnu/result renamed/lightswitch-container-x86_64-unknown-linux-gnu
                  cp lightswitch-static-glibc-x86_64-unknown-linux-gnu/lightswitch renamed/lightswitch-static-glibc-x86_64-unknown-linux-gnu
                  cp lightswitch-container-aarch64-unknown-linux-gnu/result renamed/lightswitch-container-aarch64-unknown-linux-gnu
                  cp lightswitch-static-glibc-aarch64-unknown-linux-gnu/lightswitch renamed/lightswitch-static-glibc-aarch64-unknown-linux-gnu

            - name: Create release
              uses: softprops/action-gh-release@efb35369e0ad2afab669f228072c1b0d510eae64 # v3.0.3
              with:
                  files: |
                      renamed/lightswitch-container-x86_64-unknown-linux-gnu
                      renamed/lightswitch-static-glibc-x86_64-unknown-linux-gnu
                      renamed/lightswitch-container-aarch64-unknown-linux-gnu
                      renamed/lightswitch-static-glibc-aarch64-unknown-linux-gnu

    publish:
        runs-on: ubuntu-22.04
        needs: [build]
        permissions:
            contents: write
        steps:
            - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
            - uses: DeterminateSystems/nix-installer-action@3138316df39ed29be04236d7ffc686fa525866aa # v23
            - uses: DeterminateSystems/flakehub-cache-action@83282a8aef353db1d659d3bacf4a28b6683de0b3 # v2
            - name: Show nix version
              run: nix --version
            - name: Set up nix dev env
              run: nix develop --command echo 0
            - name: Publish workspace dependencies
              run: nix develop --command cargo publish --workspace --exclude lightswitch
              env:
                  CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
            - name: Publish main crate
              run: nix develop --command cargo publish --package lightswitch
              env:
                  CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}