|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + workflow_call: |
| 7 | + inputs: |
| 8 | + tag: |
| 9 | + description: 'Tag to release' |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + tag: |
| 15 | + description: 'Tag to release (e.g., v0.0.1)' |
| 16 | + required: true |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: write |
| 20 | + |
| 21 | +env: |
| 22 | + CARGO_TERM_COLOR: always |
| 23 | + |
| 24 | +jobs: |
| 25 | + build: |
| 26 | + name: Build ${{ matrix.target }} |
| 27 | + runs-on: ${{ matrix.os }} |
| 28 | + strategy: |
| 29 | + fail-fast: false |
| 30 | + matrix: |
| 31 | + include: |
| 32 | + - target: x86_64-apple-darwin |
| 33 | + os: macos-latest |
| 34 | + archive: tar.gz |
| 35 | + - target: aarch64-apple-darwin |
| 36 | + os: macos-latest |
| 37 | + archive: tar.gz |
| 38 | + - target: x86_64-unknown-linux-gnu |
| 39 | + os: ubuntu-latest |
| 40 | + archive: tar.gz |
| 41 | + - target: aarch64-unknown-linux-gnu |
| 42 | + os: ubuntu-latest |
| 43 | + archive: tar.gz |
| 44 | + |
| 45 | + steps: |
| 46 | + - name: Checkout |
| 47 | + uses: actions/checkout@v4 |
| 48 | + |
| 49 | + - name: Install Rust |
| 50 | + uses: dtolnay/rust-toolchain@stable |
| 51 | + with: |
| 52 | + targets: ${{ matrix.target }} |
| 53 | + |
| 54 | + - name: Install cross-compilation tools |
| 55 | + if: matrix.target == 'aarch64-unknown-linux-gnu' |
| 56 | + run: | |
| 57 | + sudo apt-get update |
| 58 | + sudo apt-get install -y gcc-aarch64-linux-gnu |
| 59 | +
|
| 60 | + - name: Build |
| 61 | + run: cargo build --release --target ${{ matrix.target }} -p icm-cli |
| 62 | + env: |
| 63 | + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc |
| 64 | + |
| 65 | + - name: Package |
| 66 | + run: | |
| 67 | + cd target/${{ matrix.target }}/release |
| 68 | + tar -czvf ../../../icm-${{ matrix.target }}.${{ matrix.archive }} icm |
| 69 | + cd ../../.. |
| 70 | +
|
| 71 | + - name: Upload artifact |
| 72 | + uses: actions/upload-artifact@v4 |
| 73 | + with: |
| 74 | + name: icm-${{ matrix.target }} |
| 75 | + path: icm-${{ matrix.target }}.${{ matrix.archive }} |
| 76 | + |
| 77 | + release: |
| 78 | + name: Create Release |
| 79 | + needs: [build] |
| 80 | + runs-on: ubuntu-latest |
| 81 | + steps: |
| 82 | + - name: Checkout |
| 83 | + uses: actions/checkout@v4 |
| 84 | + |
| 85 | + - name: Download all artifacts |
| 86 | + uses: actions/download-artifact@v4 |
| 87 | + with: |
| 88 | + path: artifacts |
| 89 | + |
| 90 | + - name: Get version |
| 91 | + id: version |
| 92 | + run: | |
| 93 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 94 | + echo "version=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT |
| 95 | + elif [ "${{ github.event_name }}" = "workflow_call" ]; then |
| 96 | + echo "version=${{ inputs.tag }}" >> $GITHUB_OUTPUT |
| 97 | + elif [ "${{ github.event_name }}" = "release" ]; then |
| 98 | + echo "version=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT |
| 99 | + fi |
| 100 | +
|
| 101 | + - name: Flatten artifacts |
| 102 | + run: | |
| 103 | + mkdir -p release |
| 104 | + find artifacts -type f -name "*.tar.gz" -exec cp {} release/ \; |
| 105 | +
|
| 106 | + - name: Create checksums |
| 107 | + run: | |
| 108 | + cd release |
| 109 | + sha256sum * > checksums.txt |
| 110 | +
|
| 111 | + - name: Upload Release Assets |
| 112 | + if: github.event_name == 'release' || github.event_name == 'workflow_call' |
| 113 | + uses: softprops/action-gh-release@v2 |
| 114 | + with: |
| 115 | + tag_name: ${{ steps.version.outputs.version }} |
| 116 | + files: release/* |
| 117 | + env: |
| 118 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 119 | + |
| 120 | + - name: Create Release |
| 121 | + if: github.event_name == 'workflow_dispatch' |
| 122 | + uses: softprops/action-gh-release@v2 |
| 123 | + with: |
| 124 | + tag_name: ${{ steps.version.outputs.version }} |
| 125 | + name: icm ${{ steps.version.outputs.version }} |
| 126 | + draft: false |
| 127 | + prerelease: false |
| 128 | + generate_release_notes: true |
| 129 | + files: release/* |
| 130 | + env: |
| 131 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments