|
| 1 | +name: Go Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*.*.*' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + id-token: write |
| 11 | + attestations: write |
| 12 | + |
| 13 | +env: |
| 14 | + BINARY_NAME: nist-sp800-22-rev1a |
| 15 | + GOCACHE: /tmp/go-build |
| 16 | + GOMODCACHE: /tmp/go-mod |
| 17 | + GO_CACHE_VERSION: v1 |
| 18 | + |
| 19 | +jobs: |
| 20 | + build-and-release: |
| 21 | + name: Build & Release |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - name: Checkout |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Set up Go |
| 28 | + id: setup-go |
| 29 | + uses: actions/setup-go@v5 |
| 30 | + with: |
| 31 | + go-version-file: go.mod |
| 32 | + |
| 33 | + - name: Cache Go build and module files |
| 34 | + uses: actions/cache@v4 |
| 35 | + with: |
| 36 | + path: | |
| 37 | + ${{ env.GOCACHE }} |
| 38 | + ${{ env.GOMODCACHE }} |
| 39 | + key: go-${{ env.GO_CACHE_VERSION }}-${{ runner.os }}-${{ runner.arch }}-${{ steps.setup-go.outputs.go-version }}-${{ hashFiles('**/go.sum') }} |
| 40 | + restore-keys: | |
| 41 | + go-${{ env.GO_CACHE_VERSION }}-${{ runner.os }}-${{ runner.arch }}-${{ steps.setup-go.outputs.go-version }}- |
| 42 | +
|
| 43 | + - name: Install protoc |
| 44 | + run: | |
| 45 | + PROTOC_VERSION="28.3" |
| 46 | + wget -q "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip" |
| 47 | + unzip -q protoc-${PROTOC_VERSION}-linux-x86_64.zip -d "$HOME/protoc" |
| 48 | + echo "$HOME/protoc/bin" >> "$GITHUB_PATH" |
| 49 | +
|
| 50 | + - name: Install protoc plugins |
| 51 | + run: | |
| 52 | + go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.11 |
| 53 | + go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.6.0 |
| 54 | +
|
| 55 | + - name: Build Go binaries |
| 56 | + run: | |
| 57 | + make build |
| 58 | + make build-arm64 |
| 59 | +
|
| 60 | + - name: Prepare release artifacts |
| 61 | + run: | |
| 62 | + set -euo pipefail |
| 63 | + VERSION="${GITHUB_REF_NAME#v}" |
| 64 | + mkdir -p dist |
| 65 | + cp "build/${BINARY_NAME}" "dist/${BINARY_NAME}_${VERSION}_linux_amd64" |
| 66 | + cp "build/${BINARY_NAME}-arm64" "dist/${BINARY_NAME}_${VERSION}_linux_arm64" |
| 67 | + (cd dist && sha256sum * > checksums.txt) |
| 68 | +
|
| 69 | + - name: Create GitHub release |
| 70 | + uses: softprops/action-gh-release@v2 |
| 71 | + with: |
| 72 | + files: | |
| 73 | + dist/* |
| 74 | + generate_release_notes: true |
| 75 | + |
| 76 | + - name: Generate artifact attestation |
| 77 | + uses: actions/attest-build-provenance@v2 |
| 78 | + with: |
| 79 | + subject-path: dist |
| 80 | + |
| 81 | + docker_publish: |
| 82 | + name: Build & Publish Docker image |
| 83 | + needs: build-and-release |
| 84 | + runs-on: ubuntu-latest |
| 85 | + permissions: |
| 86 | + contents: read |
| 87 | + packages: write |
| 88 | + steps: |
| 89 | + - name: Checkout repository |
| 90 | + uses: actions/checkout@v4 |
| 91 | + |
| 92 | + - name: Log in to GHCR |
| 93 | + uses: docker/login-action@v3 |
| 94 | + with: |
| 95 | + registry: ghcr.io |
| 96 | + username: ${{ github.actor }} |
| 97 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 98 | + |
| 99 | + - name: Build and push image |
| 100 | + env: |
| 101 | + REGISTRY: ghcr.io |
| 102 | + IMAGE_NAME: ${{ github.repository_owner }}/nist-sp800-22-rev1a |
| 103 | + run: | |
| 104 | + set -euo pipefail |
| 105 | + OWNER_IMAGE=$(echo "${IMAGE_NAME}" | tr '[:upper:]' '[:lower:]') |
| 106 | + IMAGE="${REGISTRY}/${OWNER_IMAGE}" |
| 107 | + TAG="${GITHUB_REF_NAME}" |
| 108 | + echo "Building ${IMAGE}:{sha,latest,${TAG}}" |
| 109 | + docker build -t "${IMAGE}:${GITHUB_SHA}" -t "${IMAGE}:latest" -t "${IMAGE}:${TAG}" . |
| 110 | + docker push "${IMAGE}:${GITHUB_SHA}" |
| 111 | + docker push "${IMAGE}:latest" |
| 112 | + docker push "${IMAGE}:${TAG}" |
0 commit comments