diff --git a/.github/workflows/build-rs-capi.yml b/.github/workflows/build-rs-capi.yml index 3038002..cf30d5d 100644 --- a/.github/workflows/build-rs-capi.yml +++ b/.github/workflows/build-rs-capi.yml @@ -1,102 +1,100 @@ -name: Build and Push RS-CAPI Docker Images +name: Build and Release on: push: - branches: [ "main" ] - tags: [ "v*" ] - paths: - - 'rs-capi/**' - pull_request: - branches: [ "main" ] - workflow_dispatch: - -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }}/rs-capi + tags: + - 'v*' jobs: - build-and-push: - runs-on: ubuntu-latest - permissions: - contents: write - packages: write - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Log in to the Container registry - uses: docker/login-action@v3 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract metadata for Docker - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - tags: | - type=raw,value=latest,enable={{is_default_branch}} - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=sha - - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: ./rs-capi - file: ./rs-capi/Dockerfile - push: ${{ github.event_name != 'pull_request' }} - platforms: linux/amd64,linux/arm64 - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - - create-release: - needs: build-and-push - if: startsWith(github.ref, 'refs/tags/v') - runs-on: ubuntu-latest - permissions: - contents: write + # 构建各平台二进制文件 + build-release: + strategy: + matrix: + include: + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + artifact_name: rs-cap-linux-x86_64.tar.gz + - os: ubuntu-latest + target: aarch64-unknown-linux-gnu + artifact_name: rs-cap-linux-aarch64.tar.gz + - os: macos-latest + target: x86_64-apple-darwin + artifact_name: rs-cap-darwin-x86_64.tar.gz + - os: macos-latest + target: aarch64-apple-darwin + artifact_name: rs-cap-darwin-aarch64.tar.gz + + runs-on: ${{ matrix.os }} steps: - - name: Checkout repository - uses: actions/checkout@v4 + - uses: actions/checkout@v3 + + - name: Setup Rust + uses: actions-rs/toolchain@v1 with: - fetch-depth: 0 - - - name: Generate Changelog - id: changelog - uses: mikepenz/release-changelog-builder-action@v4 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + toolchain: stable + target: ${{ matrix.target }} + override: true + + - name: Build + run: cargo build --release --target ${{ matrix.target }} + + - name: Package + run: tar -czf ${{ matrix.artifact_name }} -C target/${{ matrix.target }}/release rs-cap + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.artifact_name }} + path: ${{ matrix.artifact_name }} + # 创建 GitHub Release + create-release: + needs: build-release + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v3 + - name: Create Release uses: softprops/action-gh-release@v1 with: - body: | - ## Docker Images - You can pull the Docker images using: - ```bash - docker pull ghcr.io/${{ github.repository }}/rs-capi:${{ github.ref_name }} - ``` - - Available platforms: - - linux/amd64 - - linux/arm64 - - ## Changelog - ${{ steps.changelog.outputs.changelog }} + files: | + */rs-cap-*.tar.gz draft: false prerelease: false - token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # 构建并发布 Docker 镜像 + build-docker: + needs: build-release + strategy: + matrix: + platform: [linux/amd64, linux/arm64] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + file: rs-cap/Dockerfile + platforms: ${{ matrix.platform }} + push: true + tags: | + ghcr.io/${{ github.repository }}:latest + ghcr.io/${{ github.repository }}:${{ github.ref_name }} \ No newline at end of file