Skip to content

Visual Studio Code, rebuilt in Rust

Rust

ci(nix): keep the flake on the newest release (#88)

Romanf202cb10f937
diff --git a/.github/workflows/update-flake.yml b/.github/workflows/update-flake.yml
new file mode 100644
index 00000000000..9d788ab94a3
--- /dev/null
+++ b/.github/workflows/update-flake.yml
@@ -0,0 +1,112 @@
+name: update-flake
+
+on:
+ release:
+ types: [published]
+ workflow_dispatch:
+
+concurrency:
+ group: update-flake
+
+permissions:
+ contents: read
+
+jobs:
+ release:
+ runs-on: ubuntu-latest
+ outputs:
+ json: ${{ steps.read.outputs.json }}
+ version: ${{ steps.read.outputs.version }}
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+ ref: ${{ github.event.repository.default_branch }}
+
+ - name: Read the newest release's Linux archives
+ id: read
+ env:
+ GH_TOKEN: ${{ github.token }}
+ run: |
+ tag=$(gh release list --repo "$GITHUB_REPOSITORY" --exclude-drafts --limit 100 --json publishedAt,tagName \
+ --jq '[.[] | select(.tagName | startswith("v"))] | max_by(.publishedAt) | .tagName')
+ version=${tag#v}
+ gh release view "$tag" --repo "$GITHUB_REPOSITORY" --json assets > "$RUNNER_TEMP/assets.json"
+ digest() {
+ jq --raw-output --arg name "VSRustium-$version-linux-$1.tar.gz" \
+ '.assets[] | select(.name == $name) | .digest // empty' "$RUNNER_TEMP/assets.json"
+ }
+ arm64=$(digest arm64)
+ x64=$(digest x64)
+ if [ -z "$arm64" ] && [ -z "$x64" ]; then
+ echo "::notice::$tag has no Linux archives, the flake stays where it is"
+ exit 0
+ fi
+ if [ -z "$arm64" ] || [ -z "$x64" ]; then
+ echo "::error::$tag has only one of the two Linux archives, arm64 and x64"
+ exit 1
+ fi
+ jq --null-input --arg arm64 "$arm64" --arg version "$version" --arg x64 "$x64" \
+ '{hashes: {"aarch64-linux": $arm64, "x86_64-linux": $x64}, version: $version}' > nix/release.json
+ if git diff --quiet -- nix/release.json; then
+ echo "::notice::The flake is already at $version"
+ exit 0
+ fi
+ {
+ echo "json=$(jq --compact-output . nix/release.json)"
+ echo "version=$version"
+ } >> "$GITHUB_OUTPUT"
+
+ build:
+ needs: release
+ if: needs.release.outputs.version != ''
+ strategy:
+ matrix:
+ runner: [ubuntu-24.04, ubuntu-24.04-arm]
+ runs-on: ${{ matrix.runner }}
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+ ref: ${{ github.event.repository.default_branch }}
+
+ - uses: cachix/install-nix-action@382a9ed9481c7c1f94f68b72ef105b3417c73877 # v32.1.0
+
+ - name: Build the flake and start it
+ env:
+ RELEASE: ${{ needs.release.outputs.json }}
+ VERSION: ${{ needs.release.outputs.version }}
+ run: |
+ jq . <<<"$RELEASE" > nix/release.json
+ nix build --print-build-logs
+ started=$(./result/bin/vsrustium --version | sed --quiet 1p)
+ if [ "$started" != "$VERSION" ]; then
+ echo "::error::vsrustium --version printed '$started', not $VERSION"
+ exit 1
+ fi
+
+ commit:
+ needs: [build, release]
+ runs-on: ubuntu-latest
+ permissions:
+ contents: write
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+ ref: ${{ github.event.repository.default_branch }}
+
+ - name: Commit the flake update
+ env:
+ DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
+ GH_TOKEN: ${{ github.token }}
+ RELEASE: ${{ needs.release.outputs.json }}
+ VERSION: ${{ needs.release.outputs.version }}
+ run: |
+ jq . <<<"$RELEASE" > nix/release.json
+ git config user.name "github-actions[bot]"
+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
+ git add nix/release.json
+ git commit --message "chore(nix): update the flake to $VERSION"
+ git pull --rebase origin "$DEFAULT_BRANCH"
+ git push "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "HEAD:${DEFAULT_BRANCH}"
diff --git a/README.md b/README.md
index d6a5258c605..71176c11026 100644
--- a/README.md
+++ b/README.md
@@ -109,7 +109,7 @@ Counted from the agent session logs, each call once; cost at OpenRouter list pri
- macOS: `darwin-arm64` for Apple silicon, `darwin-x64` for Intel. Signed, notarized, updates itself.
- Linux: `linux-x64` and `linux-arm64` archives (`.tar.gz`) and AppImages (`.AppImage`), glibc 2.39 or newer: Ubuntu 24.04, Debian 13. A preview: webviews in X11 sessions only (WebKitGTK 4.1), no self-update, the rest in the "M23 Linux" rows of [port/ledger.md](port/ledger.md).
-- Nix: [flake.nix](flake.nix) packages the Linux archives. Run it with `nix run github:rokartur/vsrustium`, or install `packages.<system>.default` from a NixOS or Home Manager configuration.
+- Nix: [flake.nix](flake.nix) packages the Linux archives and moves to each release once that release builds ([update-flake.yml](.github/workflows/update-flake.yml)). Run it with `nix run github:rokartur/vsrustium`, or install `packages.<system>.default` from a NixOS or Home Manager configuration.
## Build
diff --git a/flake.nix b/flake.nix
index ea33de69985..36b3b51a7b2 100644
--- a/flake.nix
+++ b/flake.nix
@@ -6,33 +6,27 @@
outputs =
{ nixpkgs, ... }:
let
- version = "1.148.0-insider";
- releases = {
- aarch64-linux = {
- arch = "arm64";
- hash = "sha256:8bdbed53d4f51e3b5d5c77f02dd1425a2ba6ea965cc0eb96ad20893507a0981b";
- };
- x86_64-linux = {
- arch = "x64";
- hash = "sha256:c1787fb34bd8caedbef3b175df33bf610ec0781bd9a03075892222cb1eeaed60";
- };
+ release = builtins.fromJSON (builtins.readFile ./nix/release.json);
+ archs = {
+ aarch64-linux = "arm64";
+ x86_64-linux = "x64";
};
forAllSystems =
f:
- nixpkgs.lib.genAttrs (builtins.attrNames releases) (
- system: f nixpkgs.legacyPackages.${system} releases.${system}
+ nixpkgs.lib.genAttrs (builtins.attrNames archs) (
+ system: f nixpkgs.legacyPackages.${system} archs.${system} release.hashes.${system}
);
in
{
packages = forAllSystems (
- pkgs: release: {
+ pkgs: arch: hash: {
default = pkgs.stdenv.mkDerivation {
pname = "vsrustium";
- inherit version;
+ inherit (release) version;
src = pkgs.fetchurl {
- url = "https://github.com/rokartur/vsrustium/releases/download/v${version}/VSRustium-${version}-linux-${release.arch}.tar.gz";
- inherit (release) hash;
+ url = "https://github.com/rokartur/vsrustium/releases/download/v${release.version}/VSRustium-${release.version}-linux-${arch}.tar.gz";
+ inherit hash;
};
nativeBuildInputs = [
@@ -87,7 +81,7 @@
homepage = "https://github.com/rokartur/vsrustium";
license = pkgs.lib.licenses.mit;
mainProgram = "vsrustium";
- platforms = builtins.attrNames releases;
+ platforms = builtins.attrNames archs;
sourceProvenance = [ pkgs.lib.sourceTypes.binaryNativeCode ];
};
};
diff --git a/nix/release.json b/nix/release.json
new file mode 100644
index 00000000000..a12d9224854
--- /dev/null
+++ b/nix/release.json
@@ -0,0 +1,7 @@
+{
+ "hashes": {
+ "aarch64-linux": "sha256:5d4d18b5043f2b3dfee38ebbb0c781149dc194856371d582710b411387b256d5",
+ "x86_64-linux": "sha256:35417836dee7c85a0526a4700ae20f8fbdccb8420fa4fc8bc92eb74621bce28a"
+ },
+ "version": "1.148.0.2-insider"
+}