evtx 0.11.2

A Fast (and safe) parser for the Windows XML Event Log (EVTX) format
Documentation
name: release

on:
  push:
    # Enable when testing release infrastructure on a branch.
    # branches:
    # - gh-actions
    tags:
      - "v[0-9]+.[0-9]+.[0-9]+"
  workflow_dispatch:
    inputs:
      version:
        description: "Override version - useful to test workflows"
        required: true

jobs:
  create-release:
    name: create-release
    runs-on: ubuntu-latest
    steps:
      - name: Create artifacts directory
        run: mkdir artifacts

      - name: Mark manual
        if: inputs.version != ''
        run: |
          echo "MANUAL=1" >> $GITHUB_ENV

      - name: Get the release version from the tag
        if: env.VERSION == ''
        run: |
          echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
          echo "version is: ${{ env.VERSION }}"

      - name: Check for existing release
        if: env.MANUAL != '1'
        id: check_release
        uses: actions/github-script@v6
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            try {
              const tag = process.env.VERSION || context.ref.replace('refs/tags/', '');
              const release = await github.rest.repos.getReleaseByTag({
                owner: context.repo.owner,
                repo: context.repo.repo,
                tag: tag
              });

              core.setOutput('exists', 'true');
              core.setOutput('upload_url', release.data.upload_url);
              core.setOutput('id', release.data.id);
              console.log(`Release for tag ${tag} already exists, using existing release.`);
            } catch (error) {
              core.setOutput('exists', 'false');
              console.log(`Release for tag does not exist. Creating new release.`);
            }

      - name: Create GitHub release
        id: release
        if: env.MANUAL != '1' && steps.check_release.outputs.exists != 'true'
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ env.VERSION }}
          release_name: ${{ env.VERSION }}

      - name: Save release upload URL to artifact
        run: |
          if [ "${{ steps.check_release.outputs.exists }}" == "true" ]; then
            echo "${{ steps.check_release.outputs.upload_url }}" > artifacts/release-upload-url
          else
            echo "${{ steps.release.outputs.upload_url }}" > artifacts/release-upload-url
          fi

      - name: Save version number to artifact
        run: echo "${{ env.VERSION }}" > artifacts/release-version

      - name: Upload artifacts
        if: env.MANUAL != '1'
        uses: actions/upload-artifact@v4
        with:
          name: artifacts
          path: artifacts

  build-release:
    name: build-release
    needs: ["create-release"]
    runs-on: ${{ matrix.os }}
    env:
      TARGET_DIR: ./target
      RUST_BACKTRACE: 1
      MACOSX_DEPLOYMENT_TARGET: 10.12

    strategy:
      matrix:
        build:
          [
            linux,
            linux-aarch64,
            linux-static,
            macos-aarch64,
            macos-x86,
            windows,
          ]
        include:
          - build: linux
            os: ubuntu-22.04
            target: x86_64-unknown-linux-gnu
          - build: linux-aarch64
            os: ubuntu-22.04
            target: aarch64-unknown-linux-gnu
          - build: linux-static
            os: ubuntu-22.04
            target: x86_64-unknown-linux-musl
          - build: macos-aarch64
            os: macos-14
            target: aarch64-apple-darwin
          - build: macos-x86
            os: macos-15
            target: x86_64-apple-darwin
          - build: windows
            os: windows-2019
            target: x86_64-pc-windows-msvc

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 1

      - name: Install Rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: 1.92.0
          targets: ${{ matrix.target }}
          components: llvm-tools

      - name: Setup Rust environment (non-Windows)
        if: runner.os != 'Windows'
        shell: bash
        run: |
          echo "RUSTUP_HOME=$HOME/.rustup" >> $GITHUB_ENV
          echo "CARGO_HOME=$HOME/.cargo" >> $GITHUB_ENV
          LLVM_TOOLS_PATH=$(rustc --print sysroot)/lib/rustlib/${{ matrix.target }}/bin
          echo "PATH=$LLVM_TOOLS_PATH:$HOME/.cargo/bin:$PATH" >> $GITHUB_ENV

      - name: Set up Homebrew (macOS only)
        if: runner.os == 'macOS'
        id: set-up-homebrew
        uses: Homebrew/actions/setup-homebrew@master

      - name: Install LLVM 19 (macOS only)
        if: runner.os == 'macOS'
        run: |
          brew install llvm@19
          echo "$(brew --prefix llvm@19)/bin" >> $GITHUB_PATH

      - name: Install Cross toolchain (zig)
        if: matrix.build == 'macos-aarch64' || matrix.build == 'linux-aarch64'
        uses: goto-bus-stop/setup-zig@v2
        with:
          version: 0.11.0

      - name: Get release download URL
        if: env.MANUAL != '1'
        uses: actions/download-artifact@v4
        with:
          name: artifacts
          path: artifacts

      - name: Set release upload URL and release version
        if: env.MANUAL != '1'
        shell: bash
        run: |
          release_upload_url="$(cat artifacts/release-upload-url)"
          echo "RELEASE_UPLOAD_URL=$release_upload_url" >> $GITHUB_ENV
          echo "release upload url: $RELEASE_UPLOAD_URL"
          release_version="$(cat artifacts/release-version)"
          echo "RELEASE_VERSION=$release_version" >> $GITHUB_ENV
          echo "release version: $RELEASE_VERSION"

      - name: Build PGO Binary (Linux)
        if: matrix.build == 'linux'
        shell: bash
        run: |
          export TARGET=${{ matrix.target }}
          ./build_pgo.sh
        env:
          HOME: ${{ github.workspace }}

      - name: Build release binary (macOS)
        if: matrix.build == 'macos-x86' || matrix.build == 'macos-aarch64'
        run: |
          export TARGET=${{ matrix.target }}
          ./build_pgo.sh
        env:
          HOME: ${{ github.workspace }}

      - name: Build release binary (linux MUSL)
        if: matrix.build == 'linux-static'
        run: cargo build --target ${{ matrix.target }} --release --features wevt_templates

      - name: Build release binary (Windows)
        if: matrix.build == 'windows'
        run: cargo build --target ${{ matrix.target }} --release --features fast-alloc,wevt_templates

      - name: Build release binary (Linux AARCH64)
        if: matrix.build == 'linux-aarch64'
        run: |
          cargo install cargo-zigbuild
          cargo zigbuild --target ${{ matrix.target }} --release --features fast-alloc,wevt_templates

      - name: Build archive
        shell: bash
        run: |
          if [ "${{ matrix.build }}" = "windows" ]; then
            echo "ASSET=target/${{ matrix.target }}/release/evtx_dump.exe" >> $GITHUB_ENV
            echo "ASSET_NAME=evtx_dump-${{ env.RELEASE_VERSION }}.exe" >> $GITHUB_ENV
          else
            echo "ASSET=target/${{ matrix.target }}/release/evtx_dump" >> $GITHUB_ENV
            echo "ASSET_NAME=evtx_dump-${{ env.RELEASE_VERSION }}-${{ matrix.target }}" >> $GITHUB_ENV
          fi
      - name: Upload release archive
        uses: shogo82148/actions-upload-release-asset@v1
        if: env.MANUAL != '1'
        with:
          upload_url: ${{ env.RELEASE_UPLOAD_URL }}
          asset_path: ${{ env.ASSET }}
          asset_name: ${{ env.ASSET_NAME }}
          asset_content_type: application/octet-stream
          overwrite: true