Skip to content

Commit

Permalink
Fully auto-generate the download page
Browse files Browse the repository at this point in the history
Based on the OS/arch combos we actually have
  • Loading branch information
calmh committed Dec 13, 2023
1 parent 7247279 commit d8f4f24
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 76 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/page-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ jobs:
with:
hugo-version: 'latest'

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 'stable'

- name: Build
run: ./build.sh
env:
Expand Down
9 changes: 2 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
set -euo pipefail

pushd script
go run . > ../themes/default/layouts/partials/github-sponsors.html
go run ./sponsors > ../themes/default/layouts/partials/github-sponsors.html
go run ./release > ../data/release.yaml
popd

rel=$(curl -s https://github.com/repos/syncthing/syncthing/releases/latest \
| grep tag_name \
| awk '{print $2}' \
| tr -d \",v)

echo "stable: $rel" > data/release.yaml
hugo --minify
2 changes: 1 addition & 1 deletion content/downloads.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ executable and a web based user interface.
{{< release >}}

If you are unsure what to download and you're running on a normal computer,
please use the "64-bit (x86-64)" build for your operating system. If you're
please use the "Intel/AMD (64-bit)" build for your operating system. If you're
running on an oddball system such as a NAS, please consult your vendor.


Expand Down
1 change: 1 addition & 0 deletions script/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.20
require (
github.com/shurcooL/githubv4 v0.0.0-20230704064427-599ae7bbf278
golang.org/x/oauth2 v0.14.0
gopkg.in/yaml.v3 v3.0.1
)

require (
Expand Down
4 changes: 4 additions & 0 deletions script/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
182 changes: 182 additions & 0 deletions script/release/release.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
package main

import (
"cmp"
"encoding/json"
"log"
"net/http"
"os"
"slices"
"strings"
"time"

"gopkg.in/yaml.v3"
)

type githubRelease struct {
HTMLURL string `json:"html_url"`
Body string `json:"body"`
TagName string `json:"tag_name"`
PublishedAt time.Time `json:"published_at"`
Assets []struct {
Name string `json:"name"`
Size int `json:"size"`
BrowserDownloadURL string `json:"browser_download_url"`
}
}

type downloadPage struct {
Version string
OSes []downloadOS
}

type downloadOS struct {
OS string
Assets []downloadAsset
}

type downloadAsset struct {
Name string
Size int
URL string
Arch string

os string
osWeight int
archWeight int
}

func main() {
// Load the latest release from GitHub
res, err := http.Get("https://github.com/repos/syncthing/syncthing/releases/latest")
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
var rel githubRelease
err = json.NewDecoder(res.Body).Decode(&rel)
if err != nil {
log.Fatal(err)
}

// Filter the assets to actual binary Syncthing packages
var filtered []downloadAsset
for _, a := range rel.Assets {
parts := strings.SplitN(a.Name, "-", 4)
if len(parts) != 4 {
continue
}
if parts[0] != "syncthing" {
continue
}
filtered = append(filtered, downloadAsset{
Name: a.Name,
Size: a.Size,
URL: a.BrowserDownloadURL,
Arch: humanReadableArch(parts[2]),

os: humanReadableOS(parts[1]),
osWeight: osWeight(parts[1]),
archWeight: archWeight(parts[2]),
})
}

// Sort by operating system and architecture
slices.SortFunc(filtered, func(a, b downloadAsset) int {
if a.osWeight != b.osWeight {
return a.osWeight - b.osWeight
}
if a.archWeight != b.archWeight {
return a.archWeight - b.archWeight
}
return cmp.Compare(a.Name, b.Name)
})

// Group by OS
p := downloadPage{
Version: rel.TagName,
}
for _, a := range filtered {
if len(p.OSes) == 0 || p.OSes[len(p.OSes)-1].OS != a.os {
p.OSes = append(p.OSes, downloadOS{
OS: a.os,
})
}
p.OSes[len(p.OSes)-1].Assets = append(p.OSes[len(p.OSes)-1].Assets, a)
}

// Produce the yaml for the release page
bs, err := yaml.Marshal(p)
if err != nil {
log.Fatal(err)
}
os.Stdout.Write(bs)
}

func osWeight(os string) int {
switch os {
case "windows":
return 1
case "linux":
return 2
case "macos":
return 3
case "freebsd":
return 4
case "openbsd":
return 5
case "netbsd":
return 6
}
return 9
}

func archWeight(arch string) int {
// First universal, then 64 bit common archs, then 32 bit common archs,
// then the rest
switch arch {
case "universal":
return 0
case "amd64":
return 1
case "arm64":
return 2
case "386":
return 3
case "arm":
return 4
case "loong64":
return 10
}
return 9
}

func humanReadableOS(os string) string {
// Special cases
switch os {
case "macos":
return "macOS"
}

// Capitalise the first letter
os = strings.ToUpper(os[:1]) + os[1:]
// Known initialisms
os = strings.Replace(os, "bsd", "BSD", -1)
return os
}

func humanReadableArch(arch string) string {
switch arch {
case "386":
return "Intel/AMD (32-bit)"
case "amd64":
return "Intel/AMD (64-bit)"
case "arm":
return "ARM (32-bit)"
case "arm64":
return "ARM (64-bit)"
case "universal":
return "Universal"
}
return strings.ToUpper(arch)
}
File renamed without changes.
79 changes: 11 additions & 68 deletions themes/default/layouts/shortcodes/release.html
Original file line number Diff line number Diff line change
@@ -1,79 +1,22 @@
{{ with $.Site.Data.release.stable }}
<h5>Syncthing <b>v{{.}}</b></h5>
{{ with $.Site.Data.release }}
<h5>Syncthing <b>{{.version}}</b></h5>

<div style="column-count: 2">
<div style="column-count: 2" class="my-2">
<dl class="dl-item">
<dt>Source Code</dt>
<dd><b><a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-source-v{{.}}.tar.gz">Source tar.gz</a></b>
<dd><a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-source-v{{.}}.tar.gz">Source tar.gz</a>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-source-v{{.}}.tar.gz.asc">GPG signature</a>
</dd>
</dl>
{{ range .oses }}
<dl class="dl-item">
<dt>Linux</dt>
<dd><b><a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-linux-amd64-v{{.}}.tar.gz">64-bit (x86-64)</a></b>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-linux-386-v{{.}}.tar.gz">32-bit (x86-32)</a>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-linux-arm-v{{.}}.tar.gz">ARM</a>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-linux-arm64-v{{.}}.tar.gz">ARM64</a>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-linux-mips-v{{.}}.tar.gz">MIPS</a>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-linux-mips64-v{{.}}.tar.gz">MIPS64</a>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-linux-mipsle-v{{.}}.tar.gz">MIPS-LE</a>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-linux-mips64le-v{{.}}.tar.gz">MIPS64-LE</a>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-linux-ppc64-v{{.}}.tar.gz">PPC64</a>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-linux-ppc64le-v{{.}}.tar.gz">PPC64-LE</a>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-linux-riscv64-v{{.}}.tar.gz">RISC-V</a>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-linux-s390x-v{{.}}.tar.gz">S/390x</a>
</dd>
</dl>
<dl class="dl-item">
<dt>Windows</dt>
<dd><b><a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-windows-amd64-v{{.}}.zip">64-bit (x86-64)</a></b>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-windows-386-v{{.}}.zip">32-bit (x86-32)</a>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-windows-arm-v{{.}}.zip">ARM</a>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-windows-arm64-v{{.}}.zip">ARM64</a>
</dd>
</dl>
<dl class="dl-item">
<dt>macOS</dt>
<dd><b><a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-macos-universal-v{{.}}.zip">64-bit (Universal)</a></b>
</dd>
</dl>
<dl class="dl-item">
<dt>FreeBSD</dt>
<dd><b><a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-freebsd-amd64-v{{.}}.tar.gz">64-bit (x86-64)</a></b>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-freebsd-386-v{{.}}.tar.gz">32-bit (x86-32)</a>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-freebsd-arm-v{{.}}.tar.gz">ARM</a>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-freebsd-arm64-v{{.}}.tar.gz">ARM64</a>
</dd>
</dl>
<dl class="dl-item">
<dt>OpenBSD</dt>
<dd><b><a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-openbsd-amd64-v{{.}}.tar.gz">64-bit (x86-64)</a></b>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-openbsd-386-v{{.}}.tar.gz">32-bit (x86-32)</a>
</dd>
</dl>
<dl class="dl-item">
<dt>NetBSD</dt>
<dd><b><a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-netbsd-amd64-v{{.}}.tar.gz">64-bit (x86-64)</a></b>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-netbsd-386-v{{.}}.tar.gz">32-bit (x86-32)</a>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-netbsd-arm-v{{.}}.tar.gz">ARM</a>
&sdot; <a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-netbsd-arm64-v{{.}}.tar.gz">ARM64</a>
</dd>
</dl>
<dl class="dl-item">
<dt>Dragonfly BSD</dt>
<dd><b><a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-dragonfly-amd64-v{{.}}.tar.gz">64-bit (x86-64)</a></b>
</dd>
</dl>
<dl class="dl-item">
<dt>Illumos</dt>
<dd><b><a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-illumos-amd64-v{{.}}.tar.gz">64-bit (x86-64)</a></b>
</dd>
</dl>
<dl class="dl-item">
<dt>Solaris</dt>
<dd><b><a href="https://github.com/syncthing/syncthing/releases/download/v{{.}}/syncthing-solaris-amd64-v{{.}}.tar.gz">64-bit (x86-64)</a></b>
</dd>
<dt>{{.os}}</dt>
<dd>{{ range $i, $a := .assets }}
{{ if gt $i 0 }} &sdot; {{ end }}
<a href="{{$a.url}}">{{$a.arch}}</a>
{{ end }}</dd>
</dl>
{{ end }}
</div>
{{ else }}
<p>Download the <a href="https://github.com/syncthing/syncthing/releases/latest">latest release</a> from GitHub.</p>
Expand Down

0 comments on commit d8f4f24

Please sign in to comment.