chore(ci): Add release pipeline (#10) #2
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |