diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml index 13e2f7c..0ff2d14 100644 --- a/.github/workflows/nightly.yaml +++ b/.github/workflows/nightly.yaml @@ -23,27 +23,29 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} publish-nightly: name: Publish nightly binaries - runs-on: ${{ matrix.build.os }} + runs-on: ubuntu-latest strategy: fail-fast: false matrix: build: - { NAME: x86_64-linux, - OS: ubuntu-22.04, - TOOLCHAIN: stable, TARGET: x86_64-unknown-linux-musl, } - { NAME: aarch64-linux, - OS: ubuntu-22.04, - TOOLCHAIN: stable, TARGET: aarch64-unknown-linux-musl, } steps: - name: Checkout uses: actions/checkout@v4 + - name: Get version info + id: version + run: | + SHORT_SHA=$(git rev-parse --short HEAD) + echo "version=nightly-${SHORT_SHA}" >> $GITHUB_OUTPUT + - name: Install dependencies shell: bash run: | @@ -52,18 +54,17 @@ jobs: --allow-unauthenticated musl-tools b3sum - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.build.TARGET }} + + - name: Install cross-compilation tools + uses: taiki-e/setup-cross-toolchain-action@v1 with: - toolchain: ${{ matrix.build.TOOLCHAIN }} target: ${{ matrix.build.TARGET }} - override: true - name: Build - uses: actions-rs/cargo@v1 - with: - use-cross: true - command: build - args: --release --locked --target ${{ matrix.build.TARGET }} + run: SOAR_NIGHTLY=1 cargo build --release --locked --target ${{ matrix.build.TARGET }} - name: Prepare nightly binary shell: bash @@ -77,7 +78,7 @@ jobs: with: files: nightly/* tag_name: nightly - name: "Nightly Build" + name: ${{ steps.version.outputs.version }} body: "This is an automated nightly build of Soar." prerelease: true draft: false diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index a1b60f0..0f99287 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -10,7 +10,7 @@ permissions: jobs: generate-changelog: name: Generate changelog - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest outputs: release_body: ${{ steps.git-cliff.outputs.content }} steps: @@ -18,6 +18,7 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + - name: Generate a changelog uses: orhun/git-cliff-action@main id: git-cliff @@ -27,53 +28,54 @@ jobs: publish-binaries: name: Publish binaries needs: generate-changelog - runs-on: ${{ matrix.build.os }} + runs-on: ubuntu-latest strategy: fail-fast: false matrix: build: - { NAME: x86_64-linux, - OS: ubuntu-22.04, - TOOLCHAIN: stable, TARGET: x86_64-unknown-linux-musl, } - { NAME: aarch64-linux, - OS: ubuntu-22.04, - TOOLCHAIN: stable, TARGET: aarch64-unknown-linux-musl, } steps: - name: Checkout uses: actions/checkout@v4 + - name: Set the release version shell: bash run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV + - name: Install dependencies shell: bash run: | sudo apt-get update sudo apt-get install -y --no-install-recommends \ --allow-unauthenticated musl-tools b3sum + - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.build.TARGET }} + + - name: Install cross-compilation tools + uses: taiki-e/setup-cross-toolchain-action@v1 with: - toolchain: ${{ matrix.build.TOOLCHAIN }} target: ${{ matrix.build.TARGET }} - override: true + - name: Build - uses: actions-rs/cargo@v1 - with: - use-cross: true - command: build - args: --release --locked --target ${{ matrix.build.TARGET }} + run: cargo build --release --locked --target ${{ matrix.build.TARGET }} + - name: Prepare release assets shell: bash run: | mkdir -p release cp {LICENSE,README.md,CHANGELOG.md} release/ cp "target/${{ matrix.build.TARGET }}/release/soar" release/ + - name: Create release artifacts shell: bash run: | @@ -84,6 +86,7 @@ jobs: release/ b3sum soar-${{ matrix.build.NAME }}.tar.gz \ > soar-${{ matrix.build.NAME }}.tar.gz.b3sum + - name: Publish to GitHub if: ${{ !contains(github.ref, '-') }} uses: svenstaro/upload-release-action@v2 @@ -95,6 +98,7 @@ jobs: tag: ${{ github.ref }} release_name: "Soar v${{ env.RELEASE_VERSION }}" body: "${{ needs.generate-changelog.outputs.release_body }}" + - name: Publish to GitHub (pre-release) if: ${{ contains(github.ref, '-') }} uses: svenstaro/upload-release-action@v2 diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..868cb95 --- /dev/null +++ b/build.rs @@ -0,0 +1,18 @@ +use std::process::Command; + +fn main() { + if std::env::var("SOAR_NIGHTLY").is_ok() { + let commit_sha = Command::new("git") + .arg("rev-parse") + .arg("--short") + .arg("HEAD") + .output() + .expect("Failed to get git commit SHA") + .stdout; + + let commit_sha = String::from_utf8(commit_sha).expect("Invalid UTF-8 output").trim().to_string(); + + println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:rustc-env=CARGO_PKG_VERSION=nightly-{}", commit_sha); + } +}