From 12e71a5ba8633dfa370b7008b6f3cd2d59b7b4fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Mon, 1 Jan 2024 16:22:30 +0100 Subject: [PATCH] improve release process --- .github/workflows/release.yml | 65 ++++++++++++++++++----------------- flake.lock | 20 +++++------ flake.nix | 64 +++++++++++++++++++--------------- 3 files changed, 81 insertions(+), 68 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index de2b236..e9629a6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 }} @@ -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: @@ -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 @@ -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 @@ -71,29 +71,29 @@ 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 @@ -101,16 +101,19 @@ jobs: 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 @@ -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 diff --git a/flake.lock b/flake.lock index 074eb39..0ea100b 100644 --- a/flake.lock +++ b/flake.lock @@ -8,11 +8,11 @@ "rust-analyzer-src": "rust-analyzer-src" }, "locked": { - "lastModified": 1704003651, - "narHash": "sha256-bA3d4E1CX5G7TVbKwJOm9jZfVOGOPp6u5CKEUzNsE8E=", + "lastModified": 1704090261, + "narHash": "sha256-Vti1mv4WhmXHPNcFgUiJyt4OKLvsvLzM2eKS4bEegf0=", "owner": "nix-community", "repo": "fenix", - "rev": "c6d82e087ac96f24b90c5787a17e29a72566c2b4", + "rev": "66fc1883c34c42df188b83272445aedb26bb64b5", "type": "github" }, "original": { @@ -97,16 +97,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1703351344, - "narHash": "sha256-9FEelzftkE9UaJ5nqxidaJJPEhe9TPhbypLHmc2Mysc=", + "lastModified": 1703992652, + "narHash": "sha256-C0o8AUyu8xYgJ36kOxJfXIroy9if/G6aJbNOpA5W0+M=", "owner": "nixos", "repo": "nixpkgs", - "rev": "7790e078f8979a9fcd543f9a47427eeaba38f268", + "rev": "32f63574c85fbc80e4ba1fbb932cde9619bad25e", "type": "github" }, "original": { "owner": "nixos", - "ref": "nixos-23.05", + "ref": "nixos-23.11", "repo": "nixpkgs", "type": "github" } @@ -124,11 +124,11 @@ "rust-analyzer-src": { "flake": false, "locked": { - "lastModified": 1703965384, - "narHash": "sha256-3iyouqkBvhh/E48TkBlt4JmmcIEyfQwY7pokKBx9WNg=", + "lastModified": 1704034202, + "narHash": "sha256-OFBXLWm+aIqG+jNAz8BmB+QpepI11SGLtSY6qEs6EmY=", "owner": "rust-lang", "repo": "rust-analyzer", - "rev": "e872f5085cf5b0e44558442365c1c033d486eff2", + "rev": "cf52c4b2b3367ae7355ef23393e2eae1d37de723", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index f05107d..feb0a78 100644 --- a/flake.nix +++ b/flake.nix @@ -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"; @@ -35,7 +35,9 @@ in { default = pkgs.mkShell { - nativeBuildInputs = with pkgs; [ pkg-config ]; + nativeBuildInputs = with pkgs; [ + pkg-config + ]; buildInputs = with pkgs; [ # Nix rnix-lsp @@ -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 @@ -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: {