Skip to content

Commit

Permalink
improve release process
Browse files Browse the repository at this point in the history
  • Loading branch information
soywod committed Jan 1, 2024
1 parent ce2b292 commit 12e71a5
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 68 deletions.
65 changes: 34 additions & 31 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ on:
- v*

jobs:
create_release:
create-release:
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
upload_url: ${{ steps.create-release.outputs.upload_url }}
steps:
- name: Create release
id: create_release
id: create-release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -22,20 +22,20 @@ jobs:
draft: false
prerelease: false

deploy_github:
deploy-unix-releases:
runs-on: ${{ matrix.os }}
needs: create_release
needs: create-release
strategy:
fail-fast: false
matrix:
include:
- target: linux
os: ubuntu-latest
- target: linux-musl
os: ubuntu-latest
- target: macos
os: macos-latest
- target: musl
os: ubuntu-latest
# TODO: put back when nix package .#windows is fixed
# TODO: uncomment once nix build .#windows works
# - target: windows
# os: ubuntu-latest
steps:
Expand All @@ -44,7 +44,7 @@ jobs:
- name: Install Nix
uses: cachix/install-nix-action@v24
with:
nix_path: nixpkgs=channel:nixos-23.05
nix_path: nixpkgs=channel:nixos-23.11
extra_nix_config: |
experimental-features = nix-command flakes
- uses: cachix/cachix-action@v12
Expand All @@ -53,16 +53,16 @@ jobs:
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Build release
run: nix build -L .#${{ matrix.target }}
- name: Copy executable and prepare folders
- name: Copy binary
run: |
mkdir -p {man,completions}
cp result/bin/himalaya* .
- name: Patch interpreter
- name: Patch binary interpreter
if: ${{ matrix.target == 'linux' }}
run: |
nix-shell -p patchelf --command "sudo patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 himalaya"
- name: Build release archive
- name: Prepare release archives
run: |
mkdir -p {man,completions}
nix run .#${{ matrix.target }} man ./man
nix run .#${{ matrix.target }} completion bash > ./completions/himalaya.bash
nix run .#${{ matrix.target }} completion elvish > ./completions/himalaya.elvish
Expand All @@ -71,46 +71,49 @@ jobs:
nix run .#${{ matrix.target }} completion zsh > ./completions/himalaya.zsh
tar -czf himalaya.tgz himalaya* man completions
zip -r himalaya.zip himalaya* man completions
- name: Upload tar.gz release asset
- name: Upload tarball release archive
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: himalaya.tgz
asset_name: himalaya-${{ matrix.target }}.tgz
asset_content_type: application/gzip
- name: Upload zip release asset
- name: Upload zip release archive
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: himalaya.zip
asset_name: himalaya-${{ matrix.target }}.zip
asset_content_type: application/zip

# TODO: remove me when nix package .#windows is fixed
deploy_windows_github:
# TODO: remove me once nix build .#windows works
deploy-windows-release:
runs-on: windows-latest
needs: create_release
needs: create-release
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Builds release
profile: minimal
- name: Build release
uses: actions-rs/cargo@v1
with:
command: build
args: --release
- name: Compress executable
- name: Copy binary
run: |
copy target/release/himalaya.exe .
- name: Prepare release archives
run: |
mkdir man
mkdir completions
copy target/release/himalaya.exe .
./himalaya.exe man ./man
./himalaya.exe completion bash > ./completions/himalaya.bash
./himalaya.exe completion elvish > ./completions/himalaya.elvish
Expand All @@ -119,35 +122,35 @@ jobs:
./himalaya.exe completion zsh > ./completions/himalaya.zsh
tar -czf himalaya.tgz himalaya.exe man completions
Compress-Archive -Path himalaya.exe,man,completions -DestinationPath himalaya.zip
- name: Upload tar.gz release asset
- name: Upload tarball release archive
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: himalaya.tgz
asset_name: himalaya-windows.tgz
asset_content_type: application/gzip
- name: Upload zip release asset
- name: Upload zip release archive
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: himalaya.zip
asset_name: himalaya-windows.zip
asset_content_type: application/zip

