Skip to content

Commit

Permalink
ci: improve release pipeline (#352)
Browse files Browse the repository at this point in the history
* fix: bump ubuntu action with workaround

* feat: add git-cliff to generate release notes

* feat: add git-cliff to generate release notes

* feat: use pinned ubuntu version in ci

* feat: use pinned ubuntu version in ci
  • Loading branch information
hcavarsan authored Jan 15, 2025
1 parent ee2a227 commit 1879ea6
Show file tree
Hide file tree
Showing 3 changed files with 227 additions and 31 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ env:
jobs:
eslint-format:
name: ESLint
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -43,13 +43,16 @@ jobs:

rust-format:
name: rustfmt
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y libgtk-3-dev
run: |
echo "deb http://gb.archive.ubuntu.com/ubuntu jammy main" | sudo tee /etc/apt/sources.list.d/ubuntu-jammy-main.list
sudo apt-get update
sudo apt-get install -y libgtk-3-dev
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
Expand All @@ -65,13 +68,16 @@ jobs:

rust-lint:
name: Clippy
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libayatana-appindicator3-dev librsvg2-dev libssl-dev libsoup2.4-dev
run: |
echo "deb http://gb.archive.ubuntu.com/ubuntu jammy main" | sudo tee /etc/apt/sources.list.d/ubuntu-jammy-main.list
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libayatana-appindicator3-dev librsvg2-dev libssl-dev libsoup2.4-dev
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
Expand All @@ -83,7 +89,7 @@ jobs:
permissions:
contents: write
packages: write
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down
169 changes: 144 additions & 25 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,71 @@ name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
trigger_homebrew:
description: 'Trigger Homebrew update'
required: true
type: boolean
default: false
- "v[0-9]+.[0-9]+.[0-9]+*"
env:
TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
VITE_ENV: "production"
TAURI_DEBUG: "false"

jobs:
validate-version:
runs-on: ubuntu-24.04
steps:
- name: Validate version format
run: |
if ! [[ ${{ github.ref_name }} =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$ ]]; then
echo "Invalid version format. Must be vX.Y.Z or vX.Y.Z-suffix"
exit 1
fi
create-release-draft:
needs: validate-version
permissions:
contents: write
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
outputs:
release_id: ${{ steps.create_release.outputs.id }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create release draft
with:
fetch-depth: 0

- name: Check existing release
id: check_release
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Creating release draft for tag: ${{ github.ref_name }}"
gh release create ${{ github.ref_name }} --draft --title "KFtray - ${{ github.ref_name }}" --notes "See the assets to download this version and install."
release_id=$(gh api repos/${{ github.repository }}/releases/tags/${{ github.ref_name }} --jq .id || echo "")
if [ ! -z "$release_id" ]; then
echo "Release already exists with ID: $release_id"
echo "release_exists=true" >> $GITHUB_OUTPUT
echo "existing_release_id=$release_id" >> $GITHUB_OUTPUT
else
echo "release_exists=false" >> $GITHUB_OUTPUT
fi
- name: Create release draft
id: create_release
if: steps.check_release.outputs.release_exists != 'true'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
release_name: "KFtray - ${{ github.ref_name }}"
draft: true
prerelease: false

- name: Set release ID output
run: |
if [ "${{ steps.check_release.outputs.release_exists }}" == "true" ]; then
echo "id=${{ steps.check_release.outputs.existing_release_id }}" >> $GITHUB_OUTPUT
else
echo "id=${{ steps.create_release.outputs.id }}" >> $GITHUB_OUTPUT
fi
kftray-tauri:
needs: create-release-draft
Expand All @@ -38,12 +75,12 @@ jobs:
strategy:
matrix:
include:
- os: ubuntu-22.04
- os: ubuntu-24.04
arch: arm64
runner: ubicloud-standard-4-arm
rust_target: aarch64-unknown-linux-gnu
tauri_args: "--target aarch64-unknown-linux-gnu --bundles appimage,updater --verbose"
- os: ubuntu-22.04
- os: ubuntu-24.04
arch: amd64
rust_target: x86_64-unknown-linux-gnu
tauri_args: "--target x86_64-unknown-linux-gnu --bundles appimage,updater --verbose"
Expand Down Expand Up @@ -99,9 +136,9 @@ jobs:
path: |
$(pnpm store path --silent)
**/node_modules
key: ${{ runner.OS }}-pnpm-${{ runner.ARCH }}-${{ hashFiles('**/pnpm-lock.yaml') }}
key: ${{ runner.OS }}-pnpm-${{ matrix.arch }}-${{ hashFiles('**/pnpm-lock.yaml', '**/package.json') }}
restore-keys: |
${{ runner.OS }}-pnpm-${{ runner.ARCH }}-
${{ runner.OS }}-pnpm-${{ matrix.arch }}-
- name: Set up Visual Studio shell
if: matrix.os == 'windows-latest' && matrix.arch == 'arm64'
Expand All @@ -110,10 +147,12 @@ jobs:
arch: amd64_arm64

- name: Setup platform-specific dependencies
if: matrix.os == 'ubuntu-22.04'
if: matrix.os == 'ubuntu-24.04'
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libayatana-appindicator3-dev librsvg2-dev libssl-dev
echo "deb http://gb.archive.ubuntu.com/ubuntu jammy main" | sudo tee /etc/apt/sources.list.d/ubuntu-jammy-main.list
for i in {1..3}; do
sudo apt-get update && sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libayatana-appindicator3-dev librsvg2-dev libssl-dev && break || sleep 5
done
- name: Reconfigure Rust targets
run: |
Expand All @@ -124,6 +163,30 @@ jobs:
fi
shell: bash
- name: Build kftray-tauri Desktop App
uses: tauri-apps/tauri-action@v0
id: tauri_build
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_OPTIONS: --max-old-space-size=6000
ENABLE_CODE_SIGNING: ${{ secrets.APPLE_CERTIFICATE }}
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
with:
tagName: ${{ github.ref_name }}
releaseName: "KFtray - ${{ github.ref_name }}"
releaseBody: "See the assets to download this version and install."
releaseDraft: true
prerelease: false
updaterJsonKeepUniversal: true
args: ${{ matrix.tauri_args }}

- name: Retry Build on Failure
if: steps.tauri_build.outcome == 'failure'
uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -151,12 +214,12 @@ jobs:
strategy:
matrix:
include:
- os: ubuntu-22.04
- os: ubuntu-24.04
arch: arm64
runner: ubicloud-standard-4-arm
rust_target: aarch64-unknown-linux-gnu
os_name: linux
- os: ubuntu-22.04
- os: ubuntu-24.04
arch: amd64
rust_target: x86_64-unknown-linux-gnu
os_name: linux
Expand Down Expand Up @@ -217,8 +280,9 @@ jobs:
${{ runner.OS }}-pnpm-${{ runner.ARCH }}-
- name: Setup platform-specific dependencies
if: matrix.os == 'ubuntu-22.04'
if: matrix.os == 'ubuntu-24.04'
run: |
echo "deb http://gb.archive.ubuntu.com/ubuntu jammy main" | sudo tee /etc/apt/sources.list.d/ubuntu-jammy-main.list
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libayatana-appindicator3-dev librsvg2-dev libssl-dev
Expand Down Expand Up @@ -295,7 +359,7 @@ jobs:
permissions:
contents: write
packages: write
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
steps:
- name: Checkout repository
Expand Down Expand Up @@ -325,13 +389,68 @@ jobs:
ghcr.io/${{ github.repository_owner }}/kftray-server:${{ github.sha }}
ghcr.io/${{ github.repository_owner }}/kftray-server:${{ github.ref_name }}
ghcr.io/${{ github.repository_owner }}/kftray-server:latest
update-release:
needs: [kftray-tauri, kftui, kftray-server, create-release-draft]
permissions:
contents: write
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Generate changelog
uses: orhun/git-cliff-action@v4
id: git-cliff
with:
config: cliff.toml
args: --latest --strip header
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Update release notes
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: ${{ needs.create-release-draft.outputs.release_id }},
body: `${{ steps.git-cliff.outputs.content }}`
});
} catch (error) {
console.error('Failed to update release notes:', error);
if (error.status === 404) {
console.log('Release not found, retrying after short delay...');
await new Promise(resolve => setTimeout(resolve, 5000));
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: ${{ needs.create-release-draft.outputs.release_id }},
body: `${{ steps.git-cliff.outputs.content }}`
});
} else {
throw error;
}
}
- name: Publish release
uses: eregon/publish-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ needs.create-release-draft.outputs.release_id }}

update-homebrew:
needs: [kftray-tauri]
needs: [update-release]
permissions:
contents: write
runs-on: macos-latest
if: |
github.event.inputs.trigger_homebrew == 'true' &&
startsWith(github.ref, 'refs/tags/v') &&
!contains(github.ref, '-beta') &&
!contains(github.ref, '-alpha')
Expand Down
71 changes: 71 additions & 0 deletions cliff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# git-cliff ~ configuration file
# https://git-cliff.org/docs/configuration

[changelog]
# template for the changelog header
header = """
# Changelog\n
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\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 %}
<!-- generated by git-cliff -->
"""
# 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"

0 comments on commit 1879ea6

Please sign in to comment.