|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v[0-9]+.[0-9]+.[0-9]+" |
| 7 | + workflow_call: |
| 8 | + secrets: |
| 9 | + DOCKER_PASSWORD: |
| 10 | + required: true |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + |
| 15 | +env: |
| 16 | + PROJECT_NAME: rustyhogs |
| 17 | + |
| 18 | +jobs: |
| 19 | + dist-binaries: |
| 20 | + name: Dist Binaries |
| 21 | + runs-on: ${{ matrix.os }} |
| 22 | + strategy: |
| 23 | + fail-fast: true |
| 24 | + matrix: |
| 25 | + build: [x86_64-linux, x86_64-macos, x86_64-windows] |
| 26 | + include: |
| 27 | + - build: x86_64-linux |
| 28 | + os: ubuntu-latest |
| 29 | + rust: stable |
| 30 | + target: x86_64-unknown-linux-gnu |
| 31 | + cross: false |
| 32 | + - build: x86_64-macos |
| 33 | + os: macos-latest |
| 34 | + rust: stable |
| 35 | + target: x86_64-apple-darwin |
| 36 | + cross: false |
| 37 | + # - build: aarch64-macos |
| 38 | + # os: macos-13-xlarge |
| 39 | + # rust: stable |
| 40 | + # target: aarch64-apple-darwin |
| 41 | + # cross: false |
| 42 | + - build: x86_64-windows |
| 43 | + os: windows-2019 |
| 44 | + rust: stable |
| 45 | + target: x86_64-pc-windows-msvc |
| 46 | + cross: false |
| 47 | + steps: |
| 48 | + - name: Checkout sources |
| 49 | + uses: actions/checkout@v3 |
| 50 | + - name: Install ${{ matrix.rust }}-${{ matrix.target }} toolchain |
| 51 | + uses: actions-rs/toolchain@v1 |
| 52 | + with: |
| 53 | + profile: minimal |
| 54 | + toolchain: ${{ matrix.rust }} |
| 55 | + target: ${{ matrix.target }} |
| 56 | + override: true |
| 57 | + - name: Build release binaries |
| 58 | + uses: actions-rs/cargo@v1 |
| 59 | + with: |
| 60 | + use-cross: ${{ matrix.cross }} |
| 61 | + command: build |
| 62 | + args: --release --target ${{ matrix.target }} |
| 63 | + - name: Build archive |
| 64 | + shell: bash |
| 65 | + run: | |
| 66 | + mkdir dist |
| 67 | + ls -lah target/${{ matrix.target }}/release |
| 68 | + if [[ ${{ matrix.build }} =~ "windows" ]]; then |
| 69 | + echo "${{ matrix.build }}: using .exe extension" |
| 70 | + exe=".exe" |
| 71 | + fi |
| 72 | + cp ./target/${{ matrix.target }}/release/*_hog$exe dist |
| 73 | + - uses: actions/upload-artifact@v3 |
| 74 | + with: |
| 75 | + name: bins-${{ matrix.build }} |
| 76 | + path: dist |
| 77 | + dist-lambda: |
| 78 | + name: Dist Lambda |
| 79 | + runs-on: ubuntu-latest |
| 80 | + steps: |
| 81 | + - name: Checkout sources |
| 82 | + uses: actions/checkout@v3 |
| 83 | + - name: Install stable-x86_64-unknown-linux-musl toolchain |
| 84 | + uses: actions-rs/toolchain@v1 |
| 85 | + with: |
| 86 | + profile: minimal |
| 87 | + toolchain: stable |
| 88 | + target: x86_64-unknown-linux-musl |
| 89 | + override: true |
| 90 | + - name: Build release binaries |
| 91 | + uses: actions-rs/cargo@v1 |
| 92 | + with: |
| 93 | + use-cross: true |
| 94 | + command: build |
| 95 | + args: --release --target x86_64-unknown-linux-musl |
| 96 | + - name: Build archive |
| 97 | + shell: bash |
| 98 | + run: | |
| 99 | + mkdir dist |
| 100 | + cp ./target/x86_64-unknown-linux-musl/release/*_lambda dist |
| 101 | + - uses: actions/upload-artifact@v3 |
| 102 | + with: |
| 103 | + name: bins-lambda |
| 104 | + path: dist |
| 105 | + dist-docker: |
| 106 | + name: Dist Docker |
| 107 | + runs-on: ubuntu-latest |
| 108 | + steps: |
| 109 | + - name: Checkout sources |
| 110 | + uses: actions/checkout@v3 |
| 111 | + - name: Get tag name |
| 112 | + id: tagname |
| 113 | + run: | |
| 114 | + name=dev |
| 115 | + echo $GITHUB_REF |
| 116 | + if [[ $GITHUB_REF == refs/tags/v* ]]; then |
| 117 | + name=${GITHUB_REF:10} |
| 118 | + fi |
| 119 | + echo "tag=${name//v}" >> "$GITHUB_OUTPUT" |
| 120 | + - name: Build Docker Images |
| 121 | + shell: bash |
| 122 | + run: make docker-build VERSION=${{ steps.tagname.outputs.tag }} |
| 123 | + - name: Save Docker Images |
| 124 | + shell: bash |
| 125 | + run: make docker-save VERSION=${{ steps.tagname.outputs.tag }} |
| 126 | + - uses: actions/upload-artifact@v3 |
| 127 | + with: |
| 128 | + name: docker |
| 129 | + path: images.tar |
| 130 | + publish: |
| 131 | + name: Publish Archive |
| 132 | + needs: [dist-binaries, dist-lambda, dist-docker] |
| 133 | + runs-on: ubuntu-latest |
| 134 | + steps: |
| 135 | + - name: Checkout sources |
| 136 | + uses: actions/checkout@v3 |
| 137 | + - name: Download artifacts |
| 138 | + uses: actions/download-artifact@v3 |
| 139 | + - name: List binaries |
| 140 | + run: ls -lah bins-* |
| 141 | + - name: Get tag name |
| 142 | + id: tagname |
| 143 | + run: | |
| 144 | + name=dev |
| 145 | + echo $GITHUB_REF |
| 146 | + if [[ $GITHUB_REF == refs/tags/v* ]]; then |
| 147 | + name=${GITHUB_REF:10} |
| 148 | + fi |
| 149 | + echo "tagname=${name}" >> "$GITHUB_OUTPUT" |
| 150 | + echo "tag=${name//v}" >> "$GITHUB_OUTPUT" |
| 151 | + - name: Build archive |
| 152 | + shell: bash |
| 153 | + run: | |
| 154 | + set -ex |
| 155 | + rm -rf tmp |
| 156 | + mkdir tmp |
| 157 | + mkdir dist |
| 158 | + for dir in bins-*; |
| 159 | + do |
| 160 | + platform=${dir#"bins-"} |
| 161 | + pkgname=$PROJECT_NAME-${{ steps.tagname.outputs.tag }}-$platform |
| 162 | + ls -lah $dir |
| 163 | + chmod +x $dir/* |
| 164 | + mkdir tmp/$pkgname |
| 165 | + mv $dir/* tmp/$pkgname |
| 166 | + if [[ $platform =~ "windows" ]]; then |
| 167 | + (cd tmp && zip -r ../dist/$pkgname.zip $pkgname) |
| 168 | + else |
| 169 | + tar czf dist/$pkgname.tar.gz -C tmp $pkgname |
| 170 | + fi |
| 171 | + done |
| 172 | + - name: Add scripts to archive |
| 173 | + shell: bash |
| 174 | + run: | |
| 175 | + pkgname=$PROJECT_NAME-${{ steps.tagname.outputs.tag }}-scripts |
| 176 | + tar czf dist/$pkgname.tar.gz scripts |
| 177 | + - name: Release archive |
| 178 | + uses: svenstaro/upload-release-action@v2 |
| 179 | + with: |
| 180 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 181 | + file: dist/* |
| 182 | + file_glob: true |
| 183 | + tag: ${{ steps.tagname.outputs.tagname }} |
| 184 | + overwrite: true |
| 185 | + publish-docker: |
| 186 | + name: Publish Docker Images |
| 187 | + needs: [dist-binaries, dist-lambda, dist-docker] |
| 188 | + runs-on: ubuntu-latest |
| 189 | + steps: |
| 190 | + - name: Checkout sources |
| 191 | + uses: actions/checkout@v3 |
| 192 | + - name: Download artifacts |
| 193 | + uses: actions/download-artifact@v3 |
| 194 | + with: |
| 195 | + name: docker |
| 196 | + - name: Load Docker Images |
| 197 | + shell: bash |
| 198 | + run: make docker-load |
| 199 | + - name: List Docker Images |
| 200 | + shell: bash |
| 201 | + run: docker images | grep hog |
| 202 | + - name: Get tag name |
| 203 | + id: tagname |
| 204 | + run: | |
| 205 | + name=dev |
| 206 | + echo $GITHUB_REF |
| 207 | + if [[ $GITHUB_REF == refs/tags/v* ]]; then |
| 208 | + name=${GITHUB_REF:10} |
| 209 | + fi |
| 210 | + echo "tag=${name//v}" >> "$GITHUB_OUTPUT" |
| 211 | + - name: Login to Docker Hub |
| 212 | + uses: docker/login-action@v3 |
| 213 | + with: |
| 214 | + username: wetfeet2000 |
| 215 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 216 | + - name: Publish Docker Images |
| 217 | + run: make docker-publish VERSION=${{ steps.tagname.outputs.tag }} |
0 commit comments