|
| 1 | +name: Build Binaries |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: "Version string to embed" |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + commit_sha: |
| 11 | + description: "Commit SHA to embed" |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + build_date: |
| 15 | + description: "Build date to embed" |
| 16 | + required: true |
| 17 | + type: string |
| 18 | + secrets: |
| 19 | + DEVELOPER_ID_P12_BASE64: |
| 20 | + description: "Base64-encoded Developer ID certificate" |
| 21 | + required: true |
| 22 | + DEVELOPER_ID_PASSWORD: |
| 23 | + description: "Password for the Developer ID certificate" |
| 24 | + required: true |
| 25 | + APPLE_NOTARIZATION_APPLE_ID_PASSWORD: |
| 26 | + description: "App-specific password for Apple ID notarization" |
| 27 | + required: true |
| 28 | + |
| 29 | +jobs: |
| 30 | + build: |
| 31 | + name: Build ${{ matrix.platform }} |
| 32 | + runs-on: ubuntu-latest |
| 33 | + timeout-minutes: 10 |
| 34 | + strategy: |
| 35 | + matrix: |
| 36 | + include: |
| 37 | + - platform: linux-amd64 |
| 38 | + goos: linux |
| 39 | + goarch: amd64 |
| 40 | + - platform: linux-arm64 |
| 41 | + goos: linux |
| 42 | + goarch: arm64 |
| 43 | + - platform: darwin-amd64 |
| 44 | + goos: darwin |
| 45 | + goarch: amd64 |
| 46 | + - platform: darwin-arm64 |
| 47 | + goos: darwin |
| 48 | + goarch: arm64 |
| 49 | + - platform: windows-amd64 |
| 50 | + goos: windows |
| 51 | + goarch: amd64 |
| 52 | + steps: |
| 53 | + - name: Checkout |
| 54 | + uses: actions/checkout@v5 |
| 55 | + with: |
| 56 | + persist-credentials: false |
| 57 | + |
| 58 | + - name: Set up Go |
| 59 | + uses: actions/setup-go@v6 |
| 60 | + with: |
| 61 | + go-version-file: go.mod |
| 62 | + cache: true |
| 63 | + check-latest: false |
| 64 | + |
| 65 | + - name: Build CLI |
| 66 | + run: | |
| 67 | + BINARY="github-actions-utils-cli-${{ matrix.platform }}" |
| 68 | + if [ "${{ matrix.goos }}" = "windows" ]; then |
| 69 | + BINARY="${BINARY}.exe" |
| 70 | + fi |
| 71 | +
|
| 72 | + # Build static binary (no CGO, static linking) |
| 73 | + CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build \ |
| 74 | + -ldflags "-s -w -extldflags '-static' \ |
| 75 | + -X github.com/techprimate/github-actions-utils-cli/internal/cli/cmd.version=${{ inputs.version }} \ |
| 76 | + -X github.com/techprimate/github-actions-utils-cli/internal/cli/cmd.commit=${{ inputs.commit_sha }} \ |
| 77 | + -X github.com/techprimate/github-actions-utils-cli/internal/cli/cmd.date=${{ inputs.build_date }}" \ |
| 78 | + -o "dist/${BINARY}" \ |
| 79 | + ./cmd/cli |
| 80 | +
|
| 81 | + - name: Upload artifact |
| 82 | + uses: actions/upload-artifact@v5 |
| 83 | + with: |
| 84 | + name: cli-${{ matrix.platform }} |
| 85 | + path: dist/github-actions-utils-cli-* |
| 86 | + retention-days: 1 |
| 87 | + |
| 88 | + sign-and-notarize-macos: |
| 89 | + name: Sign and Notarize macOS Binaries |
| 90 | + needs: build |
| 91 | + runs-on: macos-latest |
| 92 | + timeout-minutes: 20 |
| 93 | + steps: |
| 94 | + - name: Download Darwin CLI artifacts |
| 95 | + uses: actions/download-artifact@v6 |
| 96 | + with: |
| 97 | + path: dist |
| 98 | + pattern: cli-darwin-* |
| 99 | + merge-multiple: true |
| 100 | + |
| 101 | + - name: Setup signing certificate |
| 102 | + env: |
| 103 | + CERTIFICATE_BASE64: ${{ secrets.DEVELOPER_ID_P12_BASE64 }} |
| 104 | + CERTIFICATE_PASSWORD: ${{ secrets.DEVELOPER_ID_PASSWORD }} |
| 105 | + run: | |
| 106 | + # Create temporary keychain |
| 107 | + KEYCHAIN_NAME="github-actions-utils-signing.keychain-db" |
| 108 | + KEYCHAIN_PASSWORD=$(openssl rand -hex 32) |
| 109 | +
|
| 110 | + # Delete any existing keychain with the same name |
| 111 | + security delete-keychain "$KEYCHAIN_NAME" 2>/dev/null || true |
| 112 | +
|
| 113 | + # Create and setup keychain |
| 114 | + security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_NAME" |
| 115 | + security set-keychain-settings -lut 21600 "$KEYCHAIN_NAME" |
| 116 | + security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_NAME" |
| 117 | +
|
| 118 | + # Import certificate |
| 119 | + CERTIFICATE_PATH=$RUNNER_TEMP/certificate.p12 |
| 120 | + echo "$CERTIFICATE_BASE64" | base64 --decode -o "$CERTIFICATE_PATH" |
| 121 | + security import "$CERTIFICATE_PATH" -k "$KEYCHAIN_NAME" -P "$CERTIFICATE_PASSWORD" -T /usr/bin/codesign -T /usr/bin/security |
| 122 | +
|
| 123 | + # Make keychain available for codesign |
| 124 | + security list-keychains -d user -s "$KEYCHAIN_NAME" $(security list-keychains -d user | sed s/\"//g) |
| 125 | + security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PASSWORD" "$KEYCHAIN_NAME" |
| 126 | + security default-keychain -s "$KEYCHAIN_NAME" |
| 127 | +
|
| 128 | + # Clean up certificate file |
| 129 | + rm -f "$CERTIFICATE_PATH" |
| 130 | +
|
| 131 | + # Store keychain info for cleanup |
| 132 | + echo "KEYCHAIN_NAME=$KEYCHAIN_NAME" >> $GITHUB_ENV |
| 133 | + echo "KEYCHAIN_PASSWORD=$KEYCHAIN_PASSWORD" >> $GITHUB_ENV |
| 134 | +
|
| 135 | + - name: Sign and notarize CLI darwin-amd64 |
| 136 | + env: |
| 137 | + APPLE_ID: ${{ vars.APPLE_NOTARIZATION_APPLE_ID_USERNAME }} |
| 138 | + APPLE_ID_PASSWORD: ${{ secrets.APPLE_NOTARIZATION_APPLE_ID_PASSWORD }} |
| 139 | + APPLE_TEAM_ID: ${{ vars.APPLE_NOTARIZATION_TEAM_ID }} |
| 140 | + SIGNING_IDENTITY: ${{ vars.APPLE_NOTARIZATION_SIGNING_IDENTITY }} |
| 141 | + run: | |
| 142 | + cd dist |
| 143 | +
|
| 144 | + # Sign the binary |
| 145 | + codesign --sign "$SIGNING_IDENTITY" \ |
| 146 | + --options runtime \ |
| 147 | + --timestamp \ |
| 148 | + --force \ |
| 149 | + --verbose \ |
| 150 | + github-actions-utils-cli-darwin-amd64 |
| 151 | +
|
| 152 | + # Verify signature |
| 153 | + codesign --verify --verbose github-actions-utils-cli-darwin-amd64 |
| 154 | +
|
| 155 | + # Create zip and submit for notarization |
| 156 | + zip -q github-actions-utils-cli-darwin-amd64.zip github-actions-utils-cli-darwin-amd64 |
| 157 | + xcrun notarytool submit github-actions-utils-cli-darwin-amd64.zip \ |
| 158 | + --apple-id "$APPLE_ID" \ |
| 159 | + --password "$APPLE_ID_PASSWORD" \ |
| 160 | + --team-id "$APPLE_TEAM_ID" \ |
| 161 | + --wait |
| 162 | + rm github-actions-utils-cli-darwin-amd64.zip |
| 163 | +
|
| 164 | + - name: Sign and notarize CLI darwin-arm64 |
| 165 | + env: |
| 166 | + APPLE_ID: ${{ vars.APPLE_NOTARIZATION_APPLE_ID_USERNAME }} |
| 167 | + APPLE_ID_PASSWORD: ${{ secrets.APPLE_NOTARIZATION_APPLE_ID_PASSWORD }} |
| 168 | + APPLE_TEAM_ID: ${{ vars.APPLE_NOTARIZATION_TEAM_ID }} |
| 169 | + SIGNING_IDENTITY: ${{ vars.APPLE_NOTARIZATION_SIGNING_IDENTITY }} |
| 170 | + run: | |
| 171 | + cd dist |
| 172 | +
|
| 173 | + # Sign the binary |
| 174 | + codesign --sign "$SIGNING_IDENTITY" \ |
| 175 | + --options runtime \ |
| 176 | + --timestamp \ |
| 177 | + --force \ |
| 178 | + --verbose \ |
| 179 | + github-actions-utils-cli-darwin-arm64 |
| 180 | +
|
| 181 | + # Verify signature |
| 182 | + codesign --verify --verbose github-actions-utils-cli-darwin-arm64 |
| 183 | +
|
| 184 | + # Create zip and submit for notarization |
| 185 | + zip -q github-actions-utils-cli-darwin-arm64.zip github-actions-utils-cli-darwin-arm64 |
| 186 | + xcrun notarytool submit github-actions-utils-cli-darwin-arm64.zip \ |
| 187 | + --apple-id "$APPLE_ID" \ |
| 188 | + --password "$APPLE_ID_PASSWORD" \ |
| 189 | + --team-id "$APPLE_TEAM_ID" \ |
| 190 | + --wait |
| 191 | + rm github-actions-utils-cli-darwin-arm64.zip |
| 192 | +
|
| 193 | + - name: Cleanup keychain |
| 194 | + if: always() |
| 195 | + run: | |
| 196 | + if [ -n "$KEYCHAIN_NAME" ]; then |
| 197 | + security delete-keychain "$KEYCHAIN_NAME" || true |
| 198 | + fi |
| 199 | +
|
| 200 | + - name: Upload signed CLI darwin-amd64 |
| 201 | + uses: actions/upload-artifact@v5 |
| 202 | + with: |
| 203 | + name: cli-darwin-amd64 |
| 204 | + path: dist/github-actions-utils-cli-darwin-amd64 |
| 205 | + retention-days: 1 |
| 206 | + overwrite: true |
| 207 | + |
| 208 | + - name: Upload signed CLI darwin-arm64 |
| 209 | + uses: actions/upload-artifact@v5 |
| 210 | + with: |
| 211 | + name: cli-darwin-arm64 |
| 212 | + path: dist/github-actions-utils-cli-darwin-arm64 |
| 213 | + retention-days: 1 |
| 214 | + overwrite: true |
0 commit comments