elves/elvish

View on GitHub
.github/workflows/check_website.yml

Summary

Maintainability
Test Coverage
name: Check website

on:
  push:
    branches:
      - master

jobs:
  check_freshness:
    name: Check freshness
    if: github.repository == 'elves/elvish'
    runs-on: ubuntu-latest
    strategy:
      matrix:
        host: [cdg, hkg]
    steps:
    - name: Checkout code
      uses: actions/checkout@v4
    - name: Compare timestamp
      timeout-minutes: 30
      run: |
        ts=$(git show -s --format=%ct HEAD)
        wait=10
        while true; do
          if website_ts=$(curl -sSf https://${{ matrix.host }}.elv.sh/commit-ts.txt); then
            if test "$website_ts" -ge "$ts"; then
              echo "website ($website_ts) >= current ($ts)"
              exit 0
            else
              echo "website ($website_ts) < current ($ts)"
            fi
          else
            echo "website has no commit-ts.txt yet"
          fi
          sleep $wait
          test $wait -lt 96 && wait=`echo "$wait * 2" | bc`
        done

  build_binaries:
    name: Build binaries
    runs-on: ubuntu-latest
    steps:
    - name: Checkout code
      uses: actions/checkout@v4
    - name: Set up Go
      uses: actions/setup-go@v5
      with:
        # Keep this in sync with
        # https://github.com/elves/up/blob/master/Dockerfile
        go-version: 1.22.0
    - name: Build binaries
      run: go run ./cmd/elvish ./tools/buildall.elv -name elvish-HEAD -variant official ./cmd/elvish ~/elvish-bin/
    - name: Upload binaries
      uses: actions/upload-artifact@v4
      with:
        name: bin
        path: ~/elvish-bin/**/*
        retention-days: 7
    - name: Upload binary checksums
      uses: actions/upload-artifact@v4
      with:
        name: bin-checksums
        path: ~/elvish-bin/*/*.sha256sum

  check_binary_checksums:
    name: Check binary checksums
    needs: [check_freshness, build_binaries]
    strategy:
      matrix:
        host: [cdg, hkg]
    runs-on: ubuntu-latest
    steps:
    - name: Download binary checksums
      uses: actions/download-artifact@v4
      with:
        name: bin-checksums
        path: elvish-bin
    - name: Check binary checksums
      working-directory: elvish-bin
      run: |
        ret=0
        for f in */elvish-HEAD.sha256sum */elvish-HEAD.exe.sha256sum; do
          website_sum=$(curl -sS https://${{ matrix.host }}.dl.elv.sh/$f | awk '{print $1}')
          github_sum=$(cat $f | awk '{print $1}')
          if test "$website_sum" = "$github_sum"; then
            echo "$f: website == github ($github_sum)"
          else
            echo "$f: website ($website_sum) != github ($github_sum)"
            ret=1
          fi
        done
        if test $ret != 0; then
          latest_sha=$(curl -sS -H 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' -H 'Accept: application/vnd.github.VERSION.sha' https://api.github.com/repos/elves/elvish/commits/master)
          if test ${{ github.sha }} != "$latest_sha"; then
            echo "Ignoring the mismatch since there is a newer commit now"
            ret=0
          fi
        fi
        exit $ret