mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-01-11 22:12:53 +01:00
ci(goreleaser): automate releases on tag push
This commit adapts a basic GoReleaser configuration to work for Rust projects, allowing us to automatically create releases on GitHub via GitHub Actions whenever a semantic version tag (vX.Y.Z) is pushed, with custom changelogs generated by kokai, and zipped binaries attached to the release. Those zipped binaries are then used to create a Scoop release in a custom bucket. Due to the way that Scoop uses shims, when running the 'komorebic start' command, there needs to be an explicit check to try and determine if komorebi has been installed via Scoop. This is done by checking for a komorebi.ps1 shim in the Path. Scoop shims cannot be used with the Start-Process PS command, so instead, we replicate in code what the komorebi.ps1 script is doing (finding the path to the current version of the executable), and then passing the entire path to the Start-Process command that gets called to start komorebi. The README has been updated to reflect the availability of prebuilt binaries and how to get started with them.
This commit is contained in:
39
.github/workflows/windows.yaml
vendored
39
.github/workflows/windows.yaml
vendored
@@ -1,4 +1,4 @@
|
||||
# Adapted from the rustup workflows
|
||||
# Adapted from https://github.com/rust-lang/rustup/blob/master/.github/workflows/windows-builds-on-master.yaml
|
||||
|
||||
name: Windows
|
||||
|
||||
@@ -11,15 +11,15 @@ on:
|
||||
- master
|
||||
- feature/*
|
||||
- hotfix/*
|
||||
tags:
|
||||
- v*
|
||||
schedule:
|
||||
- cron: "30 0 * * 1" # Every Monday at half past midnight UTC skip-pr skip-stable
|
||||
- cron: "30 0 * * 1" # Every Monday at half past midnight UTC
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
runs-on: windows-latest
|
||||
env:
|
||||
RUSTFLAGS: -Ctarget-feature=+crt-static
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@@ -27,7 +27,6 @@ jobs:
|
||||
- x86_64-pc-windows-msvc
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
# v2 defaults to a shallow checkout, but we need at least to the previous tag
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Prep cargo dirs
|
||||
@@ -35,29 +34,18 @@ jobs:
|
||||
New-Item "${env:USERPROFILE}\.cargo\registry" -ItemType Directory -Force
|
||||
New-Item "${env:USERPROFILE}\.cargo\git" -ItemType Directory -Force
|
||||
shell: powershell
|
||||
- name: Install mingw
|
||||
run: |
|
||||
# We retrieve mingw from the Rust CI buckets
|
||||
# Disable the download progress bar which can cause perf issues
|
||||
$ProgressPreference = "SilentlyContinue"
|
||||
Invoke-WebRequest ${{ matrix.mingw }} -OutFile mingw.7z
|
||||
7z x -y mingw.7z -oC:\msys64 | Out-Null
|
||||
del mingw.7z
|
||||
echo "C:\msys64\usr\bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
|
||||
echo "C:\msys64\${{ matrix.mingwdir }}\bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
|
||||
shell: powershell
|
||||
if: matrix.mingw != ''
|
||||
- name: Set environment variables appropriately for the build
|
||||
run: |
|
||||
echo "%USERPROFILE%\.cargo\bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
|
||||
echo "TARGET=${{ matrix.target }}" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8
|
||||
echo "SKIP_TESTS=" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8
|
||||
- name: Cache cargo registry and git trees
|
||||
- name: Cache cargo registry, git trees and binaries
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
~/.cargo/bin
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||
- name: Get rustc commit hash
|
||||
id: cargo-target-cache
|
||||
@@ -95,3 +83,18 @@ jobs:
|
||||
target/${{ matrix.target }}/release/komorebi.exe
|
||||
target/${{ matrix.target }}/release/komorebic.exe
|
||||
retention-days: 7
|
||||
- name: Generate changelog
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
shell: bash
|
||||
run: |
|
||||
if ! type kokai >/dev/null; then cargo install --locked kokai --force; fi
|
||||
kokai release --no-emoji --add-links github:commits,issues --ref "$(git tag --points-at HEAD)" >"CHANGELOG.md"
|
||||
- name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v2
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
with:
|
||||
version: latest
|
||||
args: release --skip-validate --rm-dist --release-notes=CHANGELOG.md
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
SCOOP_TOKEN: ${{ secrets.SCOOP_TOKEN }}
|
||||
|
||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,2 +1,6 @@
|
||||
/target
|
||||
.idea
|
||||
/dist
|
||||
/target
|
||||
CHANGELOG.md
|
||||
dummy.go
|
||||
komorebi.ahk
|
||||
57
.goreleaser.yml
Normal file
57
.goreleaser.yml
Normal file
@@ -0,0 +1,57 @@
|
||||
# Adapted from https://jondot.medium.com/shipping-rust-binaries-with-goreleaser-d5aa42a46be0
|
||||
project_name: komorebi
|
||||
|
||||
before:
|
||||
hooks:
|
||||
- powershell.exe -Command "New-Item -Path . -Name dummy.go -ItemType file -Force"
|
||||
- powershell.exe -Command "Add-Content -Path .\dummy.go -Value 'package main'"
|
||||
- powershell.exe -Command "Add-Content -Path .\dummy.go -Value 'func main() {}'"
|
||||
|
||||
builds:
|
||||
- id: komorebi
|
||||
main: dummy.go
|
||||
goos: ["windows"]
|
||||
goarch: ["amd64"]
|
||||
binary: komorebi
|
||||
hooks:
|
||||
post:
|
||||
- mkdir -p dist/windows_amd64
|
||||
- cp ".\target\x86_64-pc-windows-msvc\release\komorebi.exe" ".\dist\komorebi_windows_amd64\komorebi.exe"
|
||||
- id: komorebic
|
||||
main: dummy.go
|
||||
goos: ["windows"]
|
||||
goarch: ["amd64"]
|
||||
binary: komorebic
|
||||
hooks:
|
||||
post:
|
||||
- mkdir -p dist/windows_amd64
|
||||
- cp ".\target\x86_64-pc-windows-msvc\release\komorebic.exe" ".\dist\komorebic_windows_amd64\komorebic.exe"
|
||||
|
||||
archives:
|
||||
- replacements:
|
||||
windows: pc-windows-msvc
|
||||
amd64: x86_64
|
||||
format: zip
|
||||
name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Arch }}-{{ .Os }}"
|
||||
files:
|
||||
- LICENSE
|
||||
- komorebi.sample.ahk
|
||||
- CHANGELOG.md
|
||||
|
||||
checksum:
|
||||
name_template: checksums.txt
|
||||
|
||||
changelog:
|
||||
sort: asc
|
||||
|
||||
scoop:
|
||||
bucket:
|
||||
owner: LGUG2Z
|
||||
name: komorebi-bucket
|
||||
token: "{{ .Env.SCOOP_TOKEN }}"
|
||||
homepage: https://github.com/LGUG2Z/komorebi
|
||||
description: A tiling window manager for Windows
|
||||
license: MIT
|
||||
post_install:
|
||||
- Write-Host "Run 'cp $original_dir\komorebi.sample.ahk $Env:UserProfile\komorebi.ahk' to get started with the sample configuration"
|
||||
- Write-Host "Once you have a configuration file in place, you can run 'komorebic start' to start the window manager"
|
||||
35
README.md
35
README.md
@@ -59,11 +59,29 @@ This means that:
|
||||
|
||||
## Getting Started
|
||||
|
||||
This project is still heavily under development and there are no prebuilt binaries available yet.
|
||||
Prebuilt binaries are available on the [releases page](https://github.com/LGUG2Z/komorebi/releases) in a `zip` archive.
|
||||
Once downloaded, you will need to move the `komorebi.exe` and `komorebic.exe` binaries to a directory in your `Path` (
|
||||
you can see these directories by running `$Env:Path.split(";")` at a PowerShell prompt).
|
||||
|
||||
If you would like to use _komorebi_, you will need
|
||||
a [working Rust development environment on Windows 10](https://rustup.rs/). If you are using
|
||||
the `x86_64-pc-windows-msvc` toolchain, make sure you have also installed
|
||||
Alternatively, you may add a new directory to your `Path`
|
||||
using [`setx`](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/setx) or the Environment
|
||||
Variables pop up in System Properties Advanced (which can be launched with `SystemPropertiesAdvanced.exe` at a
|
||||
PowerShell prompt), and then move the binaries to that directory.
|
||||
|
||||
If you use the [Scoop](https://scoop.sh/) command line installer, you can run the following commands to install the
|
||||
binaries from the latest GitHub Release:
|
||||
|
||||
```
|
||||
scoop bucket add komorebi https://github.com/LGUG2Z/komorebi-bucket
|
||||
scoop install komorebi
|
||||
```
|
||||
|
||||
If you install _komorebi_ using Scoop, the binaries will automatically be added to your `Path` and a command will be
|
||||
shown for you to run in order to get started using the sample configuration file.
|
||||
|
||||
If you prefer to compile _komorebi_ from source, you will need
|
||||
a [working Rust development environment on Windows 10](https://rustup.rs/). The `x86_64-pc-windows-msvc` toolchain is
|
||||
required, so make sure you have also installed
|
||||
the [Build Tools for Visual Studio 2019](https://stackoverflow.com/a/55603112).
|
||||
|
||||
You can then clone this repo and compile the source code to install the binaries for `komorebi` and `komorebic`:
|
||||
@@ -73,16 +91,19 @@ cargo install --path komorebi --locked
|
||||
cargo install --path komorebic --locked
|
||||
```
|
||||
|
||||
By running `komorebic start` at a Powershell prompt, you should see the following output:
|
||||
Once you have either the prebuilt binaries in your `Path`, or have compiled the binaries from source (these will already
|
||||
be in your `Path` if you installed Rust with [rustup](https://rustup.rs), which you absolutely should), you can
|
||||
run `komorebic start` at a Powershell prompt, and you will see the following output:
|
||||
|
||||
```
|
||||
Start-Process komorebi -WindowStyle hidden
|
||||
```
|
||||
|
||||
This means that `komorebi` is now running in the background, tiling all your windows, and listening for commands sent to
|
||||
it by `komorebic`.
|
||||
it by `komorebic`. You can similarly stop the process by running `komorebic stop`.
|
||||
|
||||
You can similarly stop the process by running `komorebic stop`.
|
||||
Once `komorebi` is running, you can execute the `komorebi.sample.ahk` script to set up the default keybindings via AHK
|
||||
(the file includes comments to help you start building your own configuration).
|
||||
|
||||
If you have AutoHotKey installed and a `komorebi.ahk` file in your home directory (run `$Env:UserProfile` at a
|
||||
PowerShell prompt to find your home directory), `komorebi` will automatically try to load it when starting.
|
||||
|
||||
@@ -3,6 +3,8 @@ use std::io::BufRead;
|
||||
use std::io::BufReader;
|
||||
use std::io::ErrorKind;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
use clap::AppSettings;
|
||||
use clap::ArgEnum;
|
||||
@@ -85,7 +87,7 @@ gen_target_subcommand_args! {
|
||||
FocusWorkspace
|
||||
}
|
||||
|
||||
// Thanks to @danielhenrymantilla for showing me how to use cfr_attr with an optional argument like
|
||||
// Thanks to @danielhenrymantilla for showing me how to use cfg_attr with an optional argument like
|
||||
// this on the Rust Programming Language Community Discord Server
|
||||
macro_rules! gen_workspace_subcommand_args {
|
||||
// Workspace Property: #[enum] Value Enum (if the value is an Enum)
|
||||
@@ -341,12 +343,40 @@ fn main() -> Result<()> {
|
||||
)?;
|
||||
}
|
||||
SubCommand::Start => {
|
||||
match powershell_script::run("Start-Process komorebi -WindowStyle hidden", true) {
|
||||
let mut buf: PathBuf;
|
||||
|
||||
// The komorebi.ps1 shim will only exist in the Path if installed by Scoop
|
||||
let exec = if let Ok(output) = Command::new("where.exe").arg("komorebi.ps1").output() {
|
||||
let stdout = String::from_utf8(output.stdout)?;
|
||||
match stdout.trim() {
|
||||
stdout if stdout.is_empty() => None,
|
||||
stdout => {
|
||||
buf = PathBuf::from(stdout);
|
||||
buf.pop(); // %USERPROFILE%\scoop\shims
|
||||
buf.pop(); // %USERPROFILE%\scoop
|
||||
buf.push("apps\\komorebi\\current\\komorebi.exe"); //%USERPROFILE%\scoop\komorebi\current\komorebi.exe
|
||||
Option::from(
|
||||
buf.to_str()
|
||||
.context("cannot create a string from the scoop komorebi path")?,
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let script = if let Some(exec) = exec {
|
||||
format!("Start-Process '{}' -WindowStyle hidden", exec)
|
||||
} else {
|
||||
String::from("Start-Process komorebi -WindowStyle hidden")
|
||||
};
|
||||
|
||||
match powershell_script::run(&script, true) {
|
||||
Ok(output) => {
|
||||
println!("{}", output);
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Error: {}", e);
|
||||
Err(error) => {
|
||||
println!("Error: {}", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user