JetbraFree 3.1 复活版教程之-GitHub actions构建私有的执行程序

@cloudnative 大佬发布的jetbraFree3.1在GitHub被删库了;
原帖地址:https://linux.do/t/topic/691713
感谢佬友提供gitee仓库地址:https://gitee.com/zzqoo/lsix
随后将代码重新上传到GitHub;利用GitHub actions构建程序:exe、rpm、dmg,推荐将库私有化;这样应该可以避免被删库?
就可以得到可以直接运行的程序了;

name: Cross-platform Build & Package
on:
  push:
    branches: [ master, main ]
  pull_request:
    branches: [ master, main ]
  workflow_dispatch:
jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        os: [darwin, windows, linux]
        arch: [amd64]
    name: Build for ${{ matrix.os }}/${{ matrix.arch }}
    steps:
      - name: Checkout source code
        uses: actions/checkout@v3
      
      - name: Set up Go
        uses: actions/setup-go@v4
        with:
          go-version: '1.22'
      
      - name: Install go-bindata
        run: |
          go install github.com/go-bindata/go-bindata/v3/go-bindata@latest
          echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
      
      - name: Generate bindata files
        run: |
          go-bindata -o internal/util/access.go -pkg util static/... templates/... cache/...
      
      - name: Build binary
        run: |
          OUTPUT_NAME=your-app
          EXT=""
          if [ "${{ matrix.os }}" = "windows" ]; then EXT=".exe"; fi
          mkdir -p dist/${{ matrix.os }}-${{ matrix.arch }}
          GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -o dist/${{ matrix.os }}-${{ matrix.arch }}/$OUTPUT_NAME$EXT cmd/main.go
      
      - name: Install packaging tools for Linux (RPM)
        if: matrix.os == 'linux'
        run: |
          sudo apt-get update
          sudo apt-get install -y rpm
      
      - name: Install packaging tools for macOS (DMG)
        if: matrix.os == 'darwin'
        run: |
          # Install create-dmg tool
          npm install -g create-dmg || true
          # Alternative: use genisoimage if create-dmg fails
          sudo apt-get update
          sudo apt-get install -y genisoimage
      
      - name: Package for Linux (RPM)
        if: matrix.os == 'linux'
        run: |
          APP_NAME=your-app
          VERSION=1.0.0
          
          # Create RPM build structure
          mkdir -p rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
          mkdir -p rpmbuild/SOURCES/$APP_NAME-$VERSION/usr/local/bin
          
          # Copy binary
          cp dist/${{ matrix.os }}-${{ matrix.arch }}/$APP_NAME rpmbuild/SOURCES/$APP_NAME-$VERSION/usr/local/bin/
          
          # Create tarball
          cd rpmbuild/SOURCES
          tar -czf $APP_NAME-$VERSION.tar.gz $APP_NAME-$VERSION/
          cd ../..
          
          # Create RPM spec file
          cat > rpmbuild/SPECS/$APP_NAME.spec << EOF
          Name: $APP_NAME
          Version: $VERSION
          Release: 1
          Summary: Your App Description
          License: MIT
          Source0: %{name}-%{version}.tar.gz
          BuildArch: x86_64
          
          %description
          Your application description
          
          %prep
          %setup -q
          
          %install
          mkdir -p %{buildroot}/usr/local/bin
          cp usr/local/bin/$APP_NAME %{buildroot}/usr/local/bin/
          
          %files
          /usr/local/bin/$APP_NAME
          
          %changelog
          * $(date +'%a %b %d %Y') Builder <[email protected]> - $VERSION-1
          - Initial package
          EOF
          
          # Build RPM
          rpmbuild --define "_topdir $(pwd)/rpmbuild" -ba rpmbuild/SPECS/$APP_NAME.spec
          
          # Copy RPM to dist
          cp rpmbuild/RPMS/x86_64/$APP_NAME-$VERSION-1.x86_64.rpm dist/${{ matrix.os }}-${{ matrix.arch }}.rpm
      
      - name: Package for macOS (DMG)
        if: matrix.os == 'darwin'
        run: |
          APP_NAME=your-app
          
          # Create app structure
          mkdir -p $APP_NAME.app/Contents/MacOS
          mkdir -p $APP_NAME.app/Contents/Resources
          
          # Copy binary
          cp dist/${{ matrix.os }}-${{ matrix.arch }}/$APP_NAME $APP_NAME.app/Contents/MacOS/
          chmod +x $APP_NAME.app/Contents/MacOS/$APP_NAME
          
          # Create Info.plist
          cat > $APP_NAME.app/Contents/Info.plist << EOF
          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
          <plist version="1.0">
          <dict>
              <key>CFBundleExecutable</key>
              <string>$APP_NAME</string>
              <key>CFBundleIdentifier</key>
              <string>com.example.$APP_NAME</string>
              <key>CFBundleName</key>
              <string>$APP_NAME</string>
              <key>CFBundleVersion</key>
              <string>1.0.0</string>
              <key>CFBundlePackageType</key>
              <string>APPL</string>
          </dict>
          </plist>
          EOF
          
          # Create DMG using genisoimage (cross-platform alternative)
          mkdir -p dmg-contents
          cp -r $APP_NAME.app dmg-contents/
          
          # Create DMG
          genisoimage -V "$APP_NAME" -D -R -apple -no-pad -o dist/${{ matrix.os }}-${{ matrix.arch }}.dmg dmg-contents/
      
      - name: Rename Windows executable
        if: matrix.os == 'windows'
        run: |
          # Windows binary is already .exe, just move it to final location
          cp dist/${{ matrix.os }}-${{ matrix.arch }}/your-app.exe dist/${{ matrix.os }}-${{ matrix.arch }}.exe
      
      - name: Upload Linux RPM
        if: matrix.os == 'linux'
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.os }}-${{ matrix.arch }}-rpm
          path: dist/${{ matrix.os }}-${{ matrix.arch }}.rpm
      
      - name: Upload macOS DMG
        if: matrix.os == 'darwin'
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.os }}-${{ matrix.arch }}-dmg
          path: dist/${{ matrix.os }}-${{ matrix.arch }}.dmg
      
      - name: Upload Windows EXE
        if: matrix.os == 'windows'
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.os }}-${{ matrix.arch }}-exe
          path: dist/${{ matrix.os }}-${{ matrix.arch }}.exe

