diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f49d44f..e5c7b61 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,8 @@ jobs: with: toolchain: stable components: rustfmt, clippy - - uses: actions/cache@v4 + - name: Cache + uses: actions/cache@v4 with: path: | ~/.cargo/bin/ @@ -38,7 +39,7 @@ jobs: ~/.cargo/registry/cache/ ~/.cargo/git/db/ target/ - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + key: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.cachekey }}-${{ hashFiles('**/Cargo.lock') }} - name: rustfmt shell: bash run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..4b09989 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,170 @@ +name: Release +permissions: + contents: write +on: + push: + tags: + - "v*" +env: + CARGO_TERM_COLOR: always +jobs: + create_release: + runs-on: ubuntu-latest + outputs: + upload_url: ${{ steps.create_release.outputs.upload_url }} + release_id: ${{ steps.create_release.outputs.id }} + is_pre: ${{ steps.release_type.outputs.is_pre }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install jq + run: | + sudo apt-get update + sudo apt-get -y install jq + - name: Conventional Commit Changelog + id: conventional_commits + shell: bash + run: | + curl -Ls https://github.com/clog-tool/clog-cli/releases/download/v0.9.3/clog-v0.9.3-x86_64-unknown-linux-musl.tar.gz | tar xfz - + chmod +x ./clog + echo "About to delete tag $GITHUB_REF_NAME" + # delete current tag locally + git tag -d "$GITHUB_REF_NAME" + echo "Tag deleted!" + if [[ "$GITHUB_REF_NAME" == *"-"* ]]; then + echo "Calculate last tag using $GITHUB_REF_NAME" + git tag -l --sort version:refname + last_tag="$(git tag -l --sort version:refname | tail -n1)" + echo "Last tag: $last_tag" + else + echo "Calculate last tag" + git tag -l --sort version:refname + last_tag="$(git tag -l --sort version:refname | grep -v -- - | tail -n1)" + echo "Last tag: $last_tag" + fi + echo "Running..." + printf 'Using %s as last tag\n' "$last_tag" + echo 'CHANGELOG<> $GITHUB_ENV + ./clog --from="$last_tag" --setversion="$GITHUB_REF_NAME" >> $GITHUB_ENV + echo 'EOF' >> $GITHUB_ENV + - name: Create Release + id: create_release + uses: ncipollo/release-action@v1 + with: + draft: true + prerelease: ${{ steps.release_type.outputs.is_pre }} + body: ${{ env.CHANGELOG }} + token: ${{ secrets.GITHUB_TOKEN }} + lint: + runs-on: ubuntu-latest + continue-on-error: false + steps: + - uses: actions/checkout@v4 + - name: Install Rust Toolchain + id: rust_toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + components: rustfmt, clippy + - name: Cache + uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.cachekey }}-${{ hashFiles('**/Cargo.lock') }} + - name: rustfmt + shell: bash + run: | + cargo fmt -- --check + - name: Clippy + shell: bash + run: | + cargo clippy --locked --tests -- -D warnings + test: + runs-on: ubuntu-latest + continue-on-error: false + steps: + - uses: actions/checkout@v4 + - name: Install Rust Toolchain + id: rust_toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + - name: Cache + uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.cachekey }}-${{ hashFiles('**/Cargo.lock') }} + - name: Test + shell: bash + run: | + cargo test --release + build: + runs-on: ubuntu-latest + needs: create_release + steps: + - uses: actions/checkout@v4 + - name: Install Rust Toolchain + id: rust_toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + - name: Cache + uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ steps.rust-toolchain.outputs.cachekey }}-${{ hashFiles('**/Cargo.lock') }} + - name: "Build" + shell: bash + run: | + cargo build --release + - name: Pack + id: pack + shell: bash + run: | + files=( $(cargo metadata --no-deps --format-version 1 | jq -r '[.packages[].targets[] | select (.kind[] == "bin") | .name] | map("target/release/" + .) | .[]') ) + zip -j "rofi-tools.zip" $files + echo "filename=rofi-tools" >> $GITHUB_OUTPUT + - name: "Hash (Unix)" + run: | + echo "$(sha256sum ${{ steps.pack.outputs.filename }}.zip | cut -d ' ' -f 1)" > ${{ steps.pack.outputs.filename }}.zip.sha256sum + cat ${{ steps.pack.outputs.filename }}.zip.sha256sum + - name: Upload + uses: shogo82148/actions-upload-release-asset@v1 + with: + upload_url: ${{ needs.create_release.outputs.upload_url }} + asset_path: ./${{ steps.pack.outputs.filename }}.zip + asset_name: ${{ steps.pack.outputs.filename }}.zip + asset_content_type: application/zip + - name: Upload Hash + uses: shogo82148/actions-upload-release-asset@v1 + with: + upload_url: ${{ needs.create_release.outputs.upload_url }} + asset_path: ./${{ steps.pack.outputs.filename }}.zip.sha256sum + asset_name: ${{ steps.pack.outputs.filename }}.zip.sha256sum + asset_content_type: text/plain + publish_release: + runs-on: ubuntu-latest + needs: [create_release, lint, test, build] + steps: + - name: Publish Release + uses: eregon/publish-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + release_id: ${{ needs.create_release.outputs.release_id }} diff --git a/README.md b/README.md index 163fdb7..676ec4c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ -# rofi-tools +# Rofi Tools + +![GitHub Release](https://img.shields.io/github/v/release/szaffarano/rofi-tools?sort=date) +![GitHub License](https://img.shields.io/github/license/szaffarano/rofi-tools) +![CI](https://github.com/szaffarano/rofi-tools/actions/workflows/ci.yml/badge.svg) +![Release](https://github.com/szaffarano/rofi-tools/actions/workflows/release.yml/badge.svg) +[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit) Note: Only tested with [rofi-wayland](https://github.com/lbonn/rofi) although it should work with the [official version](https://github.com/davatorium/rofi).