|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + name: Build & Release |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - uses: actions/setup-go@v5 |
| 20 | + with: |
| 21 | + go-version: '1.22' |
| 22 | + |
| 23 | + - name: Build binaries |
| 24 | + run: | |
| 25 | + mkdir -p dist |
| 26 | + targets=( |
| 27 | + "linux/amd64" |
| 28 | + "linux/arm64" |
| 29 | + "darwin/amd64" |
| 30 | + "darwin/arm64" |
| 31 | + "windows/amd64" |
| 32 | + ) |
| 33 | + for target in "${targets[@]}"; do |
| 34 | + GOOS="${target%/*}" |
| 35 | + GOARCH="${target#*/}" |
| 36 | + BINARY="tls-ca-fetch" |
| 37 | + [ "$GOOS" = "windows" ] && BINARY="tls-ca-fetch.exe" |
| 38 | + OUT="dist/tls-ca-fetch-${GOOS}-${GOARCH}" |
| 39 | + [ "$GOOS" = "windows" ] && OUT="${OUT}.exe" |
| 40 | + CGO_ENABLED=0 GOOS=$GOOS GOARCH=$GOARCH go build \ |
| 41 | + -trimpath \ |
| 42 | + -ldflags="-s -w -extldflags=-static" \ |
| 43 | + -o "$BINARY" . |
| 44 | + # Package darwin builds as tarballs for Homebrew |
| 45 | + if [ "$GOOS" = "darwin" ]; then |
| 46 | + tar -czf "dist/tls-ca-fetch-${GOOS}-${GOARCH}.tar.gz" "$BINARY" |
| 47 | + fi |
| 48 | + mv "$BINARY" "$OUT" 2>/dev/null || true |
| 49 | + echo "Built: $OUT ($(du -sh "$OUT" | cut -f1))" |
| 50 | + done |
| 51 | +
|
| 52 | + - name: Create GitHub Release |
| 53 | + uses: softprops/action-gh-release@v2 |
| 54 | + with: |
| 55 | + files: dist/* |
| 56 | + generate_release_notes: true |
| 57 | + |
| 58 | + rpm: |
| 59 | + name: RHEL9 RPM |
| 60 | + needs: build |
| 61 | + runs-on: ubuntu-latest |
| 62 | + container: |
| 63 | + image: almalinux:9 |
| 64 | + |
| 65 | + steps: |
| 66 | + - uses: actions/checkout@v4 |
| 67 | + |
| 68 | + - name: Install build tools |
| 69 | + run: dnf install -y golang rpm-build rpmdevtools |
| 70 | + |
| 71 | + - name: Build binary |
| 72 | + run: | |
| 73 | + CGO_ENABLED=0 go build \ |
| 74 | + -trimpath \ |
| 75 | + -ldflags="-s -w -extldflags=-static" \ |
| 76 | + -o tls-ca-fetch . |
| 77 | +
|
| 78 | + - name: Build RPM |
| 79 | + run: | |
| 80 | + VERSION="${GITHUB_REF_NAME#v}" |
| 81 | + rpmdev-setuptree |
| 82 | + cp tls-ca-fetch ~/rpmbuild/BUILD/ |
| 83 | +
|
| 84 | + cat > ~/rpmbuild/SPECS/tls-ca-fetch.spec <<SPEC |
| 85 | + Name: tls-ca-fetch |
| 86 | + Version: ${VERSION} |
| 87 | + Release: 1%{?dist} |
| 88 | + Summary: Fetch and inspect TLS certificate authority chains |
| 89 | + License: MIT |
| 90 | + BuildArch: x86_64 |
| 91 | +
|
| 92 | + %description |
| 93 | + tls-ca-fetch connects to a host and retrieves the full TLS certificate |
| 94 | + authority chain, outputting PEM certificates and chain metadata. |
| 95 | +
|
| 96 | + %install |
| 97 | + install -Dm755 %{_builddir}/tls-ca-fetch %{buildroot}/usr/local/bin/tls-ca-fetch |
| 98 | +
|
| 99 | + %files |
| 100 | + /usr/local/bin/tls-ca-fetch |
| 101 | +
|
| 102 | + %changelog |
| 103 | + * $(date "+%a %b %d %Y") GitHub Actions <actions@github.com> - ${VERSION}-1 |
| 104 | + - Release ${VERSION} |
| 105 | + SPEC |
| 106 | +
|
| 107 | + rpmbuild -bb ~/rpmbuild/SPECS/tls-ca-fetch.spec |
| 108 | + find ~/rpmbuild/RPMS -name '*.rpm' -exec cp {} . \; |
| 109 | + ls -lh *.rpm |
| 110 | +
|
| 111 | + - name: Upload RPM to release |
| 112 | + uses: softprops/action-gh-release@v2 |
| 113 | + with: |
| 114 | + files: "*.rpm" |
| 115 | + |
| 116 | + homebrew: |
| 117 | + name: Update Homebrew Tap |
| 118 | + needs: build |
| 119 | + runs-on: ubuntu-latest |
| 120 | + |
| 121 | + steps: |
| 122 | + - name: Download darwin tarballs from release |
| 123 | + run: | |
| 124 | + TAG="${GITHUB_REF_NAME}" |
| 125 | + for ARCH in amd64 arm64; do |
| 126 | + curl -fsSL \ |
| 127 | + "https://github.com/binRick/tls-ca-fetch/releases/download/${TAG}/tls-ca-fetch-darwin-${ARCH}.tar.gz" \ |
| 128 | + -o "tls-ca-fetch-darwin-${ARCH}.tar.gz" |
| 129 | + done |
| 130 | +
|
| 131 | + - name: Compute SHA256s |
| 132 | + run: | |
| 133 | + echo "SHA256_AMD64=$(sha256sum tls-ca-fetch-darwin-amd64.tar.gz | cut -d' ' -f1)" >> "$GITHUB_ENV" |
| 134 | + echo "SHA256_ARM64=$(sha256sum tls-ca-fetch-darwin-arm64.tar.gz | cut -d' ' -f1)" >> "$GITHUB_ENV" |
| 135 | +
|
| 136 | + - name: Checkout homebrew-tap |
| 137 | + uses: actions/checkout@v4 |
| 138 | + with: |
| 139 | + repository: binRick/homebrew-tap |
| 140 | + token: ${{ secrets.HOMEBREW_TAP_TOKEN }} |
| 141 | + path: tap |
| 142 | + |
| 143 | + - name: Write formula |
| 144 | + run: | |
| 145 | + VERSION="${GITHUB_REF_NAME#v}" |
| 146 | + TAG="${GITHUB_REF_NAME}" |
| 147 | + mkdir -p tap/Formula |
| 148 | + cat > tap/Formula/tls-ca-fetch.rb <<RUBY |
| 149 | + class TlsCaFetch < Formula |
| 150 | + desc "Fetch and inspect TLS certificate authority chains" |
| 151 | + homepage "https://github.com/binRick/tls-ca-fetch" |
| 152 | + version "${VERSION}" |
| 153 | + license "MIT" |
| 154 | +
|
| 155 | + on_macos do |
| 156 | + on_arm do |
| 157 | + url "https://github.com/binRick/tls-ca-fetch/releases/download/${TAG}/tls-ca-fetch-darwin-arm64.tar.gz" |
| 158 | + sha256 "${SHA256_ARM64}" |
| 159 | + end |
| 160 | + on_intel do |
| 161 | + url "https://github.com/binRick/tls-ca-fetch/releases/download/${TAG}/tls-ca-fetch-darwin-amd64.tar.gz" |
| 162 | + sha256 "${SHA256_AMD64}" |
| 163 | + end |
| 164 | + end |
| 165 | +
|
| 166 | + def install |
| 167 | + bin.install "tls-ca-fetch" |
| 168 | + end |
| 169 | +
|
| 170 | + test do |
| 171 | + system "#{bin}/tls-ca-fetch", "--help" |
| 172 | + end |
| 173 | + end |
| 174 | + RUBY |
| 175 | +
|
| 176 | + - name: Commit and push formula |
| 177 | + run: | |
| 178 | + cd tap |
| 179 | + git config user.name "github-actions[bot]" |
| 180 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 181 | + git add Formula/tls-ca-fetch.rb |
| 182 | + git diff --cached --quiet || git commit -m "tls-ca-fetch: update to ${GITHUB_REF_NAME}" |
| 183 | + git push |
0 commit comments