From 18944741daf94bc345c3f90e8262aa76c580e8db Mon Sep 17 00:00:00 2001 From: Jose Quintana Date: Wed, 10 May 2023 03:01:45 +0200 Subject: [PATCH] feat: ci workflow for automate checksums --- .github/workflows/release.checksums.yml | 27 +++++++++++++++++++++++++++ docs/content/download-and-install.tmpl.md | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ scripts/ci/generate_checksums.sh | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 238 insertions(+) create mode 100644 .github/workflows/release.checksums.yml create mode 100644 docs/content/download-and-install.tmpl.md create mode 100755 scripts/ci/generate_checksums.sh diff --git a/.github/workflows/release.checksums.yml b/.github/workflows/release.checksums.yml new file mode 100644 index 0000000..ece1509 --- /dev/null +++ b/.github/workflows/release.checksums.yml @@ -0,0 +1,27 @@ +name: release-checksums +on: + release: + types: + - published + +jobs: + checksum_file: + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 1 + + - name: Prepare + shell: bash + run: | + echo "SERVER_VERSION=${GITHUB_REF##*/v}" >> $GITHUB_ENV + echo "version is: ${{ env.SERVER_VERSION }}" + + - name: Generate and upload + shell: bash + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + scripts/ci/generate_checksums.sh diff --git a/docs/content/download-and-install.tmpl.md b/docs/content/download-and-install.tmpl.md new file mode 100644 index 0000000..eb254ff --- /dev/null +++ b/docs/content/download-and-install.tmpl.md @@ -0,0 +1,123 @@ +# Download and Install + +Latest **{{RELEASE_VERSION}}** release `{{RELEASE_DATE}}` ([changelog](https://github.com/static-web-server/static-web-server/releases/tag/{{RELEASE_VERSION}}), [sha256sum](https://github.com/static-web-server/static-web-server/releases/download/{{RELEASE_VERSION}}/static-web-server-{{RELEASE_VERSION}}-SHA256SUM)) + + + +See also [the release history](https://github.com/static-web-server/static-web-server/releases) on GitHub. + +!!! info "Docker" + If you are working with Docker containers then check out [the Docker page](https://static-web-server.net/features/docker/). + +## Installation methods + +### Binary installer (Linux/BSDs) + +Use our binary installer if your package manager is not supported. + +```sh +curl --proto '=https' --tlsv1.2 -sSfL https://get.static-web-server.net | sh +``` + +`static-web-server` should be installed under the `/usr/local/bin` directory. + +### Arch Linux + +Via [Yay](https://github.com/Jguer/yay) or your favorite AUR Helper. + +```sh +yay -S static-web-server-bin +``` + +### NixOS + +Via [Nix](https://github.com/NixOS/nix) (Linux/MacOS) + +```sh +nix-env -iA nixpkgs.static-web-server +``` + +### MacOS + +Via [Homebrew](https://brew.sh/) (also Linux) + +```sh +brew tap static-web-server/static-web-server + +# Just the binary +brew install static-web-server-bin + +# Or build from source +brew install static-web-server +``` + +### Windows + +Via [Scoop](https://scoop.sh/) + +```powershell +scoop install static-web-server +``` + +## Binaries + +Pre-compiled binaries grouped by CPU architectures. + +### x86_64 + +- [static-web-server-{{RELEASE_VERSION}}-x86_64-apple-darwin.tar.gz](https://github.com/static-web-server/static-web-server/releases/download/{{RELEASE_VERSION}}/static-web-server-{{RELEASE_VERSION}}-x86_64-apple-darwin.tar.gz)
+**SHA256SUM:** `{{x86_64-apple-darwin.tar.gz}}` +- [static-web-server-{{RELEASE_VERSION}}-x86_64-pc-windows-gnu.zip](https://github.com/static-web-server/static-web-server/releases/download/{{RELEASE_VERSION}}/static-web-server-{{RELEASE_VERSION}}-x86_64-pc-windows-gnu.zip)
+**SHA256SUM:** `{{x86_64-pc-windows-gnu.zip}}` +- [static-web-server-{{RELEASE_VERSION}}-x86_64-pc-windows-msvc.zip](https://github.com/static-web-server/static-web-server/releases/download/{{RELEASE_VERSION}}/static-web-server-{{RELEASE_VERSION}}-x86_64-pc-windows-msvc.zip)
+**SHA256SUM:** `{{x86_64-pc-windows-msvc.zip}}` +- [static-web-server-{{RELEASE_VERSION}}-x86_64-unknown-freebsd.tar.gz](https://github.com/static-web-server/static-web-server/releases/download/{{RELEASE_VERSION}}/static-web-server-{{RELEASE_VERSION}}-x86_64-unknown-freebsd.tar.gz)
+**SHA256SUM:** `{{x86_64-unknown-freebsd.tar.gz}}` +- [static-web-server-{{RELEASE_VERSION}}-x86_64-unknown-linux-gnu.tar.gz](https://github.com/static-web-server/static-web-server/releases/download/{{RELEASE_VERSION}}/static-web-server-{{RELEASE_VERSION}}-x86_64-unknown-linux-gnu.tar.gz)
+**SHA256SUM:** `{{x86_64-unknown-linux-gnu.tar.gz}}` +- [static-web-server-{{RELEASE_VERSION}}-x86_64-unknown-linux-musl.tar.gz](https://github.com/static-web-server/static-web-server/releases/download/{{RELEASE_VERSION}}/static-web-server-{{RELEASE_VERSION}}-x86_64-unknown-linux-musl.tar.gz)
+**SHA256SUM:** `{{x86_64-unknown-linux-musl.tar.gz}}` + +### ARM64 + +- [static-web-server-{{RELEASE_VERSION}}-aarch64-unknown-linux-gnu.tar.gz](https://github.com/static-web-server/static-web-server/releases/download/{{RELEASE_VERSION}}/static-web-server-{{RELEASE_VERSION}}-aarch64-unknown-linux-gnu.tar.gz)
+**SHA256SUM:** `{{aarch64-unknown-linux-gnu.tar.gz}}` +- [static-web-server-{{RELEASE_VERSION}}-aarch64-unknown-linux-musl.tar.gz](https://github.com/static-web-server/static-web-server/releases/download/{{RELEASE_VERSION}}/static-web-server-{{RELEASE_VERSION}}-aarch64-unknown-linux-musl.tar.gz)
+**SHA256SUM:** `{{aarch64-unknown-linux-musl.tar.gz}}` +- [static-web-server-{{RELEASE_VERSION}}-aarch64-apple-darwin.tar.gz](https://github.com/static-web-server/static-web-server/releases/download/{{RELEASE_VERSION}}/static-web-server-{{RELEASE_VERSION}}-aarch64-apple-darwin.tar.gz)
+**SHA256SUM:** `{{aarch64-apple-darwin.tar.gz}}` +- [static-web-server-{{RELEASE_VERSION}}-aarch64-linux-android.tar.gz](https://github.com/static-web-server/static-web-server/releases/download/{{RELEASE_VERSION}}/static-web-server-{{RELEASE_VERSION}}-aarch64-linux-android.tar.gz)
+**SHA256SUM:** `{{aarch64-linux-android.tar.gz}}` + +### x86 + +- [static-web-server-{{RELEASE_VERSION}}-i686-pc-windows-msvc.zip](https://github.com/static-web-server/static-web-server/releases/download/{{RELEASE_VERSION}}/static-web-server-{{RELEASE_VERSION}}-i686-pc-windows-msvc.zip)
+**SHA256SUM:** `{{i686-pc-windows-msvc.zip}}` +- [static-web-server-{{RELEASE_VERSION}}-i686-unknown-freebsd.tar.gz](https://github.com/static-web-server/static-web-server/releases/download/{{RELEASE_VERSION}}/static-web-server-{{RELEASE_VERSION}}-i686-unknown-freebsd.tar.gz)
+**SHA256SUM:** `{{i686-unknown-freebsd.tar.gz}}` +- [static-web-server-{{RELEASE_VERSION}}-i686-unknown-linux-gnu.tar.gz](https://github.com/static-web-server/static-web-server/releases/download/{{RELEASE_VERSION}}/static-web-server-{{RELEASE_VERSION}}-i686-unknown-linux-gnu.tar.gz)
+**SHA256SUM:** `{{i686-unknown-linux-gnu.tar.gz}}` +- [static-web-server-{{RELEASE_VERSION}}-i686-unknown-linux-musl.tar.gz](https://github.com/static-web-server/static-web-server/releases/download/{{RELEASE_VERSION}}/static-web-server-{{RELEASE_VERSION}}-i686-unknown-linux-musl.tar.gz)
+**SHA256SUM:** `{{i686-unknown-linux-musl.tar.gz}}` + +### ARM + +- [static-web-server-{{RELEASE_VERSION}}-arm-unknown-linux-gnueabihf.tar.gz](https://github.com/static-web-server/static-web-server/releases/download/{{RELEASE_VERSION}}/static-web-server-{{RELEASE_VERSION}}-arm-unknown-linux-gnueabihf.tar.gz)
+**SHA256SUM:** `{{arm-unknown-linux-gnueabihf.tar.gz}}` +- [static-web-server-{{RELEASE_VERSION}}-arm-unknown-linux-musleabihf.tar.gz](https://github.com/static-web-server/static-web-server/releases/download/{{RELEASE_VERSION}}/static-web-server-{{RELEASE_VERSION}}-arm-unknown-linux-musleabihf.tar.gz)
+**SHA256SUM:** `{{arm-unknown-linux-musleabihf.tar.gz}}` +- [static-web-server-{{RELEASE_VERSION}}-armv7-unknown-linux-musleabihf.tar.gz](https://github.com/static-web-server/static-web-server/releases/download/{{RELEASE_VERSION}}/static-web-server-{{RELEASE_VERSION}}-armv7-unknown-linux-musleabihf.tar.gz)
+**SHA256SUM:** `{{armv7-unknown-linux-musleabihf.tar.gz}}` + +## Source files + +- [static-web-server-{{RELEASE_VERSION_NUM}}.tar.gz](https://github.com/static-web-server/static-web-server/archive/refs/tags/{{RELEASE_VERSION}}.tar.gz)
+**SHA256SUM:** `{{SRC_TAR}}` +- [static-web-server-{{RELEASE_VERSION_NUM}}.zip](https://github.com/static-web-server/static-web-server/archive/refs/tags/{{RELEASE_VERSION}}.zip)
+**SHA256SUM:** `{{SRC_ZIP}}` diff --git a/scripts/ci/generate_checksums.sh b/scripts/ci/generate_checksums.sh new file mode 100755 index 0000000..d1a4c3e --- /dev/null +++ b/scripts/ci/generate_checksums.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +set -eux -o pipefail + +echo "Generating checksums for $SERVER_VERSION..." + +release_json="/tmp/release-$SERVER_VERSION.json" +curl \ + -Lo $release_json \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: token $GITHUB_TOKEN" \ + "https://api.github.com/repos/static-web-server/static-web-server/releases/tags/$SERVER_VERSION" + +release_dir=/tmp/release-$SERVER_VERSION + +cwd=$(pwd) +rm -rf $release_dir +mkdir -p $release_dir +cd $release_dir + +# Download precompiled binary assets +while read -r file_url; do + curl -LO --progress-bar $file_url +done < <(cat $release_json | jq -r ".assets[] | .browser_download_url") + +echo "Downloading source code assets..." +curl -Lo static-web-server-$SERVER_VERSION.zip --progress-bar \ + https://github.com/static-web-server/static-web-server/archive/refs/tags/$SERVER_VERSION.zip +curl -Lo static-web-server-$SERVER_VERSION.tar.gz --progress-bar \ + https://github.com/static-web-server/static-web-server/archive/refs/tags/$SERVER_VERSION.tar.gz + +# Compose checksum file name +checksum_file_name="static-web-server-$SERVER_VERSION-SHA256SUM" +rm -rf $checksum_file_name + +echo "Calculating and verifying checksum file..." +sha256sum static-web-server-* > $checksum_file_name +sha256sum -c $checksum_file_name + +echo "Uploading checksum file to $SERVER_VERSION GitHub release..." +release_id=$(cat $release_json | jq -r ".id") +curl -LX POST \ + --data-binary @$checksum_file_name \ + --header "Authorization: token $GITHUB_TOKEN" \ + --header "Content-Type: application/octet-stream" \ + https://uploads.github.com/repos/static-web-server/static-web-server/releases/$release_id/assets?name=$checksum_file_name + +echo "Checksum file uploaded successfully!" +echo + +echo "Updating $SERVER_VERSION checksums for 'Download and Install' page..." + +cd $cwd +release_date=$(date +%Y-%m-%d) +server_version_num=$(echo $SERVER_VERSION | sed "s/v//") +filename_version="static-web-server-$SERVER_VERSION" +filename_version_num="static-web-server-$server_version_num" + +# Replace placeholder occurrences +sed "s/{{RELEASE_DATE}}/$release_date/g" docs/content/download-and-install.tmpl.md > docs/content/download-and-install.md + +while read -r line; do + checksum=$(echo $line | awk -F ' ' '{print $1}') + filename=$(echo $line | awk -F ' ' '{print $2}') + placeholder_checksum=$(echo $filename | sed "s/^$filename_version-//") + sed -i '' "s/{{$placeholder_checksum}}/$checksum/" docs/content/download-and-install.md + + if [[ "$placeholder_checksum" = "$filename_version_num.tar.gz" ]]; then + sed -i '' "s/{{SRC_TAR}}/$checksum/" docs/content/download-and-install.md + fi + + if [[ "$placeholder_checksum" = "$filename_version_num.zip" ]]; then + sed -i '' "s/{{SRC_ZIP}}/$checksum/" docs/content/download-and-install.md + fi +done < <(cat "$release_dir/$checksum_file_name") + +sed -i '' "s/{{RELEASE_VERSION}}/$SERVER_VERSION/g" docs/content/download-and-install.md +sed -i '' "s/{{RELEASE_VERSION_NUM}}/$server_version_num/g" docs/content/download-and-install.md + +echo +echo "Committing checksum page updates..." +git config user.name "github-actions" +git config user.email "actions@users.noreply.github.com" +git add docs/content/download-and-install.md +git commit -m "docs: $SERVER_VERSION [skip ci]" || exit 0 +git push + +echo "Checksums page updated successfully!" -- libgit2 1.7.2