# Tag v* -> build static binaries and publish them as a Gitea release. name: release on: push: tags: ['v*'] jobs: release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - uses: actions/setup-go@v5 with: go-version-file: cmd/rollcall/go.mod cache-dependency-path: cmd/rollcall/go.sum - name: Build working-directory: cmd/rollcall run: | set -eu for arch in amd64 arm64; do CGO_ENABLED=0 GOOS=linux GOARCH=$arch go build -trimpath \ -ldflags="-s -w -X main.version=${GITHUB_REF_NAME}" -o rollcall-linux-$arch . # install bundle: the binary with deploy/ (bootstrap.sh, units) and agent/ (image build) b=rollcall-${GITHUB_REF_NAME}-linux-$arch mkdir -p "$b" cp rollcall-linux-$arch "$b/rollcall" cp -r ../../deploy ../../agent ../../README.md ../../INSTALL.md ../../CHANGELOG.md "$b/" tar -czf "$b.tar.gz" "$b" rm -rf "$b" done sha256sum rollcall-linux-* rollcall-*.tar.gz > SHA256SUMS - name: Release notes from CHANGELOG.md env: TAG: ${{ github.ref_name }} run: | set -eu ver=${TAG#v} # the section "## [X.Y.Z]" up to the next "## " heading awk -v v="$ver" ' /^## \[/ { inside = ($0 ~ "^## \\[" v "\\]") } inside && !/^## \[/ { print } ' CHANGELOG.md > notes.md if ! grep -q '[^[:space:]]' notes.md; then echo "::error::CHANGELOG.md has no section '## [$ver]' for tag $TAG; add it before tagging" >&2 exit 1 fi prev=$(git describe --tags --abbrev=0 "$TAG^" 2>/dev/null || true) { echo; echo "---"; if [ -n "$prev" ]; then echo "Commits: $prev...$TAG"; git log --no-merges --format='- %s' "$prev..$TAG"; else git log --no-merges --format='- %s' "$TAG"; fi; } >> notes.md echo "== release notes"; cat notes.md - name: Create release and upload assets env: API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }} TOKEN: ${{ secrets.GITHUB_TOKEN }} TAG: ${{ github.ref_name }} working-directory: cmd/rollcall run: | set -eu body=$(python3 -c 'import json,sys; print(json.dumps({"tag_name": sys.argv[1], "name": sys.argv[1], "body": open("../../notes.md").read(), "draft": False, "prerelease": "-" in sys.argv[1]}))' "$TAG") id=$(curl -sfS -X POST -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \ -d "$body" "$API/releases" | python3 -c 'import json,sys; print(json.load(sys.stdin)["id"])') for f in rollcall-linux-amd64 rollcall-linux-arm64 rollcall-*.tar.gz SHA256SUMS; do curl -sfS -X POST -H "Authorization: token $TOKEN" \ -F "attachment=@$f" "$API/releases/$id/assets?name=$f" >/dev/null echo "uploaded $f" done # The commissioning image of this tag: built with live-build on the PXE server # (the runner cannot), in a directory of its own (the lab's live image and # build stay as they are), without anyone's SSH keys, and uploaded to the # release as commissioning-* for bootstrap.sh --image-url. image: needs: release runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: SSH setup env: KEY: ${{ secrets.PXE_SSH_KEY }} run: | mkdir -p ~/.ssh && chmod 700 ~/.ssh printf '%s\n' "$KEY" > ~/.ssh/id_ed25519 && chmod 600 ~/.ssh/id_ed25519 printf 'Host *\n StrictHostKeyChecking accept-new\n ServerAliveInterval 30\n' > ~/.ssh/config - name: Build the image on the PXE server env: HOST: ${{ vars.PXE_HOST }} USER: ${{ vars.PXE_USER }} TAG: ${{ github.ref_name }} run: | set -eu W=/var/tmp/rollcall-release-$TAG ssh "$USER@$HOST" "sudo rm -rf $W && mkdir -p $W/src" scp -q -r agent deploy/publish-image.sh "$USER@$HOST:$W/src/" ssh "$USER@$HOST" "sudo env AUTHKEYS= BUILD=$W/build OUT=$W/image bash $W/src/agent/build-image.sh > $W/build.log 2>&1 || { tail -40 $W/build.log; exit 1; }; tail -5 $W/build.log" ssh "$USER@$HOST" "sudo chown -R \$(id -u):\$(id -g) $W/image" # the upload runs as the deploy user # refuse an image that lets someone in (a listing that fails refuses too) ssh "$USER@$HOST" "sudo unsquashfs -l $W/image/filesystem.squashfs > $W/files" || { echo "::error::cannot list the image" >&2; exit 1; } if ssh "$USER@$HOST" "grep -E '/\.ssh/authorized_keys' $W/files"; then echo "::error::the image carries SSH authorized_keys" >&2; exit 1 fi - name: Upload to the release env: HOST: ${{ vars.PXE_HOST }} USER: ${{ vars.PXE_USER }} TAG: ${{ github.ref_name }} API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }} TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | set -eu W=/var/tmp/rollcall-release-$TAG # the token over stdin, not on a command line printf '%s\n' "$TOKEN" | ssh "$USER@$HOST" "read -r GITEA_TOKEN && export GITEA_TOKEN && IMG=$W/image sh $W/src/publish-image.sh $TAG $API" - name: Clean up if: always() env: HOST: ${{ vars.PXE_HOST }} USER: ${{ vars.PXE_USER }} TAG: ${{ github.ref_name }} run: ssh "$USER@$HOST" "sudo rm -rf /var/tmp/rollcall-release-$TAG" || true