在GitHub代码库中新建一个.github文件夹;下面放workflows文件夹;在workflows文件夹中新建一个yml文件;把构建代码放进去;提交;GitHub就会自动构建了;
arm芯片的还需要有大佬补充下;我构建了好几次都是失败的

36 个赞

太强了,大佬

2 个赞


构建出的mac版本用不了

2 个赞

arm芯片的要修改平台啊

1 个赞

这个恢复支持啊

非常强大,感谢大佬

我这个能构建成功,但是不知道能不能用

name: Cross-platform Build & Package
on:
  push:
    branches: [ master, main ]
  pull_request:
    branches: [ master, main ]
  workflow_dispatch:

jobs:
  build:
    strategy:
      matrix:
        include:
          - os: darwin
            arch: amd64
            runner: macos-13
          - os: darwin
            arch: arm64
            runner: macos-14
          - os: linux
            arch: amd64
            runner: ubuntu-latest
          - os: windows
            arch: amd64
            runner: windows-latest
            
    runs-on: ${{ matrix.runner }}
    name: Build for ${{ matrix.os }}/${{ matrix.arch }}

    steps:
      - name: Checkout source code
        uses: actions/checkout@v4

      - name: Set up Go
        uses: actions/setup-go@v4
        with:
          go-version: '1.22'

      - name: Install go-bindata
        run: |
          go install github.com/go-bindata/go-bindata/v3/go-bindata@latest
          echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
        shell: bash

      - name: Generate bindata files
        run: |
          go-bindata -o internal/util/access.go -pkg util static/... templates/... cache/...
        shell: bash

      - name: Build binary
        env:
          GOOS: ${{ matrix.os }}
          GOARCH: ${{ matrix.arch }}
        run: |
          OUTPUT_NAME=your-app
          EXT=""
          if [ "$GOOS" = "windows" ]; then EXT=".exe"; fi
          mkdir -p dist
          go build -ldflags="-s -w" -o dist/$OUTPUT_NAME$EXT cmd/main.go
        shell: bash
      
      - name: Install packaging tools for Linux (RPM)
        if: matrix.os == 'linux'
        run: |
          sudo apt-get update
          sudo apt-get install -y rpm
      
      - name: Install packaging tools for macOS
        if: matrix.os == 'darwin'
        run: |
          # 使用系统自带的 hdiutil,不需要安装额外工具
          echo "Using system hdiutil for DMG creation"

      - name: Package for Linux (RPM)
        if: matrix.os == 'linux'
        run: |
          # Your RPM packaging script here...
          echo "Packaging RPM for Linux..."
          # Example: cp rpmbuild/RPMS/x86_64/your-app-*.rpm dist/your-app-linux-amd64.rpm
          
      - name: Package for macOS (DMG)
        if: matrix.os == 'darwin'
        run: |
          APP_NAME=your-app
          
          # Check if the binary exists from the build step
          if [ ! -f "dist/$APP_NAME" ]; then
            echo "Error: Binary 'dist/$APP_NAME' not found. The build step likely failed."
            exit 1
          fi

          # Create the .app structure
          mkdir -p "dist/$APP_NAME.app/Contents/MacOS"
          cp "dist/$APP_NAME" "dist/$APP_NAME.app/Contents/MacOS/"
          
          # Make the binary executable
          chmod +x "dist/$APP_NAME.app/Contents/MacOS/$APP_NAME"
          
          # Create the Info.plist
          cat > "dist/$APP_NAME.app/Contents/Info.plist" << EOF
          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
          <plist version="1.0">
          <dict>
              <key>CFBundleExecutable</key>
              <string>$APP_NAME</string>
              <key>CFBundleIdentifier</key>
              <string>com.example.$APP_NAME</string>
              <key>CFBundleName</key>
              <string>$APP_NAME</string>
              <key>CFBundleVersion</key>
              <string>1.0.0</string>
              <key>CFBundlePackageType</key>
              <string>APPL</string>
              <key>LSMinimumSystemVersion</key>
              <string>11.0</string>
          </dict>
          </plist>
          EOF

          # Create DMG using system hdiutil (more reliable)
          hdiutil create -srcfolder "dist/$APP_NAME.app" -volname "$APP_NAME" "dist/$APP_NAME.dmg"
          
          # Alternative: Simple create-dmg (if you prefer, but requires npm install)
          # create-dmg "dist/$APP_NAME.dmg" "dist/$APP_NAME.app"

      - name: Prepare Artifacts for Upload
        run: |
          OUTPUT_NAME=your-app
          OS=${{ matrix.os }}
          ARCH=${{ matrix.arch }}
          
          cd dist
          
          if [ "$OS" = "windows" ]; then
            mv $OUTPUT_NAME.exe ${OUTPUT_NAME}-${OS}-${ARCH}.exe
          elif [ "$OS" = "darwin" ]; then
            # DMG file should already be named correctly
            if [ -f "$OUTPUT_NAME.dmg" ]; then
              mv $OUTPUT_NAME.dmg ${OUTPUT_NAME}-${OS}-${ARCH}.dmg
            fi
          else # Linux
            tar -czf ../${OUTPUT_NAME}-${OS}-${ARCH}.tar.gz $OUTPUT_NAME
            rm $OUTPUT_NAME
          fi
        shell: bash

      - name: Upload Artifacts
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.os }}-${{ matrix.arch }}-build
          path: |
            dist/*.dmg
            dist/*.exe
            *.tar.gz
          if-no-files-found: error
1 个赞

能构建成功基本就可以使用,待需要的大佬们测试

1 个赞

试过了运行不了,

1 个赞

我之前没做dmg镜像的可以命令行运行。大佬你要试试看吗

1 个赞

:smiling_face_with_tear: 我也没mac 我是找朋友试的

3 个赞

我第一次构建的是纯命令行运行;找我朋友mac试过了;可以

1 个赞

自己没得mac不好排查问题是什么



佬友不太对呀,我发现必须放在workflows才会自动构建,并且构建失败了

2 个赞

Mac用不了,打不开

自行研究下叭,我这边是没问题的

构建成功的能发下文件么,windows感谢

我这边不提供哈;自己构建就好了

感谢,已经用上了

1 个赞

插眼, 谢佬