|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - "v*" |
| 9 | + pull_request: |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +jobs: |
| 13 | + test: |
| 14 | + name: Test |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Checkout |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Setup Go |
| 21 | + uses: actions/setup-go@v5 |
| 22 | + with: |
| 23 | + go-version-file: go.mod |
| 24 | + |
| 25 | + - name: Run tests |
| 26 | + run: go test ./... |
| 27 | + |
| 28 | + build: |
| 29 | + name: Build ${{ matrix.name }} |
| 30 | + needs: test |
| 31 | + runs-on: ${{ matrix.os }} |
| 32 | + strategy: |
| 33 | + fail-fast: false |
| 34 | + matrix: |
| 35 | + include: |
| 36 | + - name: Linux |
| 37 | + os: ubuntu-latest |
| 38 | + goos: linux |
| 39 | + goarch: amd64 |
| 40 | + artifact: M45-Relay-Client-Linux.zip |
| 41 | + - name: macOS |
| 42 | + os: macos-latest |
| 43 | + artifact: M45-Relay-Client-Mac.zip |
| 44 | + - name: Windows |
| 45 | + os: windows-latest |
| 46 | + goos: windows |
| 47 | + goarch: amd64 |
| 48 | + artifact: M45-Relay-Client-Win.zip |
| 49 | + |
| 50 | + steps: |
| 51 | + - name: Checkout |
| 52 | + uses: actions/checkout@v4 |
| 53 | + |
| 54 | + - name: Setup Go |
| 55 | + uses: actions/setup-go@v5 |
| 56 | + with: |
| 57 | + go-version-file: go.mod |
| 58 | + |
| 59 | + - name: Resolve version |
| 60 | + id: version |
| 61 | + shell: bash |
| 62 | + run: | |
| 63 | + if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then |
| 64 | + VERSION="${GITHUB_REF_NAME}" |
| 65 | + else |
| 66 | + VERSION="dev-${GITHUB_SHA::7}" |
| 67 | + fi |
| 68 | + echo "value=${VERSION}" >> "${GITHUB_OUTPUT}" |
| 69 | +
|
| 70 | + - name: Build Linux |
| 71 | + if: matrix.name == 'Linux' |
| 72 | + shell: bash |
| 73 | + run: | |
| 74 | + APP_NAME="M45-Relay-Client" |
| 75 | + VERSION="${{ steps.version.outputs.value }}" |
| 76 | + GOOS="${{ matrix.goos }}" GOARCH="${{ matrix.goarch }}" go build \ |
| 77 | + -ldflags "-X main.publicClientFlag=true -X main.version=${VERSION}" \ |
| 78 | + -o "${APP_NAME}" |
| 79 | + zip "${{ matrix.artifact }}" "${APP_NAME}" readme.txt READ-ME.html |
| 80 | +
|
| 81 | + - name: Build macOS universal app |
| 82 | + if: matrix.name == 'macOS' |
| 83 | + shell: bash |
| 84 | + run: | |
| 85 | + APP_NAME="M45-Relay-Client" |
| 86 | + VERSION="${{ steps.version.outputs.value }}" |
| 87 | + BINARY_NAME="${APP_NAME}" |
| 88 | + WRAPPER_SCRIPT="run.sh" |
| 89 | + IDENTIFIER="com.M45.M45-Relay-Client" |
| 90 | +
|
| 91 | + GOOS=darwin GOARCH=amd64 go build \ |
| 92 | + -ldflags "-X main.publicClientFlag=true -X main.version=${VERSION}" \ |
| 93 | + -o "${BINARY_NAME}-amd64" . |
| 94 | + GOOS=darwin GOARCH=arm64 go build \ |
| 95 | + -ldflags "-X main.publicClientFlag=true -X main.version=${VERSION}" \ |
| 96 | + -o "${BINARY_NAME}-arm64" . |
| 97 | +
|
| 98 | + lipo -create \ |
| 99 | + "${BINARY_NAME}-amd64" "${BINARY_NAME}-arm64" \ |
| 100 | + -output "${BINARY_NAME}" |
| 101 | +
|
| 102 | + rm -rf "${APP_NAME}.app" |
| 103 | + mkdir -p "${APP_NAME}.app/Contents/MacOS" |
| 104 | + mkdir -p "${APP_NAME}.app/Contents/Resources" |
| 105 | + mv "${BINARY_NAME}" "${APP_NAME}.app/Contents/MacOS/${BINARY_NAME}" |
| 106 | +
|
| 107 | + cat > "${APP_NAME}.app/Contents/MacOS/${WRAPPER_SCRIPT}" <<EOF |
| 108 | + #!/bin/bash |
| 109 | + SELF_DIR="\$(cd "\$(dirname "\${BASH_SOURCE[0]}")" && pwd)" |
| 110 | + osascript <<OSASCRIPT |
| 111 | + tell application "Terminal" |
| 112 | + activate |
| 113 | + do script "\\\"\$SELF_DIR/${BINARY_NAME}\\\"" |
| 114 | + end tell |
| 115 | + OSASCRIPT |
| 116 | + exit 0 |
| 117 | + EOF |
| 118 | + chmod +x "${APP_NAME}.app/Contents/MacOS/${WRAPPER_SCRIPT}" |
| 119 | +
|
| 120 | + cat > "${APP_NAME}.app/Contents/Info.plist" <<EOF |
| 121 | + <?xml version="1.0" encoding="UTF-8"?> |
| 122 | + <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" |
| 123 | + "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 124 | + <plist version="1.0"> |
| 125 | + <dict> |
| 126 | + <key>CFBundleName</key> |
| 127 | + <string>${APP_NAME}</string> |
| 128 | + <key>CFBundleDisplayName</key> |
| 129 | + <string>${APP_NAME}</string> |
| 130 | + <key>CFBundleExecutable</key> |
| 131 | + <string>${WRAPPER_SCRIPT}</string> |
| 132 | + <key>CFBundleIdentifier</key> |
| 133 | + <string>${IDENTIFIER}</string> |
| 134 | + <key>CFBundleVersion</key> |
| 135 | + <string>${VERSION}</string> |
| 136 | + <key>CFBundlePackageType</key> |
| 137 | + <string>APPL</string> |
| 138 | + <key>CFBundleSignature</key> |
| 139 | + <string>????</string> |
| 140 | + <key>CFBundleInfoDictionaryVersion</key> |
| 141 | + <string>6.0</string> |
| 142 | + </dict> |
| 143 | + </plist> |
| 144 | + EOF |
| 145 | +
|
| 146 | + ditto -c -k --sequesterRsrc --keepParent \ |
| 147 | + "${APP_NAME}.app" "${{ matrix.artifact }}" |
| 148 | +
|
| 149 | + - name: Build Windows unsigned |
| 150 | + if: matrix.name == 'Windows' |
| 151 | + shell: bash |
| 152 | + run: | |
| 153 | + APP_NAME="M45-Relay-Client" |
| 154 | + VERSION="${{ steps.version.outputs.value }}" |
| 155 | + GOOS="${{ matrix.goos }}" GOARCH="${{ matrix.goarch }}" go build \ |
| 156 | + -ldflags "-X main.publicClientFlag=true -X main.version=${VERSION}" \ |
| 157 | + -o "${APP_NAME}.exe" |
| 158 | + powershell -NoProfile -Command \ |
| 159 | + "Compress-Archive -Path '${APP_NAME}.exe','readme.txt','READ-ME.html' -DestinationPath '${{ matrix.artifact }}'" |
| 160 | +
|
| 161 | + - name: Upload artifact |
| 162 | + uses: actions/upload-artifact@v4 |
| 163 | + with: |
| 164 | + name: ${{ matrix.artifact }} |
| 165 | + path: ${{ matrix.artifact }} |
| 166 | + if-no-files-found: error |
0 commit comments