|
| 1 | +# inspired by https://github.com/topheman/update-homebrew-tap-playground/blob/master/.github/workflows/cross-compile.yml |
| 2 | +name: Cross-Compile |
| 3 | + |
| 4 | +on: [push] |
| 5 | + |
| 6 | +env: |
| 7 | + CARGO_TERM_COLOR: always |
| 8 | + BINARY_NAME: pluginlab |
| 9 | + |
| 10 | +jobs: |
| 11 | + build: |
| 12 | + if: github.ref_type == 'tag' |
| 13 | + name: Cross-Compile ${{ matrix.platform.target }} |
| 14 | + strategy: |
| 15 | + matrix: |
| 16 | + platform: |
| 17 | + |
| 18 | + - runs-on: ubuntu-24.04 |
| 19 | + target: x86_64-unknown-linux-gnu |
| 20 | + - runs-on: ubuntu-24.04-arm |
| 21 | + target: aarch64-unknown-linux-gnu |
| 22 | + - runs-on: macos-14 |
| 23 | + target: x86_64-apple-darwin |
| 24 | + - runs-on: macos-14 |
| 25 | + target: aarch64-apple-darwin |
| 26 | + runs-on: ${{ matrix.platform.runs-on }} |
| 27 | + steps: |
| 28 | + - name: Checkout source code |
| 29 | + uses: actions/checkout@v4 |
| 30 | + - name: Build binary |
| 31 | + uses: houseabsolute/actions-rust-cross@v1 |
| 32 | + with: |
| 33 | + command: build |
| 34 | + target: ${{ matrix.platform.target }} |
| 35 | + args: "--locked --release -p pluginlab" |
| 36 | + strip: true |
| 37 | + - name: Generate completions |
| 38 | + run: | |
| 39 | + mkdir -p ./tmp/${{ matrix.platform.target }} |
| 40 | + cp target/${{ matrix.platform.target }}/release/${{ env.BINARY_NAME }} ./tmp/${{ matrix.platform.target }}/${{ env.BINARY_NAME }} |
| 41 | + mkdir -p ./tmp/${{ matrix.platform.target }}/completions/{zsh,bash,fish} |
| 42 | + ./tmp/${{ matrix.platform.target }}/${{ env.BINARY_NAME }} generate-completions --shell zsh > ./tmp/${{ matrix.platform.target }}/completions/zsh/_${{ env.BINARY_NAME }} |
| 43 | + ./tmp/${{ matrix.platform.target }}/${{ env.BINARY_NAME }} generate-completions --shell bash > ./tmp/${{ matrix.platform.target }}/completions/bash/${{ env.BINARY_NAME }} |
| 44 | + ./tmp/${{ matrix.platform.target }}/${{ env.BINARY_NAME }} generate-completions --shell fish > ./tmp/${{ matrix.platform.target }}/completions/fish/${{ env.BINARY_NAME }}.fish |
| 45 | + - name: Compress |
| 46 | + run: | |
| 47 | + mkdir -p ./compressed |
| 48 | + cd ./tmp/${{ matrix.platform.target }} |
| 49 | + tar -cvf ${{ env.BINARY_NAME }}-${{ matrix.platform.target }}.tar.gz ${{ env.BINARY_NAME }} completions |
| 50 | + mv ${{ env.BINARY_NAME }}-${{ matrix.platform.target }}.tar.gz ../../compressed |
| 51 | + - name: Cache compressed binaries |
| 52 | + uses: actions/cache@v4 |
| 53 | + with: |
| 54 | + path: ./compressed |
| 55 | + key: ${{ matrix.platform.target }}-compressed-binaries-${{ github.sha }} |
| 56 | + upload-archives: |
| 57 | + if: false # This step is totally skipped, activate the workflow outside of a tag (for debug purposes) |
| 58 | + needs: build |
| 59 | + name: Upload archive for build ${{ matrix.platform.target }} |
| 60 | + strategy: |
| 61 | + matrix: |
| 62 | + platform: |
| 63 | + - target: x86_64-unknown-linux-gnu |
| 64 | + - target: aarch64-unknown-linux-gnu |
| 65 | + - target: x86_64-apple-darwin |
| 66 | + - target: aarch64-apple-darwin |
| 67 | + runs-on: ubuntu-latest |
| 68 | + steps: |
| 69 | + - name: Restore cached compressed binaries |
| 70 | + uses: actions/cache/restore@v4 |
| 71 | + with: |
| 72 | + path: ./compressed |
| 73 | + key: ${{ matrix.platform.target }}-compressed-binaries-${{ github.sha }} |
| 74 | + - name: Upload archive |
| 75 | + uses: actions/upload-artifact@v4 |
| 76 | + with: |
| 77 | + path: ./compressed/ |
| 78 | + name: ${{ env.BINARY_NAME }}-${{ matrix.platform.target }}.tar.gz |
| 79 | + retention-days: 10 |
| 80 | + create-release-draft-if-not-exist: |
| 81 | + if: github.ref_type == 'tag' |
| 82 | + permissions: |
| 83 | + contents: write |
| 84 | + needs: build |
| 85 | + runs-on: ubuntu-latest |
| 86 | + steps: |
| 87 | + - uses: actions/checkout@v4 |
| 88 | + - name: Create release draft |
| 89 | + uses: topheman/create-release-if-not-exist@v1 |
| 90 | + with: |
| 91 | + args: ${{ github.ref_name }} --draft --generate-notes |
| 92 | + upload-artifacts-to-release-draft: |
| 93 | + if: github.ref_type == 'tag' |
| 94 | + permissions: |
| 95 | + contents: write |
| 96 | + needs: create-release-draft-if-not-exist |
| 97 | + env: |
| 98 | + RELEASE_NAME: ${{ github.ref_name }} |
| 99 | + name: Upload artifacts to release draft ${{ matrix.platform.target }} |
| 100 | + strategy: |
| 101 | + matrix: |
| 102 | + platform: |
| 103 | + - target: x86_64-unknown-linux-gnu |
| 104 | + - target: aarch64-unknown-linux-gnu |
| 105 | + - target: x86_64-apple-darwin |
| 106 | + - target: aarch64-apple-darwin |
| 107 | + runs-on: ubuntu-latest |
| 108 | + steps: |
| 109 | + - uses: actions/checkout@v4 |
| 110 | + - name: Restore cached compressed binaries |
| 111 | + uses: actions/cache/restore@v4 |
| 112 | + with: |
| 113 | + path: ./compressed |
| 114 | + key: ${{ matrix.platform.target }}-compressed-binaries-${{ github.sha }} |
| 115 | + - name: Upload artifacts to release draft |
| 116 | + run: | |
| 117 | + gh release upload ${{ env.RELEASE_NAME }} ./compressed/${{ env.BINARY_NAME }}-${{ matrix.platform.target }}.tar.gz |
| 118 | + env: |
| 119 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments