|
| 1 | +name: Release |
| 2 | +on: |
| 3 | + # schedule: |
| 4 | + # - cron: '0 0 * * *' # midnight UTC |
| 5 | + |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + |
| 10 | +env: |
| 11 | + BIN_NAME: draw-together |
| 12 | + PROJECT_NAME: draw-together |
| 13 | + REPO_NAME: 0x7d8/draw-together |
| 14 | + |
| 15 | +jobs: |
| 16 | + dist: |
| 17 | + name: Dist |
| 18 | + runs-on: ${{ matrix.os }} |
| 19 | + strategy: |
| 20 | + fail-fast: false # don't fail other jobs if one fails |
| 21 | + matrix: |
| 22 | + build: [x86_64-linux, x86_64-macos, x86_64-windows] #, x86_64-win-gnu, win32-msvc |
| 23 | + include: |
| 24 | + - build: x86_64-linux |
| 25 | + os: ubuntu-20.04 |
| 26 | + rust: stable |
| 27 | + target: x86_64-unknown-linux-gnu |
| 28 | + cross: false |
| 29 | + # - build: aarch64-linux |
| 30 | + # os: ubuntu-20.04 |
| 31 | + # rust: stable |
| 32 | + # target: aarch64-unknown-linux-gnu |
| 33 | + # cross: true |
| 34 | + - build: x86_64-macos |
| 35 | + os: macos-latest |
| 36 | + rust: stable |
| 37 | + target: x86_64-apple-darwin |
| 38 | + cross: false |
| 39 | + - build: x86_64-windows |
| 40 | + os: windows-2019 |
| 41 | + rust: stable |
| 42 | + target: x86_64-pc-windows-msvc |
| 43 | + cross: false |
| 44 | + # - build: aarch64-macos |
| 45 | + # os: macos-latest |
| 46 | + # rust: stable |
| 47 | + # target: aarch64-apple-darwin |
| 48 | + # - build: x86_64-win-gnu |
| 49 | + # os: windows-2019 |
| 50 | + # rust: stable-x86_64-gnu |
| 51 | + # target: x86_64-pc-windows-gnu |
| 52 | + # - build: win32-msvc |
| 53 | + # os: windows-2019 |
| 54 | + # rust: stable |
| 55 | + # target: i686-pc-windows-msvc |
| 56 | + |
| 57 | + steps: |
| 58 | + - name: Checkout sources |
| 59 | + uses: actions/checkout@v2 |
| 60 | + with: |
| 61 | + submodules: true |
| 62 | + |
| 63 | + - name: Install ${{ matrix.rust }} toolchain |
| 64 | + uses: actions-rs/toolchain@v1 |
| 65 | + with: |
| 66 | + profile: minimal |
| 67 | + toolchain: ${{ matrix.rust }} |
| 68 | + target: ${{ matrix.target }} |
| 69 | + override: true |
| 70 | + |
| 71 | + - name: Run cargo test |
| 72 | + uses: actions-rs/cargo@v1 |
| 73 | + with: |
| 74 | + use-cross: ${{ matrix.cross }} |
| 75 | + command: test |
| 76 | + args: --release --target ${{ matrix.target }} |
| 77 | + |
| 78 | + - name: Build release binary |
| 79 | + uses: actions-rs/cargo@v1 |
| 80 | + with: |
| 81 | + use-cross: ${{ matrix.cross }} |
| 82 | + command: build |
| 83 | + args: --release --target ${{ matrix.target }} |
| 84 | + |
| 85 | + - name: Strip release binary (linux and macos) |
| 86 | + if: matrix.build == 'x86_64-linux' || matrix.build == 'x86_64-macos' |
| 87 | + run: strip "target/${{ matrix.target }}/release/$BIN_NAME" |
| 88 | + |
| 89 | + # - name: Strip release binary (arm) |
| 90 | + # if: matrix.build == 'aarch64-linux' |
| 91 | + # run: | |
| 92 | + # docker run --rm -v \ |
| 93 | + # "$PWD/target:/target:Z" \ |
| 94 | + # rustembedded/cross:${{ matrix.target }} \ |
| 95 | + # aarch64-linux-gnu-strip \ |
| 96 | + # /target/${{ matrix.target }}/release/$BIN_NAME |
| 97 | + |
| 98 | + - name: Build archive |
| 99 | + shell: bash |
| 100 | + run: | |
| 101 | + mkdir dist |
| 102 | + if [ "${{ matrix.os }}" = "windows-2019" ]; then |
| 103 | + cp "target/${{ matrix.target }}/release/$BIN_NAME.exe" "dist/" |
| 104 | + else |
| 105 | + cp "target/${{ matrix.target }}/release/$BIN_NAME" "dist/" |
| 106 | + fi |
| 107 | +
|
| 108 | + - uses: actions/upload-artifact@v4 |
| 109 | + with: |
| 110 | + name: bins-${{ matrix.build }} |
| 111 | + path: dist |
| 112 | + |
| 113 | + publish: |
| 114 | + name: Publish |
| 115 | + needs: [dist] |
| 116 | + runs-on: ubuntu-latest |
| 117 | + permissions: |
| 118 | + contents: write |
| 119 | + steps: |
| 120 | + - name: Checkout sources |
| 121 | + uses: actions/checkout@v2 |
| 122 | + with: |
| 123 | + submodules: false |
| 124 | + |
| 125 | + - uses: actions/download-artifact@v4 |
| 126 | + # with: |
| 127 | + # path: dist |
| 128 | + # - run: ls -al ./dist |
| 129 | + - run: ls -al bins-* |
| 130 | + |
| 131 | + - name: Build archive |
| 132 | + shell: bash |
| 133 | + run: | |
| 134 | + set -ex |
| 135 | +
|
| 136 | + rm -rf tmp |
| 137 | + mkdir tmp |
| 138 | + mkdir dist |
| 139 | +
|
| 140 | + for dir in bins-* ; do |
| 141 | + platform=${dir#"bins-"} |
| 142 | + unset exe |
| 143 | + if [[ $platform =~ "windows" ]]; then |
| 144 | + exe=".exe" |
| 145 | + fi |
| 146 | + pkgname=$PROJECT_NAME-$platform |
| 147 | + mkdir tmp/$pkgname |
| 148 | + # cp LICENSE README.md tmp/$pkgname |
| 149 | + mv bins-$platform/$BIN_NAME$exe tmp/$pkgname |
| 150 | + chmod +x tmp/$pkgname/$BIN_NAME$exe |
| 151 | +
|
| 152 | + if [ "$exe" = "" ]; then |
| 153 | + tar cJf dist/$pkgname.tar.xz -C tmp $pkgname |
| 154 | + else |
| 155 | + (cd tmp && 7z a -r ../dist/$pkgname.zip $pkgname) |
| 156 | + fi |
| 157 | + done |
| 158 | +
|
| 159 | + - name: Get cli version from Cargo.toml |
| 160 | + id: version |
| 161 | + run: echo "val=$(cargo metadata --format-version=1 --no-deps | jq '.packages[0].version' -r)" >> $GITHUB_OUTPUT |
| 162 | + |
| 163 | + - name: Upload binaries to release |
| 164 | + uses: svenstaro/upload-release-action@v2 |
| 165 | + with: |
| 166 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 167 | + file: dist/* |
| 168 | + file_glob: true |
| 169 | + tag: ${{ steps.version.outputs.val }} |
| 170 | + overwrite: true |
| 171 | + |
| 172 | + # |
| 173 | + # you can use this initial file in your homebrew-tap if you don't have an initial formula: |
| 174 | + # <projectname>.rb |
| 175 | + # |
| 176 | + # class <Projectname capitalized> < Formula |
| 177 | + # desc "A test formula" |
| 178 | + # homepage "http://www.example.com" |
| 179 | + # url "-----" |
| 180 | + # version "-----" |
| 181 | + # sha256 "-----" |
| 182 | + |
| 183 | + # def install |
| 184 | + # bin.install "<bin-name>" |
| 185 | + # end |
| 186 | + # end |
| 187 | + |
| 188 | + |
| 189 | + # Uncomment this section if you want to release your package to crates.io |
| 190 | + # Before publishing, make sure you have filled out the following fields: |
| 191 | + # license or license-file, description, homepage, documentation, repository, readme. |
| 192 | + # Read more: https://doc.rust-lang.org/cargo/reference/publishing.html |
| 193 | + |
| 194 | + # - name: Install ${{ matrix.rust }} toolchain |
| 195 | + # uses: actions-rs/toolchain@v1 |
| 196 | + # with: |
| 197 | + # profile: minimal |
| 198 | + # toolchain: ${{ matrix.rust }} |
| 199 | + # target: ${{ matrix.target }} |
| 200 | + # - run: cargo publish --token ${CRATES_TOKEN} |
| 201 | + # env: |
| 202 | + # CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }} |
0 commit comments