Skip to content

Commit

Permalink
chore(ci): Add release pipeline (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
szaffarano authored Jan 26, 2025
1 parent 8c1778e commit f3909cd
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 3 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ jobs:
with:
toolchain: stable
components: rustfmt, clippy
- uses: actions/cache@v4
- name: Cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.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: |
Expand Down
170 changes: 170 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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<<EOF' >> $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 }}
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down

0 comments on commit f3909cd

Please sign in to comment.