From 782aa3353316b0e591e445575a9ac9a0d1289a7a Mon Sep 17 00:00:00 2001 From: Rabindra Dhakal Date: Thu, 5 Dec 2024 19:25:27 +0545 Subject: [PATCH] add workflow --- .github/dependabot.yaml | 6 ++ .github/workflows/auto-assign.yaml | 19 +++++ .github/workflows/nightly.yaml | 86 ++++++++++++++++++++++ .github/workflows/release.yaml | 112 +++++++++++++++++++++++++++++ CHANGELOG.md | 16 +++++ Cargo.lock | 2 +- Cargo.toml | 2 +- build.rs | 21 ++++++ cliff.toml | 67 +++++++++++++++++ 9 files changed, 329 insertions(+), 2 deletions(-) create mode 100644 .github/dependabot.yaml create mode 100644 .github/workflows/auto-assign.yaml create mode 100644 .github/workflows/nightly.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 CHANGELOG.md create mode 100644 build.rs create mode 100644 cliff.toml diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml new file mode 100644 index 0000000..5ace460 --- /dev/null +++ b/.github/dependabot.yaml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/auto-assign.yaml b/.github/workflows/auto-assign.yaml new file mode 100644 index 0000000..0a895eb --- /dev/null +++ b/.github/workflows/auto-assign.yaml @@ -0,0 +1,19 @@ +name: Auto Assign +on: + issues: + types: [opened] + pull_request: + types: [opened] +jobs: + run: + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - name: 'Auto-assign issue' + uses: pozil/auto-assign-issue@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + assignees: QaidVoid + numOfAssignee: 1 diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml new file mode 100644 index 0000000..6ea5f22 --- /dev/null +++ b/.github/workflows/nightly.yaml @@ -0,0 +1,86 @@ +name: soar-dl nightly + +on: + push: + branches: + - main + workflow_dispatch: + +permissions: + contents: write + +jobs: + remove-nightly-tag: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Remove existing nightly tag + run: | + gh release delete nightly --cleanup-tag || true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + publish-nightly: + name: Publish nightly binaries + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + build: + - { + NAME: x86_64-linux, + TARGET: x86_64-unknown-linux-musl, + } + - { + NAME: aarch64-linux, + 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: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + --allow-unauthenticated musl-tools b3sum + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.build.TARGET }} + + - name: Install cross-compilation tools + uses: taiki-e/setup-cross-toolchain-action@v1 + with: + target: ${{ matrix.build.TARGET }} + + - name: Build + run: SOAR_NIGHTLY=1 cargo build --release --locked --target ${{ matrix.build.TARGET }} + + - name: Prepare nightly binary + shell: bash + run: | + mkdir -p nightly + cp "target/${{ matrix.build.TARGET }}/release/soar-dl" nightly/soar-dl-nightly-${{ matrix.build.NAME }} + b3sum nightly/soar-dl-nightly-${{ matrix.build.NAME }} > nightly/soar-dl-nightly-${{ matrix.build.NAME }}.b3sum + + - name: Upload nightly binary + uses: softprops/action-gh-release@v2 + with: + files: nightly/* + tag_name: nightly + name: ${{ steps.version.outputs.version }} + body: "This is an automated nightly build of soar-dl." + prerelease: true + draft: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..7475f18 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,112 @@ +name: soar-dl release + +on: + push: + tags: + - "v*.*.*" +permissions: + contents: write + +jobs: + generate-changelog: + name: Generate changelog + 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 + with: + config: cliff.toml + args: -vv --latest --no-exec --github-repo ${{ github.repository }} + publish-binaries: + name: Publish binaries + needs: generate-changelog + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + build: + - { + NAME: x86_64-linux, + TARGET: x86_64-unknown-linux-musl, + } + - { + NAME: aarch64-linux, + 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: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.build.TARGET }} + + - name: Install cross-compilation tools + uses: taiki-e/setup-cross-toolchain-action@v1 + with: + target: ${{ matrix.build.TARGET }} + + - name: Build + 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-dl" release/ + + - name: Create release artifacts + shell: bash + run: | + cp release/soar-dl soar-dl-${{ matrix.build.NAME }} + b3sum soar-dl-${{ matrix.build.NAME }} \ + > soar-dl-${{ matrix.build.NAME }}.b3sum + tar -czvf soar-dl-${{ matrix.build.NAME }}.tar.gz \ + release/ + b3sum soar-dl-${{ matrix.build.NAME }}.tar.gz \ + > soar-dl-${{ matrix.build.NAME }}.tar.gz.b3sum + + - name: Publish to GitHub + if: ${{ !contains(github.ref, '-') }} + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: soar-dl-${{ matrix.build.NAME }}* + file_glob: true + overwrite: true + tag: ${{ github.ref }} + release_name: "soar-dl 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 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: soar-dl-${{ env.RELEASE_VERSION }}-${{ matrix.build.NAME }}* + file_glob: true + overwrite: true + tag: ${{ github.ref }} + release_name: "Pre-release v${{ env.RELEASE_VERSION }}" + prerelease: true diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..ee0e505 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,16 @@ +# Changelog + +## [0.1.1] - 2024-12-05 + +### Added + +- Add workflow + +### Changed + +- Handle tags +- Initialize soar-dl +- Initial commit + + + diff --git a/Cargo.lock b/Cargo.lock index 641f384..a02b2f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1098,7 +1098,7 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "soar-dl" -version = "0.1.0" +version = "0.1.1" dependencies = [ "clap", "futures", diff --git a/Cargo.toml b/Cargo.toml index 43db67a..150d256 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "soar-dl" -version = "0.1.0" +version = "0.1.1" authors = ["Rabindra Dhakal "] description = "A fast download manager" license = "MIT" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..80de9aa --- /dev/null +++ b/build.rs @@ -0,0 +1,21 @@ +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); + } +} diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 0000000..0d62a8a --- /dev/null +++ b/cliff.toml @@ -0,0 +1,67 @@ +# git-cliff ~ configuration file +# https://git-cliff.org/docs/configuration + +[changelog] +# template for the changelog header +header = """ +# Changelog\n +""" +# template for the changelog body +# https://keats.github.io/tera/docs/#introduction +body = """ +{% if version -%} + ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} +{% else -%} + ## [Unreleased] +{% endif -%} +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | upper_first }} + {% for commit in commits %} + - {{ commit.message | split(pat="\n") | first | upper_first | trim }}\ + {% endfor %} +{% endfor %}\n +""" +# template for the changelog footer +footer = """ +{% for release in releases -%} + {% if release.version -%} + {% if release.previous.version -%} + [{{ release.version | trim_start_matches(pat="v") }}]: \ + https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}\ + /compare/{{ release.previous.version }}..{{ release.version }} + {% endif -%} + {% else -%} + [unreleased]: https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}\ + /compare/{{ release.previous.version }}..HEAD + {% endif -%} +{% endfor %} + +""" +# remove the leading and trailing whitespace from the templates +trim = true + +[git] +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = true +# filter out the commits that are not conventional +filter_unconventional = false +# regex for parsing and grouping commits +commit_parsers = [ + { message = "^[a|A]dd", group = "Added" }, + { message = "^[s|S]upport", group = "Added" }, + { message = "^[r|R]emove", group = "Removed" }, + { message = "^.*: add", group = "Added" }, + { message = "^.*: support", group = "Added" }, + { message = "^.*: remove", group = "Removed" }, + { message = "^.*: delete", group = "Removed" }, + { message = "^test", group = "Fixed" }, + { message = "^fix", group = "Fixed" }, + { message = "^.*: fix", group = "Fixed" }, + { message = "^.*", group = "Changed" }, +] +# filter out the commits that are not matched by commit parsers +filter_commits = false +# sort the tags topologically +topo_order = false +# sort the commits inside sections by oldest/newest order +sort_commits = "newest"