deploy_crates:
publish-crates-io:
runs-on: ubuntu-latest
needs: create_release
needs: create-release
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v2
- name: Install Nix
uses: cachix/install-nix-action@v24
with:
nix_path: nixpkgs=channel:nixos-23.05
nix_path: nixpkgs=channel:nixos-23.11
extra_nix_config: |
experimental-features = nix-command flakes
- name: Publish library to crates.io
Expand Down
20 changes: 10 additions & 10 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 37 additions & 27 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description = "CLI to manage emails";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
flake-utils.url = "github:numtide/flake-utils";
gitignore = {
url = "github:hercules-ci/gitignore.nix";
Expand Down Expand Up @@ -35,7 +35,9 @@
in
{
default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [ pkg-config ];
nativeBuildInputs = with pkgs; [
pkg-config
];
buildInputs = with pkgs; [
# Nix
rnix-lsp
Expand Down Expand Up @@ -83,22 +85,27 @@
mkPackages = buildPlatform:
let
pkgs = import nixpkgs { system = buildPlatform; };
mkPackageWithTarget = mkPackage pkgs buildPlatform;
defaultPackage = mkPackage pkgs buildPlatform null { };
mkPackage' = mkPackage pkgs buildPlatform;
in
{
default = defaultPackage;
linux = defaultPackage;
macos = defaultPackage;
musl = mkPackageWithTarget "x86_64-unknown-linux-musl" (with pkgs.pkgsStatic; {
rec {
default = if pkgs.stdenv.isDarwin then macos else linux;
linux = mkPackage' null { };
linux-musl = mkPackage' "x86_64-unknown-linux-musl" (with pkgs.pkgsStatic; {
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
SQLITE3_STATIC = 1;
SQLITE3_LIB_DIR = "${sqlite.out}/lib";
hardeningDisable = [ "all" ];
});
macos = mkPackage' null (with pkgs.darwin.apple_sdk.frameworks; {
# NOTE: needed to prevent error Undefined symbols
# "_OBJC_CLASS_$_NSImage" and
# "_LSCopyApplicationURLsForBundleIdentifier"
NIX_LDFLAGS = "-F${AppKit}/Library/Frameworks -framework AppKit";
buildInputs = [ Cocoa ];
});
# FIXME: bzlip: fatal error: windows.h: No such file or directory
# May be related to SQLite.
windows = mkPackageWithTarget "x86_64-pc-windows-gnu" {
windows = mkPackage' "x86_64-pc-windows-gnu" {
strictDeps = true;
depsBuildBuild = with pkgs.pkgsCross.mingwW64; [
stdenv.cc
Expand All @@ -112,23 +119,26 @@
name = "himalaya";
};

mkApps = buildPlatform: {
default = mkApp self.packages.${buildPlatform}.default;
linux = mkApp self.packages.${buildPlatform}.linux;
macos = mkApp self.packages.${buildPlatform}.macos;
musl = mkApp self.packages.${buildPlatform}.musl;
windows =
let
pkgs = import nixpkgs { system = buildPlatform; };
wine = pkgs.wine.override { wineBuild = "wine64"; };
himalaya = self.packages.${buildPlatform}.windows;
app = pkgs.writeShellScriptBin "himalaya" ''
export WINEPREFIX="$(mktemp -d)"
${wine}/bin/wine64 ${himalaya}/bin/himalaya.exe $@
'';
in
mkApp app;
};
mkApps = buildPlatform:
let
pkgs = import nixpkgs { system = buildPlatform; };
in
rec {
default = if pkgs.stdenv.isDarwin then macos else linux;
linux = mkApp self.packages.${buildPlatform}.linux;
linux-musl = mkApp self.packages.${buildPlatform}.linux-musl;
macos = mkApp self.packages.${buildPlatform}.macos;
windows =
let
wine = pkgs.wine.override { wineBuild = "wine64"; };
himalaya = self.packages.${buildPlatform}.windows;
app = pkgs.writeShellScriptBin "himalaya" ''
export WINEPREFIX="$(mktemp -d)"
${wine}/bin/wine64 ${himalaya}/bin/himalaya.exe $@
'';
in
mkApp app;
};

in
flake-utils.lib.eachDefaultSystem (system: {
Expand Down

0 comments on commit 12e71a5

Please sign in to comment.