|
| 1 | +name: Release |
| 2 | +permissions: |
| 3 | + contents: write |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + tags: |
| 8 | + - "[v]?[0-9]+.[0-9]+.[0-9]+" |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + tag: |
| 12 | + description: "Tag to deploy" |
| 13 | + required: true |
| 14 | + default: "0.0.0" |
| 15 | + |
| 16 | +jobs: |
| 17 | + create-release: |
| 18 | + name: Create a release |
| 19 | + runs-on: ubuntu-latest |
| 20 | + permissions: |
| 21 | + contents: write |
| 22 | + steps: |
| 23 | + - name: Checkout the repository |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + # - name: Generate a changelog |
| 29 | + # uses: orhun/git-cliff-action@v4 |
| 30 | + # with: |
| 31 | + # config: cliff.toml |
| 32 | + # args: --latest --strip header |
| 33 | + # env: |
| 34 | + # OUTPUT: BODY.md |
| 35 | + |
| 36 | + - name: Publish on GitHub |
| 37 | + uses: ncipollo/release-action@v1 |
| 38 | + with: |
| 39 | + prerelease: false |
| 40 | + # bodyFile: BODY.md |
| 41 | + |
| 42 | + publish-release: |
| 43 | + name: Publishing for ${{ matrix.os }} |
| 44 | + runs-on: ${{ matrix.os }} |
| 45 | + |
| 46 | + strategy: |
| 47 | + fail-fast: false |
| 48 | + matrix: |
| 49 | + include: |
| 50 | + - os: macos-latest |
| 51 | + os-name: macos |
| 52 | + target: x86_64-apple-darwin |
| 53 | + architecture: x86_64 |
| 54 | + binary-postfix: "" |
| 55 | + use-cross: false |
| 56 | + - os: macos-latest |
| 57 | + os-name: macos |
| 58 | + target: aarch64-apple-darwin |
| 59 | + architecture: arm64 |
| 60 | + binary-postfix: "" |
| 61 | + use-cross: false |
| 62 | + - os: ubuntu-latest |
| 63 | + os-name: linux |
| 64 | + target: x86_64-unknown-linux-gnu |
| 65 | + architecture: x86_64 |
| 66 | + binary-postfix: "" |
| 67 | + use-cross: false |
| 68 | + - os: ubuntu-latest |
| 69 | + os-name: linux |
| 70 | + target: x86_64-unknown-linux-musl |
| 71 | + architecture: x86_64 |
| 72 | + binary-postfix: "" |
| 73 | + use-cross: false |
| 74 | + - os: windows-latest |
| 75 | + os-name: windows |
| 76 | + target: x86_64-pc-windows-msvc |
| 77 | + architecture: x86_64 |
| 78 | + binary-postfix: ".exe" |
| 79 | + use-cross: false |
| 80 | + - os: ubuntu-latest |
| 81 | + os-name: linux |
| 82 | + target: aarch64-unknown-linux-gnu |
| 83 | + architecture: arm64 |
| 84 | + binary-postfix: "" |
| 85 | + use-cross: true |
| 86 | + - os: ubuntu-latest |
| 87 | + os-name: linux |
| 88 | + target: i686-unknown-linux-gnu |
| 89 | + architecture: i686 |
| 90 | + binary-postfix: "" |
| 91 | + use-cross: true |
| 92 | + |
| 93 | + steps: |
| 94 | + - name: Checkout repository |
| 95 | + uses: actions/checkout@v4 |
| 96 | + - name: Install Rust toolchain |
| 97 | + uses: actions-rs/toolchain@v1 |
| 98 | + with: |
| 99 | + toolchain: stable |
| 100 | + |
| 101 | + target: ${{ matrix.target }} |
| 102 | + |
| 103 | + profile: minimal |
| 104 | + override: true |
| 105 | + |
| 106 | + - name: Install musl for musl target |
| 107 | + if: matrix.target == 'x86_64-unknown-linux-musl' |
| 108 | + shell: bash |
| 109 | + run: | |
| 110 | + sudo apt update |
| 111 | + sudo apt-get install -y musl musl-tools |
| 112 | +
|
| 113 | + - uses: Swatinem/rust-cache@v2 |
| 114 | + - name: Cargo build |
| 115 | + uses: actions-rs/cargo@v1 |
| 116 | + with: |
| 117 | + command: build |
| 118 | + |
| 119 | + use-cross: ${{ matrix.use-cross }} |
| 120 | + |
| 121 | + toolchain: stable |
| 122 | + |
| 123 | + args: --release --target ${{ matrix.target }} |
| 124 | + |
| 125 | + - name: install strip command |
| 126 | + shell: bash |
| 127 | + run: | |
| 128 | +
|
| 129 | + if [[ ${{ matrix.target }} == aarch64-unknown-linux-gnu ]]; then |
| 130 | +
|
| 131 | + sudo apt update |
| 132 | + sudo apt-get install -y binutils-aarch64-linux-gnu |
| 133 | + fi |
| 134 | + - name: Packaging final binary |
| 135 | + shell: bash |
| 136 | + run: | |
| 137 | +
|
| 138 | + ####### reduce binary size by removing debug symbols ####### |
| 139 | +
|
| 140 | + BIN=target/${{ matrix.target }}/release/string_pipeline${{ matrix.binary-postfix }} |
| 141 | + echo "BIN=$BIN" >> "$GITHUB_ENV" |
| 142 | + if [[ ${{ matrix.target }} == aarch64-unknown-linux-gnu ]]; then |
| 143 | +
|
| 144 | + GCC_PREFIX="aarch64-linux-gnu-" |
| 145 | + else |
| 146 | + GCC_PREFIX="" |
| 147 | + fi |
| 148 | + "$GCC_PREFIX"strip $BIN |
| 149 | +
|
| 150 | + ########## create tar.gz ########## |
| 151 | +
|
| 152 | + RELEASE_NAME=string-pipeline${GITHUB_REF/refs\/tags\//}-${{ matrix.target }} |
| 153 | + echo "RELEASE_NAME=$RELEASE_NAME" >> "$GITHUB_ENV" |
| 154 | +
|
| 155 | + # create the directory for the archive |
| 156 | + mkdir -p "$RELEASE_NAME"/doc |
| 157 | + cp $BIN "$RELEASE_NAME"/ |
| 158 | + cp {README.md,LICENSE} "$RELEASE_NAME"/ |
| 159 | + # cp {CHANGELOG.md,docs/*,man/*} "$RELEASE_NAME"/doc/ |
| 160 | +
|
| 161 | + tar czvf "$RELEASE_NAME".tar.gz "$RELEASE_NAME" |
| 162 | +
|
| 163 | + ########## create sha256 ########## |
| 164 | +
|
| 165 | + if [[ ${{ runner.os }} == 'Windows' ]]; then |
| 166 | +
|
| 167 | + certutil -hashfile $RELEASE_NAME.tar.gz sha256 | grep -E [A-Fa-f0-9]{64} > $RELEASE_NAME.sha256 |
| 168 | + else |
| 169 | + shasum -a 256 $RELEASE_NAME.tar.gz > $RELEASE_NAME.sha256 |
| 170 | + fi |
| 171 | + - name: Packaging with zip format |
| 172 | + if: runner.os == 'Windows' |
| 173 | + run: | |
| 174 | + Compress-Archive -Path "$env:BIN" -Destination "$($env:RELEASE_NAME).zip" |
| 175 | + (Get-FileHash "$($env:RELEASE_NAME).zip" -Algorithm SHA256).Hash.ToLower() > "$($env:RELEASE_NAME).zip.sha256" |
| 176 | +
|
| 177 | + - name: Releasing assets |
| 178 | + uses: softprops/action-gh-release@v2 |
| 179 | + with: |
| 180 | + files: | |
| 181 | +
|
| 182 | + string-pipeline*.tar.gz |
| 183 | + string-pipeline*.zip |
| 184 | + string-pipeline*.sha256 |
| 185 | +
|
| 186 | + env: |
| 187 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments