Skip to content

Commit 30aa9eb

Browse files
authored
ci: nixOS special version (#1300)
## What? Separated `go` and `toolchain` versions, makes workflow dispatch only, adds a workflow with a cron job to check nixos go version ## Why? @r-ryantm fails due to `go 1.26.3` being non-existent on the master branch of nixos/nix-pkgs. This will make it so that: if the user/workflow can use the latest version of Go --> it downloads and uses it, otherwise it uses the version set in `go` (which will be up to date to nixos-pkgs master version). Signed-off-by: drew <me@andrinoff.com>
1 parent 409fe1f commit 30aa9eb

4 files changed

Lines changed: 114 additions & 74 deletions

File tree

.github/workflows/nixpkgs-bump.yml

Lines changed: 16 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
name: Nixpkgs Bump PR
22

3-
# Triggers on stable release publish. Opens PR against NixOS/nixpkgs
4-
# bumping pkgs/by-name/ma/matcha/package.nix to the new version.
3+
# Manual dispatch only. r-ryantm bot handles automated bumps in nixpkgs.
4+
# This workflow exists for emergency / out-of-band bumps.
5+
# Uses whatever Go version is current on nixpkgs master.
56
# Requires:
67
# - Fork floatpane/nixpkgs to exist
7-
# - NIXPKGS_BUMP_TOKEN secret: PAT with `repo` scope on floatpane/nixpkgs
8+
# - HOMEBREW_GITHUB_TOKEN secret: PAT with `repo` scope on floatpane/nixpkgs
89
# and permission to open PRs against NixOS/nixpkgs
9-
# - Initial matcha package already merged into nixpkgs (this workflow updates, not inits)
10+
# - Initial matcha package already merged into nixpkgs
1011

1112
on:
12-
release:
13-
types: [published]
1413
workflow_dispatch:
1514
inputs:
1615
version:
@@ -24,33 +23,13 @@ jobs:
2423
bump:
2524
runs-on: ubuntu-latest
2625
steps:
27-
- name: Determine version
28-
id: ver
29-
run: |
30-
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
31-
VERSION="${{ inputs.version }}"
32-
else
33-
TAG="${{ github.event.release.tag_name }}"
34-
VERSION="${TAG#v}"
35-
fi
36-
# Skip nightly / preview tags
37-
if [[ "$VERSION" == nightly* || "$VERSION" == preview* ]]; then
38-
echo "Skipping non-stable release: $VERSION"
39-
echo "skip=true" >> $GITHUB_OUTPUT
40-
else
41-
echo "skip=false" >> $GITHUB_OUTPUT
42-
fi
43-
echo "version=$VERSION" >> $GITHUB_OUTPUT
44-
4526
- name: Install Nix
46-
if: steps.ver.outputs.skip != 'true'
4727
uses: cachix/install-nix-action@v31
4828
with:
4929
extra_nix_config: |
5030
experimental-features = nix-command flakes
5131
5232
- name: Checkout nixpkgs fork
53-
if: steps.ver.outputs.skip != 'true'
5433
uses: actions/checkout@v6
5534
with:
5635
repository: floatpane/nixpkgs
@@ -59,123 +38,88 @@ jobs:
5938
fetch-depth: 0
6039

6140
- name: Sync fork with upstream master
62-
if: steps.ver.outputs.skip != 'true'
6341
working-directory: nixpkgs
6442
run: |
6543
git config user.name "Floatpane Bot"
6644
git config user.email "us@floatpane.com"
6745
git remote add upstream https://github.com/NixOS/nixpkgs.git
68-
git fetch upstream master staging
46+
git fetch upstream master
6947
git checkout master
7048
git reset --hard upstream/master
7149
git push origin master --force-with-lease
7250
7351
- name: Get current version (from master)
74-
if: steps.ver.outputs.skip != 'true'
7552
id: current
7653
working-directory: nixpkgs
7754
run: |
7855
PKG=pkgs/by-name/ma/matcha/package.nix
7956
OLD=$(grep -E '^\s*version\s*=\s*"' "$PKG" | head -1 | sed -E 's/.*"([^"]+)".*/\1/')
8057
echo "old=$OLD" >> $GITHUB_OUTPUT
8158
82-
- name: Write go overlay from staging
83-
if: steps.ver.outputs.skip != 'true'
84-
working-directory: nixpkgs
85-
run: |
86-
# master nixpkgs heavily cached. Staging has go_1_26 = 1.26.3.
87-
# Overlay swaps only go_1_26 → minimal rebuild.
88-
STAGING_REV=$(git rev-parse upstream/staging)
89-
echo "STAGING_REV=$STAGING_REV" >> $GITHUB_ENV
90-
cat > /tmp/go-overlay.nix <<EOF
91-
let
92-
staging = import (builtins.fetchTarball
93-
"https://github.com/NixOS/nixpkgs/archive/$STAGING_REV.tar.gz") {};
94-
in final: prev: {
95-
go_1_26 = staging.go_1_26;
96-
go = staging.go_1_26;
97-
buildGoModule = prev.buildGoModule.override { go = staging.go_1_26; };
98-
}
99-
EOF
100-
cat /tmp/go-overlay.nix
101-
10259
- name: Create bump branch
103-
if: steps.ver.outputs.skip != 'true'
10460
working-directory: nixpkgs
10561
run: |
106-
BRANCH="matcha-${{ steps.ver.outputs.version }}"
62+
BRANCH="matcha-${{ inputs.version }}"
10763
git checkout -b "$BRANCH"
10864
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
10965
11066
- name: Bump version and reset hashes
111-
if: steps.ver.outputs.skip != 'true'
11267
working-directory: nixpkgs
11368
run: |
11469
PKG=pkgs/by-name/ma/matcha/package.nix
115-
NEW="${{ steps.ver.outputs.version }}"
116-
# Replace version line
70+
NEW="${{ inputs.version }}"
11771
sed -i -E "s/(version\s*=\s*\")[^\"]+(\")/\1$NEW\2/" "$PKG"
118-
# Reset src hash + vendorHash to fakeHash so nix build prints real ones
11972
sed -i -E 's|hash = "sha256-[A-Za-z0-9+/=]+"|hash = lib.fakeHash|' "$PKG"
12073
sed -i -E 's|vendorHash = "sha256-[A-Za-z0-9+/=]+"|vendorHash = lib.fakeHash|' "$PKG"
12174
12275
- name: Prefetch src hash (no build)
123-
if: steps.ver.outputs.skip != 'true'
12476
id: src_hash
12577
working-directory: nixpkgs
12678
run: |
127-
NEW="${{ steps.ver.outputs.version }}"
79+
NEW="${{ inputs.version }}"
12880
URL="https://github.com/floatpane/matcha/archive/refs/tags/v$NEW.tar.gz"
129-
# --unpack matches fetchFromGitHub (NAR hash of unpacked tarball)
13081
BASE32=$(nix-prefetch-url --unpack "$URL")
13182
HASH=$(nix hash to-sri --type sha256 "$BASE32")
13283
echo "Resolved SRI hash: $HASH"
13384
echo "hash=$HASH" >> $GITHUB_OUTPUT
13485
sed -i -E "s|hash = lib.fakeHash|hash = \"$HASH\"|" pkgs/by-name/ma/matcha/package.nix
13586
13687
- name: Build to extract vendorHash
137-
if: steps.ver.outputs.skip != 'true'
13888
working-directory: nixpkgs
13989
run: |
14090
set +e
141-
nix-build ./. -A matcha --no-out-link \
142-
--arg overlays "[ (import /tmp/go-overlay.nix) ]" \
143-
2>&1 | tee /tmp/build-vendor.log
91+
nix-build ./. -A matcha --no-out-link 2>&1 | tee /tmp/build-vendor.log
14492
HASH=$(grep -oE 'got:[[:space:]]+sha256-[A-Za-z0-9+/=]+' /tmp/build-vendor.log | head -1 | awk '{print $2}')
14593
if [ -z "$HASH" ]; then
14694
echo "Failed to extract vendorHash"; exit 1
14795
fi
14896
sed -i -E "s|vendorHash = lib.fakeHash|vendorHash = \"$HASH\"|" pkgs/by-name/ma/matcha/package.nix
14997
15098
- name: Final build (sanity check)
151-
if: steps.ver.outputs.skip != 'true'
15299
working-directory: nixpkgs
153100
run: |
154-
nix-build ./. -A matcha --no-out-link \
155-
--arg overlays "[ (import /tmp/go-overlay.nix) ]"
101+
nix-build ./. -A matcha --no-out-link
156102
157103
- name: Commit and push
158-
if: steps.ver.outputs.skip != 'true'
159104
working-directory: nixpkgs
160105
run: |
161106
git add pkgs/by-name/ma/matcha/package.nix
162-
git commit -m "matcha: ${{ steps.current.outputs.old }} -> ${{ steps.ver.outputs.version }}"
107+
git commit -m "matcha: ${{ steps.current.outputs.old }} -> ${{ inputs.version }}"
163108
git push -u origin "$BRANCH" --force-with-lease
164109
165110
- name: Open PR against NixOS/nixpkgs
166-
if: steps.ver.outputs.skip != 'true'
167111
env:
168112
GH_TOKEN: ${{ secrets.HOMEBREW_GITHUB_TOKEN }}
169113
working-directory: nixpkgs
170114
run: |
171115
BODY=$(cat <<EOF
172116
## Description
173117
174-
Automated version bump for \`matcha\` email client.
118+
Manual version bump for \`matcha\` email client.
175119
176120
- Old: ${{ steps.current.outputs.old }}
177-
- New: ${{ steps.ver.outputs.version }}
178-
- Upstream release: https://github.com/floatpane/matcha/releases/tag/v${{ steps.ver.outputs.version }}
121+
- New: ${{ inputs.version }}
122+
- Upstream release: https://github.com/floatpane/matcha/releases/tag/v${{ inputs.version }}
179123
180124
## Things done
181125
@@ -190,5 +134,5 @@ jobs:
190134
--repo NixOS/nixpkgs \
191135
--base master \
192136
--head "floatpane:$BRANCH" \
193-
--title "matcha: ${{ steps.current.outputs.old }} -> ${{ steps.ver.outputs.version }}" \
137+
--title "matcha: ${{ steps.current.outputs.old }} -> ${{ inputs.version }}" \
194138
--body "$BODY"
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Sync go.mod minimum from nixpkgs master
2+
3+
# Renovate manages `toolchain` directive (preferred Go).
4+
# This workflow manages `go` directive (minimum Go) to track nixpkgs master.
5+
# Keeps r-ryantm / nixpkgs sandbox builds passing.
6+
7+
on:
8+
schedule:
9+
- cron: "0 6 * * *"
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: write
14+
pull-requests: write
15+
16+
jobs:
17+
sync:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v6
21+
with:
22+
token: ${{ secrets.HOMEBREW_GITHUB_TOKEN }}
23+
24+
- uses: cachix/install-nix-action@v31
25+
with:
26+
extra_nix_config: |
27+
experimental-features = nix-command flakes
28+
29+
- name: Get nixpkgs master Go version
30+
id: nixgo
31+
run: |
32+
VER=$(nix eval --raw --impure --expr \
33+
'(import (builtins.fetchTarball "https://github.com/NixOS/nixpkgs/archive/master.tar.gz") {}).go_1_26.version')
34+
echo "version=$VER"
35+
echo "version=$VER" >> $GITHUB_OUTPUT
36+
37+
- name: Get current go.mod values
38+
id: current
39+
run: |
40+
GO=$(grep -E '^go [0-9.]+$' go.mod | awk '{print $2}')
41+
TC=$(grep -E '^toolchain go[0-9.]+$' go.mod | sed 's/toolchain go//')
42+
echo "go=$GO" >> $GITHUB_OUTPUT
43+
echo "toolchain=$TC" >> $GITHUB_OUTPUT
44+
45+
- name: Bump go.mod if needed
46+
id: bump
47+
run: |
48+
NEW="${{ steps.nixgo.outputs.version }}"
49+
GO="${{ steps.current.outputs.go }}"
50+
TC="${{ steps.current.outputs.toolchain }}"
51+
CHANGED=false
52+
if [ "$GO" != "$NEW" ]; then
53+
sed -i -E "s/^go [0-9.]+$/go $NEW/" go.mod
54+
CHANGED=true
55+
fi
56+
# If toolchain now < go minimum, raise toolchain to match
57+
if [ -n "$TC" ]; then
58+
LOWER=$(printf '%s\n%s\n' "$TC" "$NEW" | sort -V | head -1)
59+
if [ "$LOWER" = "$TC" ] && [ "$TC" != "$NEW" ]; then
60+
sed -i -E "s/^toolchain go[0-9.]+$/toolchain go$NEW/" go.mod
61+
CHANGED=true
62+
fi
63+
fi
64+
echo "changed=$CHANGED" >> $GITHUB_OUTPUT
65+
echo "old=$GO" >> $GITHUB_OUTPUT
66+
echo "new=$NEW" >> $GITHUB_OUTPUT
67+
68+
- name: Open PR
69+
if: steps.bump.outputs.changed == 'true'
70+
uses: peter-evans/create-pull-request@v7
71+
with:
72+
token: ${{ secrets.HOMEBREW_GITHUB_TOKEN }}
73+
committer: "Floatpane Bot <us@floatpane.com>"
74+
author: "Floatpane Bot <us@floatpane.com>"
75+
commit-message: "chore: bump go.mod minimum to ${{ steps.bump.outputs.new }} (nixpkgs master)"
76+
branch: sync-go-nixpkgs
77+
delete-branch: true
78+
title: "chore: bump go.mod minimum to ${{ steps.bump.outputs.new }}"
79+
body: |
80+
nixpkgs master ships Go `${{ steps.bump.outputs.new }}`.
81+
Bump `go` directive in `go.mod` to match (was `${{ steps.bump.outputs.old }}`).
82+
83+
Keeps r-ryantm / nixpkgs sandbox builds passing.
84+
`toolchain` directive raised only if it fell below the new minimum.
85+
labels: |
86+
dependencies

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module github.com/floatpane/matcha
22

3-
go 1.26.3
3+
go 1.26.2
4+
5+
toolchain go1.26.3
46

57
require (
68
charm.land/bubbles/v2 v2.1.0

renovate.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@
1010
{
1111
"matchManagers": ["gomod"],
1212
"matchDepNames": ["go"],
13-
"rangeStrategy": "bump"
13+
"matchDepTypes": ["golang"],
14+
"enabled": false
15+
},
16+
{
17+
"matchManagers": ["gomod"],
18+
"matchDepNames": ["go"],
19+
"matchDepTypes": ["toolchain"],
20+
"rangeStrategy": "bump",
21+
"groupName": "go toolchain"
1422
},
1523
{
1624
"matchManagers": ["github-actions"],

0 commit comments

Comments
 (0)