Skip to content

Commit

Permalink
ci(workflow): update release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
QaidVoid committed Nov 12, 2024
1 parent 80cfceb commit e0b9a58
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 28 deletions.
29 changes: 15 additions & 14 deletions .github/workflows/nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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
Expand All @@ -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
Expand Down
32 changes: 18 additions & 14 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ 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:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Generate a changelog
uses: orhun/git-cliff-action@main
id: git-cliff
Expand All @@ -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: |
Expand All @@ -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
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit e0b9a58

Please sign in to comment.