|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*.*.*" |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: release-${{ github.ref }} |
| 14 | + cancel-in-progress: false |
| 15 | + |
| 16 | +jobs: |
| 17 | + validate: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Check out repository |
| 21 | + uses: actions/checkout@v5 |
| 22 | + |
| 23 | + - name: Set up Go |
| 24 | + uses: actions/setup-go@v6 |
| 25 | + with: |
| 26 | + go-version-file: go.mod |
| 27 | + cache: true |
| 28 | + cache-dependency-path: | |
| 29 | + go.sum |
| 30 | +
|
| 31 | + - name: Run test suite |
| 32 | + run: make test |
| 33 | + |
| 34 | + - name: Run go vet |
| 35 | + run: go vet ./... |
| 36 | + |
| 37 | + package: |
| 38 | + needs: validate |
| 39 | + runs-on: ubuntu-latest |
| 40 | + strategy: |
| 41 | + fail-fast: false |
| 42 | + matrix: |
| 43 | + include: |
| 44 | + - goos: linux |
| 45 | + goarch: amd64 |
| 46 | + - goos: linux |
| 47 | + goarch: arm64 |
| 48 | + - goos: darwin |
| 49 | + goarch: amd64 |
| 50 | + - goos: darwin |
| 51 | + goarch: arm64 |
| 52 | + - goos: windows |
| 53 | + goarch: amd64 |
| 54 | + - goos: windows |
| 55 | + goarch: arm64 |
| 56 | + steps: |
| 57 | + - name: Check out repository |
| 58 | + uses: actions/checkout@v5 |
| 59 | + |
| 60 | + - name: Set up Go |
| 61 | + uses: actions/setup-go@v6 |
| 62 | + with: |
| 63 | + go-version-file: go.mod |
| 64 | + cache: true |
| 65 | + cache-dependency-path: | |
| 66 | + go.sum |
| 67 | +
|
| 68 | + - name: Build release archives |
| 69 | + shell: bash |
| 70 | + env: |
| 71 | + GOOS: ${{ matrix.goos }} |
| 72 | + GOARCH: ${{ matrix.goarch }} |
| 73 | + VERSION: ${{ github.ref_name }} |
| 74 | + run: | |
| 75 | + set -euo pipefail |
| 76 | +
|
| 77 | + repo_root="${PWD}" |
| 78 | + binary_version="${VERSION#v}" |
| 79 | + ext="" |
| 80 | + archive_ext="tar.gz" |
| 81 | + if [[ "${GOOS}" == "windows" ]]; then |
| 82 | + ext=".exe" |
| 83 | + archive_ext="zip" |
| 84 | + fi |
| 85 | +
|
| 86 | + mkdir -p dist |
| 87 | +
|
| 88 | + build_archive() { |
| 89 | + local archive_base="$1" |
| 90 | + local binary_name="$2" |
| 91 | + local build_tags="$3" |
| 92 | + local stage_dir |
| 93 | + stage_dir="$(mktemp -d)" |
| 94 | +
|
| 95 | + if [[ -n "${build_tags}" ]]; then |
| 96 | + GOOS="${GOOS}" GOARCH="${GOARCH}" CGO_ENABLED=0 go build \ |
| 97 | + -trimpath \ |
| 98 | + -tags "${build_tags}" \ |
| 99 | + -ldflags "-s -w -X main.version=${binary_version}" \ |
| 100 | + -o "${stage_dir}/${binary_name}${ext}" \ |
| 101 | + ./cmd/bomly |
| 102 | + else |
| 103 | + GOOS="${GOOS}" GOARCH="${GOARCH}" CGO_ENABLED=0 go build \ |
| 104 | + -trimpath \ |
| 105 | + -ldflags "-s -w -X main.version=${binary_version}" \ |
| 106 | + -o "${stage_dir}/${binary_name}${ext}" \ |
| 107 | + ./cmd/bomly |
| 108 | + fi |
| 109 | +
|
| 110 | + local archive_path="dist/${archive_base}_${VERSION}_${GOOS}_${GOARCH}.${archive_ext}" |
| 111 | + if [[ "${archive_ext}" == "zip" ]]; then |
| 112 | + ( |
| 113 | + cd "${stage_dir}" |
| 114 | + zip -q "${repo_root}/${archive_path}" "${binary_name}${ext}" |
| 115 | + ) |
| 116 | + else |
| 117 | + tar -C "${stage_dir}" -czf "${archive_path}" "${binary_name}${ext}" |
| 118 | + fi |
| 119 | +
|
| 120 | + rm -rf "${stage_dir}" |
| 121 | + } |
| 122 | +
|
| 123 | + build_archive "bomly" "bomly" "" |
| 124 | + build_archive "bomly-lite" "bomly-lite" "bomly_external_syft,bomly_external_grype" |
| 125 | +
|
| 126 | + - name: Upload packaged artifacts |
| 127 | + uses: actions/upload-artifact@v4 |
| 128 | + with: |
| 129 | + name: release-${{ matrix.goos }}-${{ matrix.goarch }} |
| 130 | + path: dist/* |
| 131 | + |
| 132 | + publish: |
| 133 | + needs: package |
| 134 | + runs-on: ubuntu-latest |
| 135 | + permissions: |
| 136 | + contents: write |
| 137 | + steps: |
| 138 | + - name: Check out repository |
| 139 | + uses: actions/checkout@v5 |
| 140 | + with: |
| 141 | + fetch-depth: 0 |
| 142 | + |
| 143 | + - name: Download packaged artifacts |
| 144 | + uses: actions/download-artifact@v5 |
| 145 | + with: |
| 146 | + path: dist |
| 147 | + pattern: release-* |
| 148 | + merge-multiple: true |
| 149 | + |
| 150 | + - name: Generate checksums |
| 151 | + shell: bash |
| 152 | + run: | |
| 153 | + set -euo pipefail |
| 154 | + find dist -maxdepth 1 -type f | sort | xargs sha256sum > dist/SHA256SUMS |
| 155 | +
|
| 156 | + - name: Write release notes |
| 157 | + shell: bash |
| 158 | + run: | |
| 159 | + cat > RELEASE_NOTES.md <<'EOF' |
| 160 | + Bomly release ${{ github.ref_name }} |
| 161 | +
|
| 162 | + Assets in this draft prerelease include: |
| 163 | + - Full builtin `bomly` archives for Linux, macOS, and Windows |
| 164 | + - Alternate `bomly-lite` archives for users who prefer external Syft/Grype binaries |
| 165 | + - `SHA256SUMS` for release verification |
| 166 | +
|
| 167 | + GitHub-native artifact attestations are intentionally deferred while the repository remains private on a non-Enterprise plan. |
| 168 | + EOF |
| 169 | +
|
| 170 | + - name: Publish draft prerelease |
| 171 | + env: |
| 172 | + GITHUB_TOKEN: ${{ github.token }} |
| 173 | + TAG: ${{ github.ref_name }} |
| 174 | + run: | |
| 175 | + if gh release view "${TAG}" >/dev/null 2>&1; then |
| 176 | + gh release upload "${TAG}" dist/* --clobber |
| 177 | + else |
| 178 | + gh release create "${TAG}" dist/* \ |
| 179 | + --title "Bomly ${TAG}" \ |
| 180 | + --notes-file RELEASE_NOTES.md \ |
| 181 | + --draft \ |
| 182 | + --prerelease |
| 183 | + fi |
0 commit comments